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.*; class main { static class SynchronizedCollection implements Collection, Serializable { SynchronizedCollection() {} @java.io.Serial private static final long serialVersionUID = 3053995032091335093L; @SuppressWarnings("serial") // Conditionally serializable /*final*/ Collection c; // Backing Collection @SuppressWarnings("serial") // Conditionally serializable /*final*/ Object mutex; // Object on which to synchronize SynchronizedCollection(Collection c) { this.c = Objects.requireNonNull(c); mutex = this; } SynchronizedCollection(Collection c, Object mutex) { this.c = Objects.requireNonNull(c); this.mutex = Objects.requireNonNull(mutex); } public int size() { synchronized (mutex) {return c.size();} } public boolean isEmpty() { synchronized (mutex) {return c.isEmpty();} } public boolean contains(Object o) { synchronized (mutex) {return c.contains(o);} } public Object[] toArray() { synchronized (mutex) {return c.toArray();} } public T[] toArray(T[] a) { synchronized (mutex) {return c.toArray(a);} } public T[] toArray(java.util.function.IntFunction f) { synchronized (mutex) {return c.toArray(f);} } public Iterator iterator() { return c.iterator(); // Must be manually synched by user! } public boolean add(E e) { synchronized (mutex) {return c.add(e);} } public boolean remove(Object o) { synchronized (mutex) {return c.remove(o);} } public boolean containsAll(Collection coll) { synchronized (mutex) {return c.containsAll(coll);} } public boolean addAll(Collection coll) { synchronized (mutex) {return c.addAll(coll);} } public boolean removeAll(Collection coll) { synchronized (mutex) {return c.removeAll(coll);} } public boolean retainAll(Collection coll) { synchronized (mutex) {return c.retainAll(coll);} } public void clear() { synchronized (mutex) {c.clear();} } public String toString() { synchronized (mutex) {return c.toString();} } // Override default methods in Collection @Override public void forEach(java.util.function.Consumer consumer) { synchronized (mutex) {c.forEach(consumer);} } @Override public boolean removeIf(java.util.function.Predicate filter) { synchronized (mutex) {return c.removeIf(filter);} } @Override public Spliterator spliterator() { return c.spliterator(); // Must be manually synched by user! } @Override public java.util.stream.Stream stream() { return c.stream(); // Must be manually synched by user! } @Override public java.util.stream.Stream parallelStream() { return c.parallelStream(); // Must be manually synched by user! } @java.io.Serial private void writeObject(ObjectOutputStream s) throws IOException { synchronized (mutex) {s.defaultWriteObject();} } } static Iterator iterator(Iterable c) { return c == null ? emptyIterator() : c.iterator(); } static Iterator emptyIterator() { return Collections.emptyIterator(); } }