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.*; // persistable (if you set "operation", make sure it's with a // persistable object) class main { static class AllOnAllOperation implements Steppable { Producer> allOnAll; // e.g. an instance of AllOnAll AllOnAllOperation() {} AllOnAllOperation(Producer> allOnAll, IVF2 operation) { this.operation = operation; this.allOnAll = allOnAll;} IVF2 operation; void operation(A a, B b) { if (operation != null) operation.get(a, b); else operation_base(a, b); } final void operation_fallback(IVF2 _f, A a, B b) { if (_f != null) _f.get(a, b); else operation_base(a, b); } void operation_base(A a, B b) {} public boolean step() { Pair p = allOnAll.next(); if (p == null) return false; operation(p.a, p.b); return true; } } static interface Producer { public A next(); // null when end }static interface Steppable { public boolean step(); // return false if done }static interface IVF2 { void get(A a, B b); }static class Pair implements Comparable> { A a; B b; Pair() {} Pair(A a, B b) { this.b = b; this.a = a;} public int hashCode() { return hashCodeFor(a) + 2*hashCodeFor(b); } public boolean equals(Object o) { if (o == this) return true; if (!(o instanceof Pair)) return false; Pair t = (Pair) o; return eq(a, t.a) && eq(b, t.b); } public String toString() { return "<" + a + ", " + b + ">"; } public int compareTo(Pair p) { if (p == null) return 1; int i = ((Comparable) a).compareTo(p.a); if (i != 0) return i; return ((Comparable) b).compareTo(p.b); } } static int hashCodeFor(Object a) { return a == null ? 0 : a.hashCode(); } static boolean eq(Object a, Object b) { return a == b || a != null && b != null && a.equals(b); } static String str(Object o) { return o == null ? "null" : o.toString(); } static String str(char[] c) { return new String(c); } }