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 java.time.Duration;
import java.lang.invoke.VarHandle;
import java.lang.invoke.MethodHandles;
import static x30_pkg.x30_util.DynamicObject;
import java.awt.geom.*;
import java.text.*;
import java.text.NumberFormat;
import java.util.TimeZone;
class main {
static class HashedImage2B implements IBinaryImage, MakesImage2B {
Image2B image; // don't change this afterwards...
long hash;
boolean hashComputed = false;
HashedImage2B(BufferedImage image) { this(new Image2B(image)); }
HashedImage2B(Image2B image) {
this.image = image; assertNotNull(image); }
long hash() {
while (!hashComputed) {
synchronized(this) {
if (!hashComputed) {
hash = hashBinaryImage(image);
hashComputed = true;
}
}
}
return hash;
}
public boolean equals(Object o) { if (o instanceof HashedImage2B) {
if (hash() != ((HashedImage2B) o).hash()) return false;
if (!binaryImagesIdentical(image, ((HashedImage2B) o).image)) {
reportHashCollision(this, ((HashedImage2B) o));
return false;
}
return true;
} return false; }
public int hashCode() { return (int) hash(); }
final public Image2B getImage2B(){ return get(); }
public Image2B get() { return image; }
public int getWidth() { return image.getWidth(); }
public int getHeight() { return image.getHeight(); }
public BufferedImage getBufferedImage() { return image.getBufferedImage(); }
// check that Image2B wasn't modified
void verify() {
if (hash != 0)
assertEquals(hash, hashBinaryImage(image));
}
String classNameForPrinting() { return cnfp(this, HashedImage2B.class, "HashedImage2B"); }
public String toString() { return formatFunctionCall(classNameForPrinting(),
w() + "*" + h() + "px", "hash " + longToHex(hash())); }
// implement IBinaryImage
public boolean getBoolPixel(int x, int y) { return image.getBoolPixel(x, y); }
}
static A assertNotNull(A a) {
assertTrue(a != null);
return a;
}
static A assertNotNull(String msg, A a) {
assertTrue(msg, a != null);
return a;
}
static long hashBinaryImage(IBinaryImage img) {
return new HashBinaryImage(img).get();
}
static int hash(Object... l) {
return hashAboutObjects(l);
}
static boolean binaryImagesIdentical(IBinaryImage img1, IBinaryImage img2) {
if (img1 == img2) return true;
if (img1 == null) return img2 == null;
if (img2 == null) return false;
int w = img1.getWidth(), h = img1.getHeight();
if (w != img2.getWidth() || h != img2.getHeight()) return false;
return binaryImagesIdentical(img1.toImage2B(), img2.toImage2B());
}
static boolean binaryImagesIdentical(Image2B img1, Image2B img2) {
if (img1 == img2) return true;
if (img1 == null) return img2 == null;
if (img2 == null) return false;
int w = img1.getWidth(), h = img1.getHeight();
if (w != img2.getWidth() || h != img2.getHeight()) return false;
byte[] pixels1 = img1.pixels, pixels2 = img2.pixels;
return Arrays.equals(pixels1, pixels2);
}
static long hashCollisions;
static void reportHashCollision(Object... data) {
printVars("Hash collision! " + shorten(joinWithComma(data)));
++hashCollisions;
}
// get purpose 1: access a list/array/map (safer version of x.get(y))
static A get(List l, int idx) {
return l != null && idx >= 0 && idx < l(l) ? l.get(idx) : null;
}
// seems to conflict with other signatures
/*static B get(Map map, A key) {
ret map != null ? map.get(key) : null;
}*/
static A get(A[] l, int idx) {
return idx >= 0 && idx < l(l) ? l[idx] : null;
}
// default to false
static boolean get(boolean[] l, int idx) {
return idx >= 0 && idx < l(l) ? l[idx] : false;
}
// get purpose 2: access a field by reflection or a map
static Object get(Object o, String field) {
try {
if (o == null) return null;
if (o instanceof Class) return get((Class) o, field);
if (o instanceof Map)
return ((Map) o).get(field);
Field f = getOpt_findField(o.getClass(), field);
if (f != null) {
makeAccessible(f);
return f.get(o);
}
if (o instanceof DynamicObject)
return getOptDynOnly(((DynamicObject) o), field);
} catch (Exception e) {
throw asRuntimeException(e);
}
throw new RuntimeException("Field '" + field + "' not found in " + o.getClass().getName());
}
static Object get_raw(String field, Object o) {
return get_raw(o, field);
}
static Object get_raw(Object o, String field) { try {
if (o == null) return null;
Field f = get_findField(o.getClass(), field);
makeAccessible(f);
return f.get(o);
} catch (Exception __e) { throw rethrow(__e); } }
static Object get(Class c, String field) {
try {
Field f = get_findStaticField(c, field);
makeAccessible(f);
return f.get(null);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
static Field get_findStaticField(Class> c, String field) {
Class _c = c;
do {
for (Field f : _c.getDeclaredFields())
if (f.getName().equals(field) && (f.getModifiers() & java.lang.reflect.Modifier.STATIC) != 0)
return f;
_c = _c.getSuperclass();
} while (_c != null);
throw new RuntimeException("Static field '" + field + "' not found in " + c.getName());
}
static Field get_findField(Class> c, String field) {
Class _c = c;
do {
for (Field f : _c.getDeclaredFields())
if (f.getName().equals(field))
return f;
_c = _c.getSuperclass();
} while (_c != null);
throw new RuntimeException("Field '" + field + "' not found in " + c.getName());
}
static Object get(String field, Object o) {
return get(o, field);
}
static boolean get(BitSet bs, int idx) {
return bs != null && bs.get(idx);
}
static A assertEquals(Object x, A y) {
return assertEquals("", x, y);
}
static A assertEquals(String msg, Object x, A y) {
if (assertVerbose()) return assertEqualsVerbose(msg, x, y);
if (!(x == null ? y == null : x.equals(y)))
throw fail((msg != null ? msg + ": " : "") + y + " != " + x);
return y;
}
static String cnfp(Object o, Class c, String className) {
return classNameForPrinting(o, c, className);
}
// binary legacy syntax
static String formatFunctionCall(String fname, Object... args) {
return formatFunctionCall((Object) fname, args);
}
static String formatFunctionCall(Object fname, Object... args) {
return fname + "(" + joinWithComma(allToString(args)) + ")";
}
static String formatFunctionCall(String fname, Iterable args) {
return formatFunctionCall((Object) fname, args);
}
static String formatFunctionCall(Object fname, Iterable args) {
return formatFunctionCall(fname, toObjectArray(args));
}
static String classNameForPrinting(Object o, Class c, String className) {
return (o.getClass() != c ? "subclass of " : "") + className;
}
static String longToHex(long l) {
return bytesToHex(longToBytes(l));
}
static void assertTrue(Object o) {
if (!(eq(o, true) /*|| isTrue(pcallF(o))*/))
throw fail(str(o));
}
static boolean assertTrue(String msg, boolean b) {
if (!b)
throw fail(msg);
return b;
}
static boolean assertTrue(boolean b) {
if (!b)
throw fail("oops");
return b;
}
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