#include <stdio.h> #include <iostream> using namespace std; int main() { int k,n,x,left=0,right=0,isEmpty=0; cin>>n; int a[n]; for(int l=0;l<=n;l++){ a[l] = 0; } for(int i=0;i<n;i++){ cin>>k; if(k==1){ cin>>x; a[right] = x; right++; isEmpty++; } if(k==2){ if(isEmpty>0) cout<<a[left]<<endl; else cout<<"-1"<<endl; } if(k==3){ if(isEmpty>0){ a[left] =0; isEmpty--; left++; } } /*for(int j=0;j<n;j++){ cout<<a[j]<<" "; } cout<<endl;*/ } return 0; }
//AC 0.2s 720KB