stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

const int maxn=5*1e5+12345;

int num[maxn];

set<int>s;

int main(){

	int n;

	scanf("%d",&n);

	for(int i=1;i<=n;i++)

		scanf("%d",&num[i]);

	int max_dep=1;

	for(int i=1;i<=n;i++){

		if(s.count(0)>=1){

			printf("No\n");

			continue;

		}

		int tmp_num=num[i];

		while(s.count(max_dep)){

			max_dep++;

		}

		if(max_dep-1<tmp_num){

			printf("Yes\n");

		}

		else if(max_dep-1>tmp_num){

			printf("No\n");

			continue;

		}

		else if(max_dep-1==tmp_num){

			if(s.size()!=max_dep-1){

				printf("No\n");

				continue;

			}

			else {

				printf("Yes\n");

			}

		}

		while(s.count(tmp_num))s.erase(tmp_num--);

		s.insert(tmp_num);

	}

}

// Faster C++ solution for the same problem (measured speedup: 5.258164614169839x):
//??：4s   空?：256MB

//?意:在一?无?深的二叉?上挂牌子,?定n个操作,表示在深度?di

//的子?点?挂牌子,如果符合到根的路径上只有1个牌子,那?就挂上去

//如果可以挂一定要挂,根?点深度?0

//算法:直接模?挂牌操作,??当前挂牌的情况,??当前允?挂牌上界 

//和最深的位置,如果某个的位置出?了??牌子,通?移?可以将他?

//移?至同一?子?,然后将其向上?点,更新最深点

//?于最浅的点,可以将牌子按照深度,从左挂到右?,可以??如果

//当前最浅深度的一个子?点挂牌,那就将挂牌上界往下移?

//因?只有?外一个子?点可以挂牌子了,如果?外一个子?点的一个

//儿子又有牌子,那就??将上界下移? 

//?个子?点都被挂牌,相当于自己被挂牌子 

//如果根?点被挂上牌子,就直接No,如果在最浅位置上方,那也不能挂

//当然如果上界和最深?不相等,上界?个深度明?是不能挂牌的 

//?于?目的数据,是不可能?下整个??数?的,所以?于明?可行的

//操作直接跳?就可以了(在根没有挂牌子的情况下)但是需要更新一下

//最深的深度 

#include<cstdio>

#include<algorithm>

using namespace std;

int d[1000005];

