#include<iostream> #include<memory.h> #include<string> #define N 10010 using namespace std; int main() { int m,i,a[N],b[N],top,n,y,j; string x[N]; memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); cin>>m; top=0; for(i=1;i<=m;i++) { cin>>y; a[++top]=y; } cin>>n; j=0; for(i=1;i<=n;i++) { cin>>x[i]; if(x[i]!="LENGTH") cin>>b[i]; } for(i=1;i<=n;i++) { if(x[i]=="JOIN") { a[++top]=b[i]; } else if(x[i]=="ASK") { cout<<a[b[i]]<<endl; } else if(x[i]=="LEAVE") { for(int k=b[i];k<=top;k++) { a[k]=a[k+1]; } top--; } else if(x[i]=="LENGTH") { cout<<top<<endl; } else if(x[i]=="FINISH") { for(int o=1;o<=top-b[i];o++) a[o]=a[o+b[i]]; top=top-b[i]; } } return 0; }