#include <bits/stdc++.h>
using namespace std;
struct node{
int d;
int n;
};
node a[10000]={{0,0},{5,3},{4,5},{3,2},{2,0},{1,4}};
int n=5,i,h=1;
int insert(){尾删
}
int push(int x){头增
n++;
a[n].d=x;
a[n].n=h;
h=n;
return 0;
}
int pop(){头删
h=a[h].n;
return 0;
}
int weizeng(int x){尾增
n++;
i=a[h].n;
while(a[i].n!=0){
i=a[i].n;
}
a[i].n=n;
return 0;
}
int display(){输出
cout<<a[h].d<<" ";
i=a[h].n;shuchu
while(a[i].n!=0){
cout<<a[i].d<<" ";
i=a[i].n;
}
cout<<a[i].d;
}
int main(){
int x;
string m;
n=5;h=1;
while(1){
cin>>m;
if(m=="push"){
cin>>x;
push(x);
}
if(m=="pop"){
pop();
}
if(m=="insert"){
insert();
}
if(m=="weizeng"){
cin>>x;
weizeng(x);
}
if(m=="display"){
display();
}
}
}