#include<cstdio> #include<stack> using namespace std; int main() { int n ; char x; int y ; stack<int> myStack; while (scanf("%d", &n) != EOF) { for (int i = 0 ; i < n ; ++i) { scanf("%c", &x); if (x == 'P') { scanf("%d", &y); myStack.push(y); } else if (x == 'O') { if (!myStack.empty()) { myStack.pop(); } } else if (x == 'A') { if (myStack.empty()) { printf("E\n"); } else { printf("%d\n", myStack.top()); } } } } }