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.*;
// 6.5 mega exceptions per second (MEPS)
// So this is ~25 times faster as regular exceptions
import java.text.NumberFormat;
import static x30_pkg.x30_util.DynamicObject;
import java.awt.geom.*;
class main {
static void bench_throwAndCatchQuickException() {
benchFor10(() -> {
try {
if (alwaysTrue())
throw new QuickException();
} catch (QuickException e) {
}
});
}
// returns minimal time needed
static long benchFor10(Runnable r) { return benchFor10(str(r), r); }
static long benchFor10(String desc, Runnable r) {
return benchForNSeconds(desc, r, 10);
}
// returns result of function
static A benchFor10(IF0 f) { return benchFor10(str(f), f); }
static A benchFor10(String desc, IF0 f) {
benchFor10(new Runnable() { public void run() { try { f.get() ;
} catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "f!"; }});
return f.get();
}
public static volatile boolean alwaysTrue_flag = true;
static boolean alwaysTrue() { return alwaysTrue_flag; }
static String str(Object o) {
return o == null ? "null" : o.toString();
}
static String str(char[] c) {
return new String(c);
}
// returns result of function
static A benchForNSeconds(double n, IF0 f) { return benchForNSeconds(n, str(f), f); }
static A benchForNSeconds(double n, String desc, IF0 f) {
benchForNSeconds(new Runnable() { public void run() { try { f.get() ;
} catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "f!"; }}, n);
return f.get();
}
// returns minimal time needed
static long benchForNSeconds(Runnable r, double n) { return benchForNSeconds(str(r), r, n); }
static long benchForNSeconds(String desc, Runnable r, double n) {
long start = sysNow(), min = -1, print = sysNow();
int seconds = 1;
long count = 0, sum = 0;
while (seconds <= n) {
long time = nanos();
r.run();
++count;
time = nanos()-time;
min = min < 0 ? time : min(min, time);
sum += time;
double avg = doubleRatio(sum, count);
if (sysNow() >= start+seconds*1000) {
printAndSetConsoleTitleIfMain(
"avg=" + formatDouble(nanosToMS(avg), 3) + " ms, " +
"min=" + formatDouble(nanosToMS(min), 3) + " ms: " +
desc + " (" + seconds + "/" + n + " s, last=" + formatDouble(nanosToMS(time), 3) + " ms, " + n2(count) + "/s)");
++seconds;
count = sum = 0;
}
}
return min;
}
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 long sysNow() {
ping();
return System.nanoTime()/1000000;
}
static long nanos() {
return nanoTime();
}
static int min(int a, int b) {
return Math.min(a, b);
}
static long min(long a, long b) {
return Math.min(a, b);
}
static float min(float a, float b) { return Math.min(a, b); }
static float min(float a, float b, float c) { return min(min(a, b), c); }
static double min(double a, double b) {
return Math.min(a, b);
}
static double min(double[] c) {
double x = Double.MAX_VALUE;
for (double d : c) x = Math.min(x, d);
return x;
}
static float min(float[] c) {
float x = Float.MAX_VALUE;
for (float d : c) x = Math.min(x, d);
return x;
}
static byte min(byte[] c) {
byte x = 127;
for (byte d : c) if (d < x) x = d;
return x;
}
static short min(short[] c) {
short x = 0x7FFF;
for (short d : c) if (d < x) x = d;
return x;
}
static int min(int[] c) {
int x = Integer.MAX_VALUE;
for (int d : c) if (d < x) x = d;
return x;
}
static double doubleRatio(double x, double y) {
return y == 0 ? 0 : x/y;
}
static void printAndSetConsoleTitleIfMain(String s) {
print(s);
if (isMain()) consoleTitle(s);
}
static String formatDouble(double d, int digits) {
String format = digits <= 0 ? "0" : "0." + rep(digits, '#');
return decimalFormatEnglish(format, d);
}
static String formatDouble(double d) {
return str(d);
}
static double nanosToMS(double nanoseconds) {
return nsToMS(nanoseconds);
}
static String n2(long l) { return formatWithThousands(l); }
static String n2(AtomicLong l) { return n2(l.get()); }
static String n2(Collection l) { return n2(l(l)); }
static String n2(Map map) { return n2(l(map)); }
static String n2(double l, String singular) {
return empty(singular) ? str(l) : n2(l, singular, singular + "s");
}
static String n2(double l, String singular, String plural) {
if (fraction(l) == 0)
return n2((long) l, singular, plural);
else
return l + " " + plural;
}
static String n2(long l, String singular, String plural) {
return n_fancy2(l, singular, plural);
}
static String n2(long l, String singular) {
return empty(singular) ? n2(l) : n_fancy2(l, singular, singular + "s");
}
static String n2(Collection l, String singular) {
return n2(l(l), singular);
}
static String n2(Collection l, String singular, String plural) {
return n_fancy2(l, singular, plural);
}
static String n2(Map m, String singular, String plural) {
return n_fancy2(m, singular, plural);
}
static String n2(Map m, String singular) {
return n2(l(m), singular);
}
static String n2(long[] a, String singular) { return n2(l(a), singular); }
static String n2(Object[] a, String singular) { return n2(l(a), singular); }
static String n2(Object[] a, String singular, String plural) { return n_fancy2(a, singular, plural); }
static void _handleError(Error e) {
call(javax(), "_handleError", e);
}
//sbool ping_actions_shareable = true;
static volatile boolean ping_pauseAll = false;
static int ping_sleep = 100; // poll pauseAll flag every 100
static volatile boolean ping_anyActions = false;
static Map ping_actions = newWeakHashMap();
static ThreadLocal ping_isCleanUpThread = new ThreadLocal();
// always returns true
static boolean ping() {
//ifdef useNewPing
newPing();
//endifdef
if (ping_pauseAll || ping_anyActions) ping_impl(true /* XXX */);
//ifndef LeanMode ping_impl(); endifndef
return true;
}
// returns true when it slept
static boolean ping_impl(boolean okInCleanUp) { try {
if (ping_pauseAll && !isAWTThread()) {
do
Thread.sleep(ping_sleep);
while (ping_pauseAll);
return true;
}
if (ping_anyActions) { // don't allow sharing ping_actions
if (!okInCleanUp && !isTrue(ping_isCleanUpThread.get()))
failIfUnlicensed();
Object action = null;
synchronized(ping_actions) {
if (!ping_actions.isEmpty()) {
action = ping_actions.get(currentThread());
if (action instanceof Runnable)
ping_actions.remove(currentThread());
if (ping_actions.isEmpty()) ping_anyActions = false;
}
}
if (action instanceof Runnable)
((Runnable) action).run();
else if (eq(action, "cancelled"))
throw fail("Thread cancelled.");
}
return false;
} catch (Exception __e) { throw rethrow(__e); } }
static long nanoTime() {
return System.nanoTime();
}
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