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 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 javax.imageio.*;
import java.math.*;
class main {
static String pnlToString(String prefix, Iterable l) {
return hijackPrint(new Runnable() { public void run() { try { pnl(prefix, l) ;
} catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "pnl(prefix, l)"; }});
}
static String pnlToString(final Iterable l) {
return hijackPrint(new Runnable() { public void run() { try { pnl(l) ;
} catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "pnl(l)"; }});
}
static String pnlToString(final A[] l) {
return hijackPrint(new Runnable() { public void run() { try { pnl(l) ;
} catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "pnl(l)"; }});
}
static String pnlToString(final Map map) {
return hijackPrint(new Runnable() { public void run() { try { pnl(map) ;
} catch (Exception __e) { throw rethrow(__e); } } public String toString() { return "pnl(map)"; }});
}
static String pnlToString(MultiMap map) {
return pnlToString(multiMapToMap(map));
}
static String hijackPrint(Object r) {
final StringBuilder buf = new StringBuilder();
Object old = interceptPrintInThisThread(new F1() {
Boolean get(String s) {
buf.append(s);
return false;
}
});
try {
callF(r);
return str(buf);
} finally {
interceptPrintInThisThread(old);
}
}
static A pnl(String prefix, A l) {
printNumberedLines(prefix, l);
return l;
}
static A pnl(A l) {
printNumberedLines(l);
return l;
}
static A pnl(A map) {
printNumberedLines(map);
return map;
}
static A[] pnl(A[] a) {
printNumberedLines(a);
return a;
}
static String pnl(String s) {
printNumberedLines(lines(s));
return s;
}
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 Map> multiMapToMap(MultiMap m) {
return m == null ? null : m.data;
}
// f can return false to suppress regular printing
// call print_raw within f to actually print something
// f preferrably is F1
static Object interceptPrintInThisThread(Object f) {
Object old = print_byThread().get();
print_byThread().set(f);
return old;
}
// 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);
}
} 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 Map> callF_cache = newDangerousWeakHashMap();
static A callF(F0 f) {
return f == null ? null : f.get();
}
static B callF(F1 f, A a) {
return f == null ? null : f.get(a);
}
static B callF(IF1 f, A a) {
return f == null ? null : f.get(a);
}
static C callF(IF2 f, A a, B b) {
return f == null ? null : f.get(a, b);
}
static void callF(VF1 f, A a) {
if (f != null) f.get(a);
}
static Object callF(Object f, Object... args) { try {
if (f instanceof String)
return callMC((String) f, args);
if (f instanceof Runnable) {
((Runnable) f).run();
return null;
}
if (f == null) return null;
Class c = f.getClass();
ArrayList methods;
synchronized(callF_cache) {
methods = callF_cache.get(c);
if (methods == null)
methods = callF_makeCache(c);
}
int n = l(methods);
if (n == 0) {
throw fail("No get method in " + getClassName(c));
}
if (n == 1) return invokeMethod(methods.get(0), f, args);
for (int i = 0; i < n; i++) {
Method m = methods.get(i);
if (call_checkArgs(m, args, false))
return invokeMethod(m, f, args);
}
throw fail("No matching get method in " + getClassName(c));
} catch (Exception __e) { throw rethrow(__e); } }
// used internally
static ArrayList callF_makeCache(Class c) {
ArrayList l = new ArrayList();
Class _c = c;
do {
for (Method m : _c.getDeclaredMethods())
if (m.getName().equals("get")) {
makeAccessible(m);
l.add(m);
}
if (!l.isEmpty()) break;
_c = _c.getSuperclass();
} while (_c != null);
callF_cache.put(c, l);
return l;
}
static String str(Object o) {
return o == null ? "null" : o.toString();
}
static String str(char[] c) {
return new String(c);
}
/*static L printNumberedLines(L l) {
printNumberedLines((Collection) l);
ret l;
}
static L printNumberedLines(S prefix, L l) {
printNumberedLines(prefix, (Collection) l);
ret l;
}*/
static void printNumberedLines(Map map) {
printNumberedLines(mapToLines(map));
}
static A printNumberedLines(A l) {
int i = 0;
if (l != null) for (Object a : l) print((++i) + ". " + str(a));
return l;
}
static A printNumberedLines(String prefix, A l) {
int i = 0;
if (l != null) for (Object a : l) print(prefix + (++i) + ". " + str(a));
return l;
}
static void printNumberedLines(Object[] l) {
printNumberedLines(asList(l));
}
static void printNumberedLines(Object o) {
printNumberedLines(lines(str(o)));
}
static String lines(Iterable lines) { return fromLines(lines); }
static String lines(Object[] lines) { return fromLines(asList(lines)); }
static List lines(String s) { return toLines(s); }
static void _handleError(Error e) {
call(javax(), "_handleError", e);
}
static ThreadLocal