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.*;
// combines a value with the merged token range of two PWTs
import static x30_pkg.x30_util.DynamicObject;
class main {
static ParsedWithTokens pwt_combine(A value, ParsedWithTokens p1, ParsedWithTokens p2) {
assertSame(p1.tok, p2.tok);
return new ParsedWithTokens(value, p1.tok, min(p1.iStart, p2.iStart), max(p1.iRemaining, p2.iRemaining));
}
// increases the token range of a PWT merging another PWT
static ParsedWithTokens pwt_combine(ParsedWithTokens p1, ParsedWithTokens p2) {
return pwt_combine(p1.get(), p1, p2);
}
// Second meaning: Combines all parses pb out of a list B
// with all parses pa out of a list A
// where pb occurred to the right of pb.
// (Also applies a user-defined combination function merging pa and pb into a new PWT value.)
static List> pwt_combine(Iterable> l1, Iterable> l2, IF2 f) {
List> out = new ArrayList();
for (ParsedWithTokens a : l1)
for (ParsedWithTokens b : pwt_toTheRightOf(l2, a))
out.add(pwt_combine(f.get(a.get(), b.get()), a, b));
return out;
}
// Same thing with 3 lists.
static List> pwt_combine(Iterable> l1, Iterable> l2, Iterable> l3, IF3 f) {
List> out = new ArrayList();
for (ParsedWithTokens a : l1)
for (ParsedWithTokens b : pwt_toTheRightOf(l2, a))
for (ParsedWithTokens c : pwt_toTheRightOf(l3, b))
out.add(pwt_combine(f.get(a.get(), b.get(), c.get()), a, c));
return out;
}
static void assertSame(Object a, Object b) { assertSame("", a, b); }
static void assertSame(String msg, Object a, Object b) {
if (a != b)
throw fail(joinNemptiesWithColon(msg, a + " != " + b + " (" + identityHash(a) + "/" + identityHash(b) + ")"));
}
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 int max(int a, int b) { return Math.max(a, b); }
static int max(int a, int b, int c) { return max(max(a, b), c); }
static long max(int a, long b) { return Math.max((long) a, b); }
static long max(long a, long b) { return Math.max(a, b); }
static double max(int a, double b) { return Math.max((double) a, b); }
static float max(float a, float b) { return Math.max(a, b); }
static double max(double a, double b) { return Math.max(a, b); }
static int max(Collection c) {
int x = Integer.MIN_VALUE;
for (int i : c) x = max(x, i);
return x;
}
static double max(double[] c) {
if (c.length == 0) return Double.MIN_VALUE;
double x = c[0];
for (int i = 1; i < c.length; i++) x = Math.max(x, c[i]);
return x;
}
static float max(float[] c) {
if (c.length == 0) return Float.MAX_VALUE;
float x = c[0];
for (int i = 1; i < c.length; i++) x = Math.max(x, c[i]);
return x;
}
static byte max(byte[] c) {
byte x = -128;
for (byte d : c) if (d > x) x = d;
return x;
}
static short max(short[] c) {
short x = -0x8000;
for (short d : c) if (d > x) x = d;
return x;
}
static int max(int[] c) {
int x = Integer.MIN_VALUE;
for (int d : c) if (d > x) x = d;
return x;
}
static > A max(A a, A b) {
return cmp(a, b) >= 0 ? a : b;
}
static IterableIterator> pwt_toTheRightOf(Iterable> l, ParsedWithTokens b) {
return filterI(iterator(l), p -> {
//print("ttro: " + p.iStart + " / " + b.iRemaining);
return p.iStart == (b.iRemaining | 1);
});
}
static RuntimeException fail() { throw new RuntimeException("fail"); }
static RuntimeException fail(Throwable e) { throw asRuntimeException(e); }
static RuntimeException fail(Object msg) { throw new RuntimeException(String.valueOf(msg)); }
static RuntimeException fail(Object... objects) { throw new Fail(objects); }
static RuntimeException fail(String msg) { throw new RuntimeException(msg == null ? "" : msg); }
static RuntimeException fail(String msg, Throwable innerException) { throw new RuntimeException(msg, innerException); }
static String joinNemptiesWithColon(String... strings) {
return joinNempties(": ", strings);
}
static String joinNemptiesWithColon(Collection strings) {
return joinNempties(": ", strings);
}
static int identityHash(Object o) {
return identityHashCode(o);
}
static int cmp(Number a, Number b) {
return a == null ? b == null ? 0 : -1 : cmp(a.doubleValue(), b.doubleValue());
}
static int cmp(double a, double b) {
return a < b ? -1 : a == b ? 0 : 1;
}
static int cmp(int a, int b) {
return a < b ? -1 : a == b ? 0 : 1;
}
static int cmp(long a, long b) {
return a < b ? -1 : a == b ? 0 : 1;
}
static int cmp(Object a, Object b) {
if (a == null) return b == null ? 0 : -1;
if (b == null) return 1;
return ((Comparable) a).compareTo(b);
}
static IterableIterator filterI(Iterator it, F1 f) {
return filterIterator(it, f);
}
static IterableIterator filterI(Iterator it, IF1 f) {
return filterIterator(it, f);
}
static IterableIterator filterI(F1 f, Iterator it) {
return filterIterator(f, it);
}
static IterableIterator filterI(IF1 f, Iterator it) {
return filterIterator(f, it);
}
static IterableIterator filterI(IF1 f, Iterable it) {
return filterIterator(f, iterator(it));
}
static Iterator iterator(Iterable c) {
return c == null ? emptyIterator() : c.iterator();
}
static RuntimeException asRuntimeException(Throwable t) {
if (t instanceof Error)
_handleError((Error) t);
return t instanceof RuntimeException ? (RuntimeException) t : new RuntimeException(t);
}
static String joinNempties(String sep, Object... strings) {
return joinStrings(sep, strings);
}
static String joinNempties(String sep, Iterable strings) {
return joinStrings(sep, strings);
}
static int identityHashCode(Object o) {
return System.identityHashCode(o);
}
static IterableIterator filterIterator(final Iterator it, final F1 f) {
if (it == null) return null;
return iff(new F0