#include<iostream>
using namespace std;
const int N = 100010;
int idx, head, va[N], ne[N];
int n;
void addtohead(int x) {
va[idx] = x;
ne[idx] = head;
head = idx++;
}
void add(int k, int x) {
va[idx] = x;
ne[idx] = ne[k];
ne[k] = idx++;
}
void remove(int k) {
ne[idx] = ne[ne[k]];
}
void init() {
head = -1;//这里用head指向一个空来表示tail
idx = 0;
}
int main() {
cin >> n;
init();//初始化
for (int i = 0; i < n; i++) {
char s;
cin >> s;
if (s == 'H') {
int x;
cin >> x;
addtohead(x);
}
if (s == 'D') {
int k;
cin >> k;
if (k == 0) head = ne[head];//删除头节点
else remove(k - 1);//注意删除第k个输入后面的数,那函数里放的是下标,k要减去1
}
if (s == 'I') {
int k, x;
cin >> k >> x;
add(k - 1, x);//同样的,第k个数,和下标不同,所以要减1
}
}
for (int i = head; i != -1; i = ne[i]) cout << va[i] << ' ';
cout << endl;
return 0;
}