#include <bits/stdc++.h> using namespace std; class MyStack { private: int size; vector<long long> mem; // 用 vector 扩容有保证! vector<long long> mxm; public: MyStack(): size(0) { mem.resize(100000); mxm.resize(100000); } int push(long long x) { mem[size] = x; if (size == 0) { mxm[size] = x; } else { if (mxm[size - 1] > x) { mxm[size] = mxm[size - 1]; } else { mxm[size] = x; } } size++; return size; } long long pop() { if(size == 0) return -1; long long ret = mem[size-1]; size--; return ret; } int clear() { if (size == 0) return -1; long long ret = mxm[size - 1]; size = 0; return ret; } }; int main() { int q; cin >> q; MyStack stk; string s; getline(cin, s); while (q--) { getline(cin, s); if (s.find("PUSH") != string::npos) { int idx = s.find(" "); // cout << atoi(s.substr(idx + 1).c_str()) << endl; cout << stk.push(atoi(s.substr(idx + 1).c_str())) << endl; } else if ("POP" == s) { cout << stk.pop() << endl; } else { cout << stk.clear() << endl; } } return 0; }