int main(){

	//freopen("a.in","r",stdin);

	//freopen("a.out","w",stdout);

	int n;

	scanf("%d",&n);

	int top=0,down=0;

	while(n--){

		int x;

		scanf("%d",&x);

		if(d[0]||x<top){printf("No\n");continue;}		

		if(x==top&&top!=down){printf("No\n");continue;}

		if(x>=1000000){printf("Yes\n");down=max(down,x);continue;}

		d[x]++;down=max(down,x);

		while(d[x]>=2){

			d[x-1]++;

			d[x]=0;

			if(x==down)down--;

			x--;

		}

		for(int i=top+1;d[i]==1;i++)

			top=i;

		printf("Yes\n");

	}

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

const int N = 500010;

int f[N], cur, s[N];



void pn() {puts("No");}

void py() {puts("Yes");}



void add(int x, int val) {

	if(!x) return;

	while(x < N) {

		s[x] += val;

		x += x & -x;

	}

}



int query(int x) {

	int ret = 0;

	while(x) {

		ret += s[x];

		x -= x & -x;

	}

	return ret;

}



void Add(int t) {

	while(t) {

		if(!f[t]) break;

		f[t]--;

		add(t, -1);

		t--;

	}

	f[t]++;

	add(t, 1);

}



int main() {

	int n, x;

	scanf("%d", &n);

	for (int i = 0; i < n; i++) {

		scanf("%d", &x);

		if(f[0]) pn();

		else {

			//printf("%di\n", i);

			if(x >= N) {

				cur = 1;

				py();

			} else {

				//printf("%d %d\n", x, query(x));

				if(query(x) == x) {

					if(query(N-1) > x || cur) pn();

					else {

						py();

						Add(x);

					}

				} else {

					py();

					Add(x);

				}

			}

		}

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.198240678242674x):
//??：4s   空?：256MB

//?意:在一?无?深的二叉?上挂牌子,?定n个操作,表示在深度?di

//的子?点?挂牌子,如果符合到根的路径上只有1个牌子,那?就挂上去

//如果可以挂一定要挂,根?点深度?0

//算法:直接模?挂牌操作,??当前挂牌的情况,??当前允?挂牌上界 

//和最深的位置,如果某个的位置出?了??牌子,通?移?可以将他?

//移?至同一?子?,然后将其向上?点,更新最深点

//?于最浅的点,可以将牌子按照深度,从左挂到右?,可以??如果

//当前最浅深度的一个子?点挂牌,那就将挂牌上界往下移?

//因?只有?外一个子?点可以挂牌子了,如果?外一个子?点的一个

//儿子又有牌子,那就??将上界下移? 

//?个子?点都被挂牌,相当于自己被挂牌子 

//如果根?点被挂上牌子,就直接No,如果在最浅位置上方,那也不能挂

//当然如果上界和最深?不相等,上界?个深度明?是不能挂牌的 

//?于?目的数据,是不可能?下整个??数?的,所以?于明?可行的

//操作直接跳?就可以了(在根没有挂牌子的情况下)但是需要更新一下

//最深的深度 

#include<cstdio>

#include<algorithm>

using namespace std;

int d[1000005];

int main(){

	//freopen("a.in","r",stdin);

	//freopen("a.out","w",stdout);

	int n;

	scanf("%d",&n);

	int top=0,down=0;

	while(n--){

		int x;

		scanf("%d",&x);

		if(d[0]||x<top){printf("No\n");continue;}		

		if(x==top&&top!=down){printf("No\n");continue;}

		if(x>=1000000){printf("Yes\n");down=max(down,x);continue;}

		d[x]++;down=max(down,x);

		while(d[x]>=2){

			d[x-1]++;

			d[x]=0;

			if(x==down)down--;

			x--;

		}

		for(int i=top+1;d[i]==1;i++)

			top=i;

		printf("Yes\n");

	}

	return 0;

}
// Slower C++ solution:
#include <set>

#include <vector>

#include <iostream>

#include <algorithm>

#pragma warning(disable : 4996)

using namespace std;

int n, x, b[500029], r = 1, sum;

int main() {

	scanf("%d", &n);

	for (int i = 0; i < n; i++) {

		scanf("%d", &x);

		if (b[0]) puts("No");

		else if (x >= 500020) puts("Yes");

		else {

			while (b[r]) r++;

			if (r <= x) {

				puts("Yes");

				int z = x; b[z]++, sum++;

				while (b[z] == 2) b[z] = 0, b[--z]++, sum--;

				r = min(r, z + 1);

			}

			else {

				if (sum == x) puts("Yes"), b[0] = 1;

				else puts("No");

			}

		}

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.201445991200658x):
#include <cstdio>

#include <algorithm>

using namespace std;

int n, x, b[500029], r = 1, sum;

int main() {

	scanf("%d", &n);

	for (int i = 0; i < n; i++) {

		scanf("%d", &x);

		if (b[0]) puts("No");

		else if (x >= 500020) puts("Yes");

		else {

			while (b[r]) r++;

			if (r <= x) {

				puts("Yes");

				int z = x; b[z]++, sum++;

				while (b[z] == 2) b[z] = 0, b[--z]++, sum--;

				r = min(r, z + 1);

			}

			else {

				if (sum == x) puts("Yes"), b[0] = 1;

				else puts("No");

			}

		}

	}

	return 0;

}
// Slower C++ solution:
#include <set>

#include <vector>

#include <iostream>

#include <algorithm>

#pragma warning(disable : 4996)

using namespace std;

int n, x, b[500029], r = 1, sum;

int main() {

	scanf("%d", &n);

	for (int i = 0; i < n; i++) {

		scanf("%d", &x);

		if (b[0]) puts("No");

		else if (x >= 500020) puts("Yes");

		else {

			while (b[r]) r++;

			if (r <= x) {

				puts("Yes");

				int z = x; b[z]++, sum++;

				while (b[z] == 2) b[z] = 0, b[--z]++, sum--;

				r = min(r, z + 1);

			}

			else {

				if (sum == x) puts("Yes"), b[0] = 1;

				else puts("No");

			}

		}

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.200932524760781x):
#include <cstdio>

#include <algorithm>

using namespace std;

int n, x, b[500029];

int main() {

	scanf("%d", &n);

	int r = 1, sum = 0;

	for (int i = 0; i < n; i++) {

		scanf("%d", &x);

		if (b[0]) puts("No");

		else if (x >= 500020) puts("Yes");

		else {

			while (b[r]) r++;

			if (r <= x) {

				puts("Yes");

				int z = x; b[z]++, sum++;

				while (b[z] == 2) b[z] = 0, b[--z]++, sum--;

				r = min(r, z + 1);

			}

			else {

				if (sum == x) puts("Yes"), b[0] = 1;

				else puts("No");

			}

		}

	}

	return 0;

}
// Slower C++ solution:
#include<cstdio>

#include<algorithm>

using namespace std;

typedef long long int ll;

static const int MAX_N = 2000;



int N;

ll A[MAX_N];

ll memo[MAX_N][2 * MAX_N];



ll memoize(int i, int j){

	if(memo[i][j] != -1) return memo[i][j];

	int i2 = (i == N - 1 ? 0 : i + 1);

	int j2 = (j == 0 ? N - 1 : j - 1);

	int itv = (i > j ? N + j - i : j - i);

	if((N - itv) % 2 == 1){

		if(i == j) return memo[i][j] = A[i];

		else return memo[i][j] = max(memoize(i2, j) + A[i], memoize(i, j2) + A[j]);

	}else{

		if(i == j) return memo[i][j] = 0LL;

		else if(A[i] > A[j]) return memo[i][j] = memoize(i2, j);

		else return memo[i][j] = memoize(i, j2);

	}

	return 0;

}



int main(){

	scanf("%d", &N);

	for(int i = 0; i < N; i++) scanf("%lld", &A[i]);

	fill(memo[0], memo[N], -1);

	for(int i = 0; i < N; i++){

		for(int j = 0; j < N; j++){

			memo[i][j] = memoize(i, j);

		}

	}

	ll res = 0LL;

	for(int i = 0; i < N; i++){

		for(int j = 0; j < N; j++){

			res = max(res, memo[i][j]);

		}

	}

	printf("%lld\n", res);

	return 0;

}




// Faster C++ solution for the same problem (measured speedup: 1.2928855774208752x):
#include<cstdio>

#include<algorithm>

using namespace std;

typedef long long int ll;

static const int MAX_N = 2000;

 

int N;

ll A[MAX_N];

ll memo[MAX_N][MAX_N];

 

ll memoize(int i, int j){

    if(memo[i][j] != -1) return memo[i][j];

    int i2 = (i == N - 1 ? 0 : i + 1);

    int j2 = (j == 0 ? N - 1 : j - 1);

    int itv = (i > j ? N + j - i : j - i);

    if((N - itv) % 2 == 1){

        if(i == j) return memo[i][j] = A[i];

        else return memo[i][j] = max(memoize(i2, j) + A[i], memoize(i, j2) + A[j]);

    }else{

        if(i == j) return memo[i][j] = 0LL;

        else if(A[i] > A[j]) return memo[i][j] = memoize(i2, j);

        else return memo[i][j] = memoize(i, j2);

    }

    return 0;

}

 

int main(){

    scanf("%d", &N);

    for(int i = 0; i < N; i++) scanf("%lld", &A[i]);

    fill(memo[0], memo[N], -1);

    for(int i = 0; i < N; i++){

        for(int j = 0; j < N; j++){

            memo[i][j] = memoize(i, j);

        }

    }

    ll res = 0LL;

    for(int i = 0; i < N; i++) res = max(res, memo[i][(i + N - 1) % N]);

    printf("%lld\n", res);

    return 0;

}
// Slower C++ solution:
#include<cstdio>

#include<cstdlib>

#include<iostream>

using namespace std;

struct node{

	int key;

	node *next,*prev;

	

};

char name[20];

node *nil;

node *list(int key)

{

	node *cur=nil->next;

	while(cur!=nil&&cur->key!=key)

	{

		cur=cur->next;

	}

	return cur;

}

void init()

{

	nil=(node*)malloc(sizeof(node));

	nil->next=nil;

	nil->prev=nil;

}

void printflist()

{

	node *cur=nil->next;

	int isf=0;

	while(1){

		if(cur==nil)break;

		if(isf++>0)printf(" ");

		printf("%d",cur->key);

		cur=cur->next;

	}

	printf("\n");

}

void deletenode(node *t)

{

	if(t==nil)return;

	t->prev->next=t->next;

	t->next->prev=t->prev;

	free(t); 

}

void deletefirst()

{

	deletenode(nil->next);

}

void deletelast()

{

	deletenode(nil->prev);

}

void deletekey(int key)

{

     deletenode(list(key));	

}

void insert(int key)

{

	node *x=(node*)malloc(sizeof(node));

	x->key=key;

	x->next=nil->next;

	nil->next->prev=x;

	nil->next=x;

	x->prev=nil;

}

int main()

{

	int n,key;

	

	cin>>n;

	init();

	for(int i=1;i<=n;i++)

	{

		cin>>name;

		if(name[0]=='i'){

			cin>>key;

			insert(key);

		}

		else

		{

			if(name[6]=='F')

			{

				deletefirst();

			}

			else if(name[6]=='L')

			{

				deletelast();

			}

			else

			{

				cin>>key;

				deletekey(key);

			}

		}

	}

     printflist();

     return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.140217745739863x):
//#define _CRT_SECURE_NO_WARNINGS

#include<cstdio>

#include<cstdlib>

#include<cstring>



struct Node {

	int key;

	Node* prev, * next;

};



Node* nil;



Node* listSearch(int key) {

	Node* cur = nil->next;//从头节点后面的元素开始访问

	while (cur != nil && cur->key != key) {

		cur = cur->next;

	}

	return cur;

}



void init() {

	nil = (Node*)malloc(sizeof(Node));

	nil->prev = nil;

	nil->next = nil;

}



void printList() {

	Node* cur = nil->next;

	int isf = 0;

	while (1) {

		if (cur == nil) break;

		if (isf++ > 0)printf(" ");

		printf("%d", cur->key);

		cur = cur->next;

	}

	printf("\n");

}



void deleteNode(Node* t) {

	if (t == nil)return;

	t->prev->next = t->next;

	t->next->prev = t->prev;

	free(t);

}



void deleteFirst() {

	deleteNode(nil->next);

}



void deleteLast() {

	deleteNode(nil->prev);

}



void deleteKey(int key) {

	//删除搜索到的结点

	deleteNode(listSearch(key));

}



void insert(int key) {

	Node* x = (Node*)malloc(sizeof(Node));

	x->key = key;

	//在头结点后添加元素

	x->next = nil->next;

	nil->next->prev = x;

	nil->next = x;

	x->prev = nil;

}



int main() {

	int key, n, i;

	int size = 0;

	char com[20];

	int np = 0, nd = 0;

	scanf("%d", &n);

	init();

	for (i = 0; i < n; i++) {

		scanf("%s%d", com, &key);//使用效率更高的输入函数

		if (com[0] == 'i') { insert(key); np++; size++; }

		else if (com[0] == 'd') {

			if (strlen(com) > 6) {

				if (com[6] == 'F')deleteFirst();

				else if (com[6] == 'L') deleteLast();

			}

			else {

				deleteKey(key);

				nd++;

			}

			size--;

		}

	}



	printList();



	return 0;

}
// Slower C++ solution:
#include<stdio.h>

#include<string.h>

#include<math.h>

#include<algorithm>

#include<iostream>

#include<list>

using namespace std;

int main()

{

    int n,i,len,m,j,q,T=0;

	char c[20];

	list<int> v;

	cin>>n;

	for(i=0;i<n;i++)

	{

		cin>>c;

		if(c[0]=='i') {cin>>m;v.push_front(m);}

		else if(c[6]=='L') v.pop_back();

		else if(c[6]=='F') v.pop_front();

		else

		{

			cin>>m;

			for(list<int>::iterator it=v.begin();it!=v.end();it++)

				if(*it==m)

				{

					v.erase(it);

					break;

				}

		}

	}

	 i=0;

	for(list<int>::iterator it=v.begin();it!=v.end();it++)

	{

		if(i++) cout<<' ';

		cout<<*it;

	}

	cout<<'\n';

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.157787003448741x):
//#define _CRT_SECURE_NO_WARNINGS

#include<cstdio>

#include<cstdlib>

#include<cstring>



struct Node {

	int key;

	Node* prev, * next;

};



Node* nil;



Node* listSearch(int key) {

	Node* cur = nil->next;//从头节点后面的元素开始访问

	while (cur != nil && cur->key != key) {

		cur = cur->next;

	}

	return cur;

}



void init() {

	nil = (Node*)malloc(sizeof(Node));

	nil->prev = nil;

	nil->next = nil;

}



void printList() {

	Node* cur = nil->next;

	int isf = 0;

	while (1) {

		if (cur == nil) break;

		if (isf++ > 0)printf(" ");

		printf("%d", cur->key);

		cur = cur->next;

	}

	printf("\n");

}



void deleteNode(Node* t) {

	if (t == nil)return;

	t->prev->next = t->next;

	t->next->prev = t->prev;

	free(t);

}



void deleteFirst() {

	deleteNode(nil->next);

}



void deleteLast() {

	deleteNode(nil->prev);

}



void deleteKey(int key) {

	//删除搜索到的结点

	deleteNode(listSearch(key));

}



void insert(int key) {

	Node* x = (Node*)malloc(sizeof(Node));

	x->key = key;

	//在头结点后添加元素

	x->next = nil->next;

	nil->next->prev = x;

	nil->next = x;

	x->prev = nil;

}



int main() {

	int key, n, i;

	int size = 0;

	char com[20];

	int np = 0, nd = 0;

	scanf("%d", &n);

	init();

	for (i = 0; i < n; i++) {

		scanf("%s%d", com, &key);//使用效率更高的输入函数

		if (com[0] == 'i') { insert(key); np++; size++; }

		else if (com[0] == 'd') {

			if (strlen(com) > 6) {

				if (com[6] == 'F')deleteFirst();

				else if (com[6] == 'L') deleteLast();

			}

			else {

				deleteKey(key);

				nd++;

			}

			size--;

		}

	}



	printList();



	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define _ ios_base::sync_with_stdio(0);cin.tie(0);

#define clr(a) memset(a, 0x00, sizeof(a))

#define Error(x) cout << #x << " = " << x << endl

#define iDEBUG freopen("in.txt", "r", stdin)

#define oDEBUG freopen("out.txt","w",stdout)

#define pb push_back

#define pp pop_back

#define x first

#define y second

#define all(x) x.begin(),x.end()

#define hi cout << "hi" << endl

typedef long long ll;



using namespace std;



int main()

{_

    //iDEBUG;

    list<int> l;

    list<int>::iterator iter;



    int n, x;

    cin >> n;

    for(int i=0; i<n; i++)

    {

        string str;

        cin >> str;

        if(str == "deleteFirst")

            l.pop_front();

        else if(str == "deleteLast")

            l.pop_back();

        else if(str == "insert")

        {

            cin >> x;

            l.push_front(x);

        }

        else

        {

            cin >> x;

            for(iter=l.begin(); iter!=l.end(); iter++)

                if(*iter == x)

                {

                    l.erase(iter);

                    break;

                }

        }

    }

    for(iter=l.begin(); iter!=l.end(); iter++)

    {

        if(iter != l.begin())

            cout << " ";

        cout << *iter;

    }

    cout << endl;



    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.276157358657933x):
//#define _CRT_SECURE_NO_WARNINGS

#include<cstdio>

#include<cstdlib>

#include<cstring>



struct Node {

	int key;

	Node* prev, * next;

};



Node* nil;



Node* listSearch(int key) {

	Node* cur = nil->next;//从头节点后面的元素开始访问

	while (cur != nil && cur->key != key) {

		cur = cur->next;

	}

	return cur;

}



void init() {

	nil = (Node*)malloc(sizeof(Node));

	nil->prev = nil;

	nil->next = nil;

}



void printList() {

	Node* cur = nil->next;

	int isf = 0;

	while (1) {

		if (cur == nil) break;

		if (isf++ > 0)printf(" ");

		printf("%d", cur->key);

		cur = cur->next;

	}

	printf("\n");

}



void deleteNode(Node* t) {

	if (t == nil)return;

	t->prev->next = t->next;

	t->next->prev = t->prev;

	free(t);

}



void deleteFirst() {

	deleteNode(nil->next);

}



void deleteLast() {

	deleteNode(nil->prev);

}



void deleteKey(int key) {

	//删除搜索到的结点

	deleteNode(listSearch(key));

}



void insert(int key) {

	Node* x = (Node*)malloc(sizeof(Node));

	x->key = key;

	//在头结点后添加元素

	x->next = nil->next;

	nil->next->prev = x;

	nil->next = x;

	x->prev = nil;

}



int main() {

	int key, n, i;

	int size = 0;

	char com[20];

	int np = 0, nd = 0;

	scanf("%d", &n);

	init();

	for (i = 0; i < n; i++) {

		scanf("%s%d", com, &key);//使用效率更高的输入函数

		if (com[0] == 'i') { insert(key); np++; size++; }

		else if (com[0] == 'd') {

			if (strlen(com) > 6) {

				if (com[6] == 'F')deleteFirst();

				else if (com[6] == 'L') deleteLast();

			}

			else {

				deleteKey(key);

				nd++;

			}

			size--;

		}

	}



	printList();



	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cstring>

#include<list>

using namespace std;



int main() {

    int n, key;

    char op[20];

    list<int> List;

    scanf("%d", &n);

    getchar();



    for (int i = 0; i < n; i++) {

        scanf("%s %d", op, &key);

        if (op[0] == 'i') {

            List.push_front(key);

        }

        else {

            if (strlen(op) > 6) {

                if (op[6] == 'F') {

                    List.pop_front();

                }

                else {

                    List.pop_back();

                }

            }

            else { 

                for (list<int>::iterator it = List.begin(); it != List.end(); it++) {

                    if (*it == key) {

                        List.erase(it);

                        break;

                    }

                }

            }

        }

    }

    int flag = 0;

    for (list<int>::iterator it = List.begin(); it != List.end(); it++) {

        if (flag != 0)

            printf(" ");

        flag++;

        printf("%d", (*it));

    }

    printf("\n");

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.133417630911974x):
//#define _CRT_SECURE_NO_WARNINGS

#include<cstdio>

#include<cstdlib>

#include<cstring>



struct Node {

	int key;

	Node* prev, * next;

};



Node* nil;



Node* listSearch(int key) {

	Node* cur = nil->next;//从头节点后面的元素开始访问

	while (cur != nil && cur->key != key) {

		cur = cur->next;

	}

	return cur;

}



void init() {

	nil = (Node*)malloc(sizeof(Node));

	nil->prev = nil;

	nil->next = nil;

}



void printList() {

	Node* cur = nil->next;

	int isf = 0;

	while (1) {

		if (cur == nil) break;

		if (isf++ > 0)printf(" ");

		printf("%d", cur->key);

		cur = cur->next;

	}

	printf("\n");

}



void deleteNode(Node* t) {

	if (t == nil)return;

	t->prev->next = t->next;

	t->next->prev = t->prev;

	free(t);

}



void deleteFirst() {

	deleteNode(nil->next);

}



void deleteLast() {

	deleteNode(nil->prev);

}



void deleteKey(int key) {

	//删除搜索到的结点

	deleteNode(listSearch(key));

}



void insert(int key) {

	Node* x = (Node*)malloc(sizeof(Node));

	x->key = key;

	//在头结点后添加元素

	x->next = nil->next;

	nil->next->prev = x;

	nil->next = x;

	x->prev = nil;

}



int main() {

	int key, n, i;

	int size = 0;

	char com[20];

	int np = 0, nd = 0;

	scanf("%d", &n);

	init();

	for (i = 0; i < n; i++) {

		scanf("%s%d", com, &key);//使用效率更高的输入函数

		if (com[0] == 'i') { insert(key); np++; size++; }

		else if (com[0] == 'd') {

			if (strlen(com) > 6) {

				if (com[6] == 'F')deleteFirst();

				else if (com[6] == 'L') deleteLast();

			}

			else {

				deleteKey(key);

				nd++;

			}

			size--;

		}

	}



	printList();



	return 0;

}
// Slower C++ solution:
#include <iostream>

#include <string>

#include <vector>

#include <algorithm>

using namespace std;

inline int xmod(int a, int b) {

    int ret = a % b;

    return (ret >= 0) ? ret : ret + b;

}

int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);



    int n;

    cin >> n;



    int len=1000050;

    vector<int> li(len);

    int fi=0, la=0;



    string op;

    int key;

    vector<int>::iterator pos;



    for (int i=0; i<n; ++i) {

        cin >> op;

        if (op[0] == 'i') {

            cin >> key;

            fi = xmod(fi-1, len);

            li[fi] = key;

        } else if (op.size() > 6 && op[6] == 'F') {

            while (li[fi] == -1) {

                fi = (fi+1) % len;

            }

            fi = (fi+1) % len;

        } else if (op.size() > 6 && op[6] == 'L') {

            while (li[xmod(la-1, len)] == -1) {

                la = xmod(la-1, len);

            }

            la = xmod(la-1, len);

        } else {

            cin >> key;

            for (int j=fi; j!=la; j=(j+1)%len) {

                if (li[j] == key) {

                    li[j] = -1;

                    break;

                }

            }

        }

    }



    bool nospace = true;

    for (int i=fi; i!=la; i=(i+1)%len) {

        if (li[i] == -1) {

            continue;

        }

        if (nospace) {

            cout << li[i];

            nospace = false;

        } else {

            cout << " " << li[i];

        }

    }

    cout << endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.997428757360349x):
#include <iostream>

#include <string>

#include <vector>

#include <algorithm>

using namespace std;

inline int xmod(int a, int b) {

    return (a >= 0) ? a%b : a%b + b;

}

int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);

    

    int n; cin >> n;



    int len=1000050;

    int* li = new int[len];

    int fi=0, la=0;



    string op;

    int key;

    for (int i=0; i<n; ++i) {

        cin >> op;

        if (op == "insert") {

            cin >> key;

            fi = xmod(fi-1, len);

            li[fi] = key;

        } else if (op == "deleteFirst") {

            while (li[fi] == -1) fi = (fi+1) % len;

            fi = (fi+1) % len;

        } else if (op == "deleteLast") {

            while (li[xmod(la-1, len)] == -1) la = xmod(la-1, len);

            la = xmod(la-1, len);

        } else {

            cin >> key;

            for (int j=fi; j!=la; j=(j+1)%len) {

                if (li[j] == key) {

                    li[j] = -1;

                    break;

                }

            }

        }

    }



    bool nospace = true;

    for (int i=fi; i!=la; i=(i+1)%len) {

        if (li[i] == -1) continue;

        if (nospace) {

            cout << li[i];

            nospace = false;

        } else {

            cout << " " << li[i];

        }

    }

    cout << endl;



    delete[] li;

    return 0;

}