class CircularBuffer<T> {
private T
[] array
= (T
[]) (new Object[1<<10]); private int start = 0, end = 0;
public T get(int i) {
assert(0 <= i && i < size());
return array[mod(start + i)];
}
public void set(int i, T elem) {
assert(0 <= i && i < size());
array[mod(start + i)] = elem;
}
public void append(T elem) {
if (size() == array.length) resize();
array[mod(end++)] = elem;
}
public void prepend(T elem) {
if (size() == array.length) resize();
array[mod(--start)] = elem;
}
public void dropFirst(int count) {
assert(0 <= count && count <= size());
start += count;
}
public void dropLast(int count) {
assert(0 <= count && count <= size());
end -= count;
}
public int size() {
return mod(mod(end) - mod(start));
}
public void clear() {
start = end = 0;
}
private int mod(int x) {
return Math.
floorMod(x, array.
length); }
private void resize() {
T
[] array2
= (T
[])(new Object[2*array.
length]); for(int i = 0; i < size(); i++) {
array2[i] = get(i);
}
end = size();
start = 0;
array = array2;
}
public static void main
(String[] args
) { CircularBuffer<Integer> buffer = new CircularBuffer<Integer>();
for (int i = 0; i < 1027; ++i) {
buffer.append(0);
}
System.
out.
println(buffer.
size()); }
}