#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
vector<int>a;
int n;
cin>>n;
int q;
int opt;
int opt1;
while(n--){
cin>>q;
if(q==1){
cin>>opt;
a.push_back(opt);
}else if(q==2){
a.pop_back();
}else if(q==3){
cin>>opt;
cout<<a[opt]<<endl;
}else if(q==4){
cin>>opt;
cin>>opt1;
a.insert(a.begin()+opt+1,opt1);
}else if(q==5){
sort(a.begin(),a.end());
}else if(q==6){
sort(a.begin(),a.end());
reverse(a.begin(),a.end());
}else if(q==7){
cout<<a.size()<<endl;
}else if(q==8){
for(int i=0;i<a.size();i++){
cout<<a[i]<<" ";
}
cout<<endl;
}
}
return 0;
}