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; class main { static class HashedByteArray implements Comparable { byte[] data; int hashCode; HashedByteArray() {} HashedByteArray(byte[] data) { this.data = data;} public int hashCode() { if (hashCode == 0) hashCode = oneIfZero(arrayHashCode(data)); return hashCode; } public boolean equals(Object o) { if (o instanceof HashedByteArray) return this == ((HashedByteArray) o) || hashCode() == ((HashedByteArray) o).hashCode() && byteArraysEqual(data, ((HashedByteArray) o).data); return false; } // we interpret the bytes as ubytes public int compareTo(HashedByteArray a) { return Arrays.compareUnsigned(data, a.data); } public String toString() { return bytesToHex(data); } } static int oneIfZero(int i) { return i == 0 ? 1 : i; } static int arrayHashCode(byte[] a) { return Arrays.hashCode(a); } static int hashCode(Object a) { return a == null ? 0 : a.hashCode(); } static int hashCode(long l) { return Long.hashCode(l); } static int hashCode(double d) { return Double.hashCode(d); } static boolean byteArraysEqual(byte[] a, byte[] b) { return Arrays.equals(a, b); } public static String bytesToHex(byte[] bytes) { return bytesToHex(bytes, 0, bytes.length); } public static String bytesToHex(byte[] bytes, int ofs, int len) { StringBuilder stringBuilder = new StringBuilder(len*2); for (int i = 0; i < len; i++) { String s = "0" + Integer.toHexString(bytes[ofs+i]); stringBuilder.append(s.substring(s.length()-2, s.length())); } return stringBuilder.toString(); } }