#include <iostream>
#include <string>
using namespace std;
int arr[10001];
int index;
void push(int number)
{
arr[index] = number;
index++;
}
int size()
{
return index;
}
int top()
{
return (!size()) ? -1 : arr[index - 1];
}
bool empty()
{
return (!size()) ? true : false;
}
void pop()
{
if (!size())
cout << -1 << endl;
else
{
cout << arr[index - 1] << endl;
index--;
}
}
int main(void)
{
string com; //명령어
int num; //push할 정수
int n; //테스트 케이스 수
cin >> n;
while (n--)
{
cin >> com;
if ("push" == com)
{
cin >> num; //push일 경우에만 정수 입력
push(num);
}
else if ("top" == com)
cout << top() << endl;
else if ("size" == com)
cout << size() << endl;
else if ("empty" == com)
cout << empty() << endl;
else if ("pop" == com)
pop();
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKaW50IGFyclsxMDAwMV07CmludCBpbmRleDsKCnZvaWQgcHVzaChpbnQgbnVtYmVyKQp7CglhcnJbaW5kZXhdID0gbnVtYmVyOwoJaW5kZXgrKzsKfQppbnQgc2l6ZSgpCnsKCXJldHVybiBpbmRleDsKfQoKaW50IHRvcCgpCnsKCXJldHVybiAoIXNpemUoKSkgPyAtMSA6IGFycltpbmRleCAtIDFdOwp9Cgpib29sIGVtcHR5KCkKewoJcmV0dXJuICghc2l6ZSgpKSA/IHRydWUgOiBmYWxzZTsKfQoKdm9pZCBwb3AoKQp7CglpZiAoIXNpemUoKSkKCQljb3V0IDw8IC0xIDw8IGVuZGw7CgllbHNlCgl7CgkJY291dCA8PCBhcnJbaW5kZXggLSAxXSA8PCBlbmRsOwoJCWluZGV4LS07Cgl9Cn0KaW50IG1haW4odm9pZCkKewoJc3RyaW5nIGNvbTsJCS8v66qF66C57Ja0CglpbnQgbnVtOwkJLy9wdXNo7ZWgIOygleyImAoJaW50IG47CQkJLy/thYzsiqTtirgg7LyA7J207IqkIOyImAoJY2luID4+IG47CgkKCXdoaWxlIChuLS0pCgl7CgkJY2luID4+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