#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
int n;
int arr[110];
string str;
int main(){
cin >> n;
int top = 0;
for(int i = 1; i <= n; i++){
cin >> str;
if(str == "push"){
top++;
cin >> arr[top];
} else if(str == "pop"){
cout << arr[top] << endl;
top--;
} else if(str == "top"){
cout << arr[top] << endl;
}
}
return 0;
}
#include
#define endl '\n'
using namespace std;
int n;
int arr[110];
string str;
int main(){
cin >> n;
int top = 0; // top表示当前栈中有的元素个数
for(int i = 1; i <= n; i++){
cin >> str;
if(str == "push"){
top++;
cin >> arr[top];
} else if(str == "pop"){
cout << arr[top] << endl;
top--;
} else if(str == "top"){
cout << arr[top] << endl;
}
}
return 0;
}