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 java.awt.geom.*;
import static x30_pkg.x30_util.DynamicObject;
import java.text.*;
import java.text.NumberFormat;
import java.util.TimeZone;
class main {
static FlexibleVarContext fromParams(Object... params) {
FlexibleVarContext ctx = new FlexibleVarContext();
for (int i = 0; i < l(params); i += 2)
ctx.put((String) params[i], params[i+1]);
return ctx;
}
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(IMultiMap mm) { return mm == null ? 0 : mm.size(); }
static int l(IntSize o) { return o == null ? 0 : o.size(); }
static int iteratorCount_int_close(Iterator i) { try {
int n = 0;
if (i != null) while (i.hasNext()) { i.next(); ++n; }
if (i instanceof AutoCloseable) ((AutoCloseable) i).close();
return n;
} catch (Exception __e) { throw rethrow(__e); } }
static RuntimeException rethrow(Throwable t) {
if (t instanceof Error)
_handleError((Error) t);
throw t instanceof RuntimeException ? (RuntimeException) t : new RuntimeException(t);
}
static RuntimeException rethrow(String msg, Throwable t) {
throw new RuntimeException(msg, t);
}
static void _handleError(Error e) {
//call(javax(), '_handleError, e);
}
// A FlexibleVarContext is thread-safe AFTER the first variable has been defined
// or after you call makeThreadSafe(), whichever comes first
static class FlexibleVarContext extends VarContext {
Map vars;
FlexibleVarContext() {}
FlexibleVarContext(VarContext parent) { super(parent); }
Object get(String name) {
if (containsKey(vars, name))
return mapGet(vars, name);
if (parent != null)
return parent.get(name);
return null;
}
void set(String name, Object value) {
vars = putOrCreateSyncMap(vars, name, value);
}
AutoCloseable tempSet(String name, Object value) {
initMap();
return main.tempPut(vars, name, value);
}
void unset(String name) {
remove(vars, name);
}
Map varMap() { return vars; }
final void initMap(){ makeThreadSafe(); }
void makeThreadSafe() {
if (vars == null) vars = syncHashMap();
}
static FlexibleVarContext fromParams(Object... params) {
FlexibleVarContext ctx = new FlexibleVarContext();
for (int i = 0; i < l(params); i += 2)
ctx.put((String) params[i], params[i+1]);
return ctx;
}
}
abstract static class VarContext {
final public VarContext getParent(){ return parent(); }
public VarContext parent() { return parent; }
VarContext parent;
VarContext() {}
VarContext(VarContext parent) {
this.parent = parent;}
abstract Object get(String name);
final void put(String name, Object value){ set(name, value); }
abstract void set(String name, Object value);
final AutoCloseable tempPut(String name, Object value){ return tempSet(name, value); }
abstract AutoCloseable tempSet(String name, Object value);
// either undefines variable completely or just sets variable to null
abstract void unset(String name);
abstract Map varMap();
void printMe() {
pnl(varMap());
print("parent", parent);
}
// mechanism for returning from a script
final public VarContext setExitFromScript(Object exitFromScript){ return exitFromScript(exitFromScript); }
public VarContext exitFromScript(Object exitFromScript) { this.exitFromScript = exitFromScript; return this; } final public Object getExitFromScript(){ return exitFromScript(); }
public Object exitFromScript() { return exitFromScript; }
Object exitFromScript;
final public VarContext setReturnValue(Object returnValue){ return returnValue(returnValue); }
public VarContext returnValue(Object returnValue) { this.returnValue = returnValue; return this; } final public Object getReturnValue(){ return returnValue(); }
public Object returnValue() { return returnValue; }
Object returnValue;
boolean exiting() { ping(); return exitFromScript != null; }
}
static boolean containsKey(Map map, A key) {
return map != null && map.containsKey(key);
}
static B mapGet(Map map, A a) {
return map == null || a == null ? null : map.get(a);
}
static B mapGet(A a, Map map) {
return map == null || a == null ? null : map.get(a);
}
static Map putOrCreateSyncMap(Map map, A key, B value) {
if (map == null) map = syncHashMap();
map.put(key, value);
return map;
}
static AutoCloseable tempSet(Object o, final String field, Object value) {
return tempSetField(o, field, value);
}
static AutoCloseable tempPut(Map map, A key, B value) {
if (map != null) {
boolean wasContained = map.containsKey(key);
B old = map.put(key, value);
return () -> { if (wasContained) map.put(key, old); else map.remove(key); };
}
return null;
}
static void remove(List l, int i) {
if (l != null && i >= 0 && i < l(l))
l.remove(i);
}
static void remove(Collection l, A a) {
if (l != null) l.remove(a);
}
static B remove(Map map, Object a) {
return map == null ? null : map.remove(a);
}
static void remove(BitSet bs, int i) {
bs.clear(i);
}
static Map syncHashMap() {
return synchroHashMap();
}
static A set(A o, String field, Object value) {
if (o == null) return null;
if (o instanceof Class) set((Class) o, field, value);
else try {
Field f = set_findField(o.getClass(), field);
makeAccessible(f);
smartSet(f, o, value);
} catch (Exception e) {
throw new RuntimeException(e);
}
return o;
}
static void set(Class c, String field, Object value) {
if (c == null) return;
try {
Field f = set_findStaticField(c, field);
makeAccessible(f);
smartSet(f, null, value);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
static Field set_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 set_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 void set(BitSet bs, int idx) {
{ if (bs != null) bs.set(idx); }
}
static A pnl(A l) { return pnl("", l); }
static A pnl(String prefix, A l) {
printNumberedLines(prefix, l);
return l;
}
static A[] pnl(A[] l) { return pnl("", l); }
static A[] pnl(String prefix, A[] l) {
printNumberedLines(prefix, l);
return l;
}
static A pnl(A map) {
printNumberedLines(map);
return map;
}
static A pnl(String prefix, A map) {
printNumberedLines(prefix, map);
return map;
}
static String pnl(String s) {
printNumberedLines(lines(s));
return s;
}
static MultiMap pnl(MultiMap mm) {
pnl(mm == null ? null : mm.asMap());
return mm;
}
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