include[HTML_REMOVED]
include[HTML_REMOVED]
include[HTML_REMOVED]
include[HTML_REMOVED]
int i, j, n, m, temp, temp1, sum, l;
char op;
int val[100005], nex[100005], head, idx;
void insertBeforeHead(int x);
void insert(int k, int x);
void Delete(int k);
int main()
{
head = -1, idx = 0;
scanf(“%d”, &m);
for(i=1;i<=m;i){
getchar();
scanf(“%c%d”, &op, &temp);
if(op==’I’){
scanf(“%d”, &temp1);
insert(temp-1, temp1);
}else if(op==’H’){
insertBeforeHead(temp);
}else if(op==’D’){
if(temp==0){
head = nex[head];
}else Delete(temp-1);
}
}
for(i=head; i!=-1; i = nex[i]){
printf(“%d “, val[i]);
}
return 0;
}
void insertBeforeHead(int x){
val[idx] = x;
nex[idx] = head;
head = idx;
idx;
}
void insert(int k, int x){
val[idx] = x;
nex[idx] = nex[k];
nex[k] = idx;
idx++;
}
void Delete(int k){
nex[k] = nex[nex[k]];
}