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.*;
// now synchronized
import java.text.NumberFormat;
import static x30_pkg.x30_util.DynamicObject;
class main {
static class MultiBest {
MultiBest() {}
Collection best = new ArrayList();
double score = negativeInfinity();
boolean verboseNewBest = false;
final double score(){ return bestScore(); }
final double getScore(){ return bestScore(); }
synchronized double bestScore() {
return best == null ? minusInfinity() : score;
}
boolean isEmpty() { return best.isEmpty(); }
synchronized float floatScoreOr(float defaultValue) {
return best == null ? defaultValue : (float) score;
}
void put(Pair extends A, Double> p) {
if (p != null) put(p.a, p.b);
}
void put(A a, double score) {
ping();
boolean newBest = false;
if (a != null) synchronized(this) {
if (score > this.score) {
best.clear();
this.score = score;
newBest = true;
}
if (score >= this.score) {
best.add(a);
}
}
if (newBest && verboseNewBest) print("New best! " + this);
}
synchronized Collection get() { return best; }
synchronized boolean has() { return !isEmpty(); }
public String toString() {
return isEmpty() ? "-"
: "Score " + formatDouble_significant2(score, 4)
+ (tied() ? ", " + nWinners(duplicity()) : "")
+ ": " + joinWithComma(map(__13 -> stringify(__13), best));
}
String stringify(A a) { return str(a); }
boolean tied() { return duplicity() > 1; }
int duplicity() { return best.size(); }
synchronized void clear() { best.clear(); score = 0; }
}
static double negativeInfinity() {
return Double.NEGATIVE_INFINITY;
}
static double minusInfinity() {
return negativeInfinity();
}
static void put(Map map, A a, B b) {
if (map != null) map.put(a, b);
}
static void put(List l, int i, A a) {
if (l != null && i >= 0 && i < l(l)) l.set(i, a);
}
//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 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