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 SynchronizedCircularBuffer { SynchronizedCircularBuffer() {} A[] buffer; long base; // elements dropped due to overcapacity int size; // elements actually contained SynchronizedCircularBuffer(int capacity) { buffer = (A[]) new Object[capacity]; } synchronized void add(A a) { if (size == buffer.length) { --size; ++base; } buffer[(int) ((base+size) % buffer.length)] = a; ++size; } synchronized A get(long pos) { if (pos < base || pos >= base+size) return null; return buffer[(int) (pos % buffer.length)]; } synchronized int size() { return size; } synchronized int capacity() { return buffer.length; } synchronized boolean isFull() { return size() == capacity(); } synchronized long getBase() { return base; } }}