题目链接

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e4+5;
int arr[maxn];
int main(){
	int n,x;
	char c;
	while(cin>>n){
		int k=0;
		for(int i=0;i<n;i++){
			cin>>c;
			if(c=='P'){
				cin>>x;
				arr[k++]=x;
			}else if(c=='A'){
				if(k-1 < 0) cout<<"E"<<endl;
				else cout<<arr[k-1]<<endl;
			}else if(c=='O'){
				if(k<1) continue;
				else k--;
			}	
		}
		cout<<endl;
	}
	
	return 0;
}