import java.util.*;
import java.util.zip.*;
import java.util.List;
import java.util.regex.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
import java.util.concurrent.locks.*;
import java.util.function.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.table.*;
import java.io.*;
import java.net.*;
import java.lang.reflect.*;
import java.lang.ref.*;
import java.lang.management.*;
import java.security.*;
import java.security.spec.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.geom.*;
import javax.imageio.*;
import java.math.*;
import static x30_pkg.x30_util.DynamicObject;
class main {
static class IndexedList extends AbstractList {
ArrayList l = new ArrayList();
MultiMap index;
static boolean debug = false;
IndexedList() {}
IndexedList(List x) {
l.ensureCapacity(l(x));
addAll(x);
}
// required immutable list methods
@Override
public A get(int i) {
return l.get(i);
}
@Override
public int size() {
return l.size();
}
// required mutable list methods
@Override
public A set(int i, A a) {
unindex(i);
A prev = l.get(i);
l.set(i, a);
index(i);
return prev;
}
@Override
public void add(int i, A a) {
if (i != l.size()) {
l.add(i, a);
index = null;
} else {
l.add(i, a);
index(i);
}
}
@Override
public A remove(int i) {
A a = l.get(i);
l.remove(i);
index = null;
return a;
}
// speed up methods
@Override
protected void removeRange(int fromIndex, int toIndex) {
l.subList(fromIndex, toIndex).clear();
index = null;
}
public int indexOf(Object a) {
ensureIndexed();
List positions = index.get((A) a);
int n = l(positions);
int min = -1;
if (n != 0) {
min = positions.get(0);
for (int i = 1; i < n; i++) {
int p = positions.get(i);
if (p < min) min = p;
}
}
if (debug) print("IndexedList.indexOf " + a + " => " + min);
return min;
}
@Override
public boolean contains(Object a) {
ensureIndexed();
boolean b = index.containsKey((A) a);
if (debug) print("IndexedList.contains " + a + " => " + b);
return b;
}
// indexing methods
void unindex(int i) {
if (index != null)
index.remove(l.get(i), i);
}
void index(int i) {
if (index == null)
ensureIndexed();
else
index.put(l.get(i), i);
}
void ensureIndexed() {
if (index == null) {
index = new MultiMap();
int n = size();
for (int i = 0; i < n; i++)
index.put(l.get(i), i);
}
}
}
static int l(Object[] a) { return a == null ? 0 : a.length; }
static int l(boolean[] a) { return a == null ? 0 : a.length; }
static int l(byte[] a) { return a == null ? 0 : a.length; }
static int l(short[] a) { return a == null ? 0 : a.length; }
static int l(long[] a) { return a == null ? 0 : a.length; }
static int l(int[] a) { return a == null ? 0 : a.length; }
static int l(float[] a) { return a == null ? 0 : a.length; }
static int l(double[] a) { return a == null ? 0 : a.length; }
static int l(char[] a) { return a == null ? 0 : a.length; }
static int l(Collection c) { return c == null ? 0 : c.size(); }
static int l(Iterator i) { return iteratorCount_int_close(i); } // consumes the iterator && closes it if possible
static int l(Map m) { return m == null ? 0 : m.size(); }
static int l(CharSequence s) { return s == null ? 0 : s.length(); }
static long l(File f) { return f == null ? 0 : f.length(); }
static int l(Object o) {
return o == null ? 0
: o instanceof String ? l((String) o)
: o instanceof Map ? l((Map) o)
: o instanceof Collection ? l((Collection) o)
: o instanceof Object[] ? l((Object[]) o)
: o instanceof boolean[] ? l((boolean[]) o)
: o instanceof byte[] ? l((byte[]) o)
: o instanceof char[] ? l((char[]) o)
: o instanceof short[] ? l((short[]) o)
: o instanceof int[] ? l((int[]) o)
: o instanceof float[] ? l((float[]) o)
: o instanceof double[] ? l((double[]) o)
: o instanceof long[] ? l((long[]) o)
: (Integer) call(o, "size");
}
static void addAll(Collection c, Iterable b) {
if (c != null && b != null) for (A a : b) c.add(a);
}
static boolean addAll(Collection c, Collection b) {
return c != null && b != null && c.addAll(b);
}
static boolean addAll(Collection c, B... b) {
return c != null && b != null && c.addAll(Arrays.asList(b));
}
static Map addAll(Map a, Map extends A,? extends B> b) {
if (a != null && b != null) a.putAll(b);
return a;
}
static final class IndexedList2 extends ArrayList {
final HashMap index = new HashMap();
static int instances;
IndexedList2() { ++instances; }
IndexedList2(List x) {
this();
ensureCapacity(l(x));
addAll(x);
}
@Override
public A set(int i, A a) {
A prev = get(i);
if (prev != a) {
indexRemove(prev);
indexAdd(a);
super.set(i, a);
}
return prev;
}
@Override
public void add(int i, A a) {
indexAdd(a);
super.add(i, a);
}
@Override
public boolean add(A a) {
indexAdd(a);
return super.add(a);
}
@Override
public A remove(int i) {
A a = get(i);
indexRemove(a);
super.remove(i);
return a;
}
public boolean remove(Object a) {
int i = indexOf(a);
if (i < 0) return false;
{ remove(i); return true; }
}
// speed up methods
@Override
protected void removeRange(int fromIndex, int toIndex) {
for (int i = fromIndex; i < toIndex; i++)
unindex(i);
super.removeRange(fromIndex, toIndex);
}
@Override
public int indexOf(Object a) {
if (!contains(a)) return -1;
return super.indexOf(a);
}
@Override
public boolean contains(Object a) {
return index.containsKey(a);
}
@Override
public void clear() {
index.clear();
super.clear();
}
@Override
public boolean addAll(int i, Collection extends A> c) {
for (A a : c) indexAdd(a);
return super.addAll(i, c);
}
// indexing methods
void unindex(int i) {
indexRemove(get(i));
}
void indexAdd(A a) {
Integer i = index.get(a);
index.put(a, i == null ? 1 : i+1);
}
void indexRemove(A a) {
Integer i = index.get(a);
if (i != null && i > 1)
index.put(a, i-1);
else
index.remove(a);
}
// static methods
static IndexedList2 ensureIndexed(List l) {
return l instanceof IndexedList2 ? (IndexedList2) l : new IndexedList2(l);
}
}
static volatile StringBuffer local_log = new StringBuffer(); // not redirected
static boolean printAlsoToSystemOut = true;
static volatile Appendable print_log = local_log; // might be redirected, e.g. to main bot
// in bytes - will cut to half that
static volatile int print_log_max = 1024*1024;
static volatile int local_log_max = 100*1024;
static boolean print_silent = false; // total mute if set
static Object print_byThread_lock = new Object();
static volatile ThreadLocal