/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/**
* Created by green on 19.12.15.
*/
class steck {
private int size;
private int capacity;
public steck(){
capacity = 2;
}
public steck(int x){
capacity = x;
}
public boolean isEmpty(){
return size == 0;
}
private void resize(int x){
System.
arraycopy(date,
0, newDate,
0, size
); date = null;
date = newDate;
}
if(size == capacity){
resize(2*capacity);
}
date[size++] = x;
}
if(isEmpty()){
return null;
}
if(size < capacity/2){
resize(capacity/2);
}
size = size -1;
return temp;
}
if(isEmpty()) return null;
return date[size-1];
}
public void clear(){
size = 0;
}
public int size(){
return size;
}
public int getCapacity(){
return size;
}
}
class Ideone
{
{
steck test = new steck(4);
System.
out.
println(test.
isEmpty()); test.push(12);
System.
out.
println(test.
isEmpty()); System.
out.
println(test.
peek()); test.push(13);
test.push(14);
test.push(15);
test.push(16);
test.push(17);
test.push('(');
System.
out.
println(test.
size()); System.
out.
println(test.
peek().
equals('(')); test.pop();
System.
out.
println(test.
peek()); test.pop();
System.
out.
println(test.
peek()); test.pop();
System.
out.
println(test.
peek()); test.pop();
System.
out.
println(test.
peek()); test.pop();
System.
out.
println(test.
peek()); System.
out.
println(test.
isEmpty()); test.pop();
System.
out.
println(test.
peek()); test.pop();
System.
out.
println(test.
isEmpty()); }
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7Ci8qKgogKiBDcmVhdGVkIGJ5IGdyZWVuIG9uIDE5LjEyLjE1LgogKi8KY2xhc3Mgc3RlY2sgewogICAgcHJpdmF0ZSBpbnQgc2l6ZTsKICAgIHByaXZhdGUgT2JqZWN0W10gZGF0ZTsKICAgIHByaXZhdGUgaW50IGNhcGFjaXR5OwogICAgcHVibGljIHN0ZWNrKCl7CiAgICAgICAgZGF0ZSA9IG5ldyBPYmplY3RbMl07CiAgICAgICAgY2FwYWNpdHkgPSAyOwogICAgfQogICAgcHVibGljIHN0ZWNrKGludCB4KXsKICAgICAgICBkYXRlID0gbmV3IE9iamVjdFt4XTs7CiAgICAgICAgY2FwYWNpdHkgPSB4OwogICAgfQoKICAgIHB1YmxpYyBib29sZWFuIGlzRW1wdHkoKXsKICAgICAgICByZXR1cm4gc2l6ZSA9PSAwOwogICAgfQoKICAgIHByaXZhdGUgdm9pZCByZXNpemUoaW50IHgpewogICAgICAgIE9iamVjdFtdIG5ld0RhdGUgPSBuZXcgT2JqZWN0W3hdOwogICAgICAgIFN5c3RlbS5hcnJheWNvcHkoZGF0ZSwgMCwgbmV3RGF0ZSwgMCwgc2l6ZSk7CiAgICAgICAgZGF0ZSA9IG51bGw7CiAgICAgICAgZGF0ZSA9IG5ld0RhdGU7CiAgICB9CgogICAgcHVibGljIHZvaWQgcHVzaChPYmplY3QgeCl7CiAgICAgICAgaWYoc2l6ZSA9PSBjYXBhY2l0eSl7CiAgICAgICAgICAgIHJlc2l6ZSgyKmNhcGFjaXR5KTsKICAgICAgICB9CiAgICAgICAgZGF0ZVtzaXplKytdID0geDsKICAgIH0KCiAgICBwdWJsaWMgT2JqZWN0IHBvcCgpewogICAgICAgIGlmKGlzRW1wdHkoKSl7CiAgICAgICAgICAgIHJldHVybiBudWxsOwogICAgICAgIH0KICAgICAgICBpZihzaXplIDwgY2FwYWNpdHkvMil7CiAgICAgICAgICAgIHJlc2l6ZShjYXBhY2l0eS8yKTsKICAgICAgICB9CiAgICAgICAgT2JqZWN0IHRlbXAgPSBkYXRlW3NpemUgLTFdOwogICAgICAgIHNpemUgPSBzaXplIC0xOwogICAgICAgIHJldHVybiB0ZW1wOwogICAgfQoKICAgIHB1YmxpYyBPYmplY3QgcGVlaygpewogICAgICAgIGlmKGlzRW1wdHkoKSkgcmV0dXJuIG51bGw7CiAgICAgICAgcmV0dXJuIGRhdGVbc2l6ZS0xXTsKICAgIH0KCiAgICBwdWJsaWMgdm9pZCBjbGVhcigpewogICAgICAgIHNpemUgPSAwOwogICAgfQoKICAgIHB1YmxpYyBpbnQgc2l6ZSgpewogICAgICAgIHJldHVybiBzaXplOwogICAgfQogICAgcHVibGljIGludCBnZXRDYXBhY2l0eSgpewogICAgICAgIHJldHVybiBzaXplOwogICAgfQp9CgpjbGFzcyBJZGVvbmUKewoJcHVibGljIHN0YXRpYyB2b2lkIG1haW4gKFN0cmluZ1tdIGFyZ3MpIHRocm93cyBqYXZhLmxhbmcuRXhjZXB0aW9uCgl7CgkJc3RlY2sgdGVzdCA9IG5ldyBzdGVjayg0KTsKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4odGVzdC5pc0VtcHR5KCkpOwogICAgICAgIHRlc3QucHVzaCgxMik7CiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKHRlc3QuaXNFbXB0eSgpKTsKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4odGVzdC5wZWVrKCkpOwogICAgICAgIHRlc3QucHVzaCgxMyk7CiAgICAgICAgdGVzdC5wdXNoKDE0KTsKICAgICAgICB0ZXN0LnB1c2goMTUpOwogICAgICAgIHRlc3QucHVzaCgxNik7CiAgICAgICAgdGVzdC5wdXNoKDE3KTsKICAgICAgICB0ZXN0LnB1c2goJygnKTsKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4odGVzdC5zaXplKCkpOwogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbih0ZXN0LnBlZWsoKS5lcXVhbHMoJygnKSk7CiAgICAgICAgdGVzdC5wb3AoKTsKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4odGVzdC5wZWVrKCkpOwogICAgICAgIHRlc3QucG9wKCk7CiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKHRlc3QucGVlaygpKTsKICAgICAgICB0ZXN0LnBvcCgpOwogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbih0ZXN0LnBlZWsoKSk7CiAgICAgICAgdGVzdC5wb3AoKTsKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4odGVzdC5wZWVrKCkpOwogICAgICAgIHRlc3QucG9wKCk7CiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKHRlc3QucGVlaygpKTsKICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4odGVzdC5pc0VtcHR5KCkpOwogICAgICAgIHRlc3QucG9wKCk7CiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKHRlc3QucGVlaygpKTsKICAgICAgICB0ZXN0LnBvcCgpOwogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbih0ZXN0LmlzRW1wdHkoKSk7Cgl9Cn0=