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.*;
// returns a prefiltered list of elements; you still need to do a
// full-text search on those.
// If it returns null, you have to search all elements
import java.text.NumberFormat;
class main {
static Collection doubleWordIndex_lookupString(DoubleWordIndex index, String query, Object... __) {
boolean debug = boolPar("debug",__);
List ranges = index.wordRanges(query);
if (empty(ranges)) return null;
List> sets = new ArrayList();
for (IntRange r : ranges) { // go through words in query
String word = substring(query, r);
Set l;
if (r.start == 0)
if (r.end == l(query)) // bad case - look for part of word
l = msmGetAllAsSet(index.index1.index, containingIC(index.index1.words(), word));
else { // look for ending of word - use reverse index
Collection words = prefixSubSet(index.index2.words(), reversed(word));
l = msmGetAllAsSet(index.index2.index, words);
if (debug)
print(n2(words) + "/" + nEntries(l) + " for: " + word);
}
else if (r.end == l(query)) { // look for start of word
Collection words = prefixSubSet(index.index1.words(), word);
l = msmGetAllAsSet(index.index1.index, words);
if (debug)
print(n2(words) + "/" + nEntries(l) + " for: " + word);
} else // look for complete word
l = index.get(word);
if (empty(l)) return l;
sets.add(l);
}
Set smallest = smallestCollection(sets), out = smallest;
for (Set set : sets) {
if (set == smallest) continue;
Set out2 = new HashSet();
for (A a : out)
if (set.contains(a))
out2.add(a);
out = out2;
}
return out;
}
static boolean boolPar(ThreadLocal tl) {
return boolOptParam(tl);
}
// defaults to false
static boolean boolPar(Object[] __, String name) {
return boolOptParam(__, name);
}
static boolean boolPar(String name, Object[] __) {
return boolOptParam(__, name);
}
static boolean boolPar(String name, Map __) {
return boolOptParam(name, __);
}
static boolean boolPar(String name, Object[] params, boolean defaultValue) {
return optParam(params, name, defaultValue);
}
static boolean empty(Collection c) { return c == null || c.isEmpty(); }
static boolean empty(CharSequence s) { return s == null || s.length() == 0; }
static boolean empty(Map map) { return map == null || map.isEmpty(); }
static boolean empty(Object[] o) { return o == null || o.length == 0; }
static boolean empty(Object o) {
if (o instanceof Collection) return empty((Collection) o);
if (o instanceof String) return empty((String) o);
if (o instanceof Map) return empty((Map) o);
if (o instanceof Object[]) return empty((Object[]) o);
if (o instanceof byte[]) return empty((byte[]) o);
if (o == null) return true;
throw fail("unknown type for 'empty': " + getType(o));
}
static boolean empty(Iterator i) { return i == null || !i.hasNext(); }
static boolean empty(double[] a) { return a == null || a.length == 0; }
static boolean empty(float[] a) { return a == null || a.length == 0; }
static boolean empty(int[] a) { return a == null || a.length == 0; }
static boolean empty(long[] a) { return a == null || a.length == 0; }
static boolean empty(byte[] a) { return a == null || a.length == 0; }
static boolean empty(short[] a) { return a == null || a.length == 0; }
static boolean empty(File f) { return getFileSize(f) == 0; }
static boolean empty(IntRange r) { return r == null || r.empty(); }
static String substring(String s, int x) {
return substring(s, x, strL(s));
}
static String substring(String s, int x, int y) {
if (s == null) return null;
if (x < 0) x = 0;
if (x >= s.length()) return "";
if (y < x) y = x;
if (y > s.length()) y = s.length();
return s.substring(x, y);
}
static String substring(String s, IntRange r) {
return r == null ? null : substring(s, r.start, r.end);
}
// convenience method for quickly dropping a prefix
static String substring(String s, CharSequence l) {
return substring(s, l(l));
}
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(Object o) {
return o == null ? 0
: o instanceof String ? l((String) o)
: o instanceof Map ? l((Map) o)
: o instanceof Collection ? l((Collection) o)
: o instanceof Object[] ? l((Object[]) o)
: o instanceof boolean[] ? l((boolean[]) o)
: o instanceof byte[] ? l((byte[]) o)
: o instanceof char[] ? l((char[]) o)
: o instanceof short[] ? l((short[]) o)
: o instanceof int[] ? l((int[]) o)
: o instanceof float[] ? l((float[]) o)
: o instanceof double[] ? l((double[]) o)
: o instanceof long[] ? l((long[]) o)
: (Integer) call(o, "size");
}
static int l(IntRange r) { return r == null ? 0 : r.length(); }
static Set msmGetAllAsSet(MultiSetMap mm, A... keys) {
Set l = new HashSet();
for (A key : keys)
l.addAll(mm.get(key));
return l;
}
static Set msmGetAllAsSet(MultiSetMap mm, Iterable keys) {
Set l = new HashSet();
for (A key : unnull(keys))
l.addAll(mm.get(key));
return l;
}
static List containingIC(Collection l, final String x) {
List out = new ArrayList();
for (String s : unnull(l))
if (cic(s, x))
out.add(s);
return out;
}
static List containingIC(String x, Collection l) {
return containingIC(l, x);
}
static NavigableSet prefixSubSet(NavigableSet set, String prefix) {
return set.subSet(prefix, true, prefix + Character.MAX_VALUE, true);
}
static List reversed(Collection l) {
return reversedList(l);
}
static List reversed(A[] l) {
return reversedList(asList(l));
}
static String reversed(String s) {
return reversedString(s);
}
static volatile StringBuffer local_log = new StringBuffer(); // not redirected
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