include [HTML_REMOVED]
using namespace std;
const int N = 100000;
int head, e[N], ne[N], idx;
//初始化
void init()
{
head = -1;
idx = 0;
}
//插入到头节点
void add_to_head(int x)
{
e[idx] = x;
ne[idx] = head;
head = idx;
idx;
}
//将x插入到k的后面
void add(int k, int x)
{
e[idx] = x;
ne[idx] = ne[k];
ne[k] = idx;
idx;
}
//删除下标为k后面的点
void remove(int k)
{
ne[k] = ne[ne[k]];
}
int main()
{
int m;
cin >> m;
init();
while (m–)
{
int k, x;
char option;
cin >> option;
if (option == ‘H’) {
cin >> x;
add_to_head(x);
}
else if (option == ‘D’) {
cin >> k;
if (!k)head = ne[head];
else remove(k - 1);
}
else {
cin >> k;
cin >> x;
add(k - 1, x);
}
}
for (int i = head;i != -1;i = ne[i]) {
cout << e[i] << " ";
}
cout << endl;
}