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.*; import java.time.Duration; import java.lang.invoke.VarHandle; import java.lang.invoke.MethodHandles; // assumes that each set function is called exactly once // (but it doesn't matter which thread you call each of them from.) class main { static class LongPairCollector extends AtomicCounter { volatile long valueOfA; volatile long valueOfB; final LongConsumer a = __1 -> setA(__1); final LongConsumer b = __2 -> setB(__2); void setA(long a) { valueOfA = a; itemReceived(); } void setB(long b) { valueOfB = b; itemReceived(); } final LongConsumer setterForA(){ return setA(); } LongConsumer setA() { return a; } final LongConsumer setterForB(){ return setB(); } LongConsumer setB() { return b; } void itemReceived() { if (incCounter() == 2) complete(valueOfA, valueOfB); } // override me void complete(long a, long b) {} } static class AtomicCounter { volatile int counter; // statically get var handles private static final VarHandle vhCounter; static { try { var l = MethodHandles.lookup(); vhCounter = l.findVarHandle(AtomicCounter.class, "counter", int.class); } catch (Exception __e) { throw rethrow(__e); } } final int inc(){ return incCounter(); } int incCounter() { return (int) vhCounter.getAndAdd(this, 1)+1; } } 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 void _handleError(Error e) { //call(javax(), '_handleError, e); } }