stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



#define FOR(i,a,b) for (int i = (a); i < (b); i++)

#define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)

#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)

#define FILL(a,value) memset(a, value, sizeof(a))



#define SZ(a) (int)a.size()

#define ALL(a) a.begin(), a.end()

#define PB push_back

#define MP make_pair



typedef long long LL;

typedef vector<int> VI;

typedef pair<int, int> PII;



const double PI = acos(-1.0);

const int INF = 1000 * 1000 * 1000 + 7;

const LL LINF = INF * (LL) INF;



const int MAX = 1001000;



char S[MAX];

char T[MAX];



int A[MAX];



int main()

{

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

	//ios::sync_with_stdio(false); cin.tie(0);



	int n;

	scanf("%d", &n);

	scanf("%s", S);

	scanf("%s", T);



	if ((string)(S) ==(string(T)))

	{

		cout<<0<<endl;

		return 0;

	}



	FILL(A, -1);

	int ind = n-1;

	RFOR(i, n, 0)

	{

		while (ind > i) ind--;

		while(ind >= 0 && S[ind] != T[i])

		{

			ind--;

		}



		if (ind == -1)

		{

			cout<<-1<<endl;

			return 0;

		}



		if (A[ind] == -1) A[ind] = i;

	}



	vector<PII> a;

	FOR (i, 0, n)

	{

		if (A[i] != -1) a.PB(MP(i, A[i]));

	}



	/*FOR (i, 0, SZ(a))

	{

		cout<<a[i].first<<' '<<a[i].second<<endl;

	}

	cout<<endl;*/



	int res = 0;



	ind = 0;

	int ind2 = 0;

	FOR (i, 0, SZ(a))

	{

		while(true)

		{

			if (ind2 == SZ(a)) break;

			if (a[ind2].first <= a[i].second)

			{

				ind2++;

				continue;

			}

			break;

		}

		while(true)

		{

			if (ind == SZ(a)) break;

			if (a[ind].first - (ind - i - 1) <= a[i].second)

			{

				ind++;

				continue;

			}

			break;

		}



		res = max(res, ind - i);

	}



	cout<<res<<endl;



}




// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

#define maxn 1000005

using namespace std;

int n,ans;

char s[maxn],t[maxn];

queue<int>q;

int main()

{

	scanf("%d%s%s",&n,s,t);

	for(int i=0;i<n;i++) if(s[i]!=t[i]) {ans=-1;break;}

	if(ans!=-1) return puts("0"),0;

	for(int up=n-1,down=n-1;down>=0;down--){

		if(t[down]==t[down-1]) continue;

		while(up>down||(up>=0&&s[up]!=t[down])) up--;

		if(up<0) {ans=-1;break;}

		while(!q.empty()&&q.front()-q.size()>=down) q.pop();

		if(up!=down) q.push(up);

		ans=max(ans,(int)q.size()+1);

	}

	printf("%d\n",ans);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

using namespace std;

constexpr int MOD = 1e9 + 7;



long L, R;

long dp[66][2][2][2];



// y % x = y ^ x and x <= y

// y % x is less than x. 

// when (y>>1) > x, MSB(y) == MSB(y^x) > x. so this doesnt fulfill the condition.

// then (x<<1) >= y >= x. In this case, y % x == y - x.

//

// On the other hand, xor is addition without carry-up.

// Digit that will carry when y + x and not when y ^ x, can be found by y & x.

// finally y ^ x is y + x - (y & x)<<1

// Requirement : y % x = y ^ x (y>=x) => y - x = y + x - (y & x)<<1 => x == y & x

//



int main() {

	cin >> L >> R;



	dp[0][0][0][0] = 1;

	

	// l = 1 : x is already more than L

	// r = 1 : y is already less than R

	// j = 1 : MSB of x and y is matched

	//

	// (x, y) = (1, 1), (0, 1), (0, 0) is required on each digit

	bool x[3] = {1, 0, 0}, y[3] = {1, 1, 0};



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

		bool lb = L>>(59-i)&1, rb = R>>(59-i)&1;



		for(int l = 0; l < 2; ++l) {

			for(int r = 0; r < 2; ++r) {

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



					// loop for updating

					for(int k = 0; k < 3; ++k) {

						if(!l && !x[k] && lb) continue;

						if(!r && y[k] && !rb) continue;

						if(!j && x[k] ^ y[k]) continue;

						

						int nl = (x[k] ^ lb   ? 1 : l);

						int nr = (y[k] ^ rb   ? 1 : r);

						int nj = (x[k] & y[k] ? 1 : j);



						(dp[i+1][nl][nr][nj] += dp[i][l][r][j]) %= MOD;

					}



				}

			}

		}

	}



	long ans = 0;

	for(int l=0;l<2;++l) for(int r=0;r<2;++r) ans = (ans + dp[60][l][r][1]) % MOD;



	cout << ans << '\n';

    return 0;

}


// Optimized solution to the same problem (faster):
#include <cstdio>

long L, R, MOD=1e9+7;

long dp[66][2][2][2];



int main() {

	scanf("%ld%ld", &L, &R);



	dp[0][0][0][0] = 1;

	bool x[3] = {1, 0, 0}, y[3] = {1, 1, 0};



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

		bool lb = L>>(59-i)&1, rb = R>>(59-i)&1;



		for(int l = 0; l < 2; ++l)

			for(int r = 0; r < 2; ++r)

				for(int j = 0; j < 2; ++j)



					for(int k = 0; k < 3; ++k) {

						if(!l && !x[k] && lb) continue;

						if(!r && y[k] && !rb) continue;

						if(!j && x[k] ^ y[k]) continue;

						

						int nl = (x[k] ^ lb   ? 1 : l);

						int nr = (y[k] ^ rb   ? 1 : r);

						int nj = (x[k] & y[k] ? 1 : j);



						(dp[i+1][nl][nr][nj] += dp[i][l][r][j]) %= MOD;

					}



	}

	long ans = dp[60][0][0][1] + dp[60][0][1][1] + dp[60][1][0][1] + dp[60][1][1][1];

	printf("%ld\n", ans % MOD);

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define N 1000021

using namespace std;

int w,h;

int par[N],Rank[N];

char mp[1001][1001];



void init(){

  for(int i=0;i<N;i++) par[i]=i,Rank[i]=0;

}



int find(int x){

  if(par[x]==x)return x;

  return par[x]=find(par[x]);

}



void unite(int x,int y){

  x=find(x),y=find(y);

  if(x==y)return;

  if(Rank[x]<Rank[y])par[x]=y;

  else par[y]=x,Rank[x]+=(Rank[x]==Rank[y]);

}



bool same(int x,int y){return find(x)==find(y);}

int Pos(int x,int y){return w*y+x;}



int dx[]={0,0,-1,1};

int dy[]={1,-1,0,0};

void umeru(){

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

    for(int j=0;j<w;j++)

      for(int k=0;k<4;k++){

	int ni=i+dy[k],nj=j+dx[k];

	if(mp[i][j]=='#')continue;

	if(ni<0||nj<0||ni>=h||nj>=w||mp[ni][nj]=='#')continue;

	unite(Pos(j,i),Pos(nj,ni));

      }

}



void umeru2(int x,int y){

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

    int ny=y+dy[i],nx=x+dx[i];

    if(ny<0||nx<0||ny>=h||nx>=w||mp[ny][nx]=='#')continue;

    unite(Pos(x,y),Pos(nx,ny));

  }

}



int main(){

  init();

  cin>>w>>h;

  int t;

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

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

      cin>>mp[i][j];

      if(mp[i][j]=='t')t=Pos(j,i);

    }

  umeru();

 

  int n,ans=-1;

  if(same(0,t)) ans=0;

  cin>>n;

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

    cin>>a>>b;

    umeru2(a,b);

    mp[b][a]='.';

    if(same(0,t)&&ans==-1)ans=i;

  }

  cout <<ans<<endl;

  return 0;

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

#define lp(i,n) for(int i=0;i<n;i++)

#define lps(i,j,n) for(int i=j;i<n;i++)

#define fordebug int hoge;cin>>hoge;

#define DEKAI 1000000007;

#define INF (1<<28)

#define int long long

#define double long double

#define floot10 cout<<fixed<<setprecision(10)

bool dp[1100][1100];



signed main(){

  int w,h;

  cin>>w>>h;

  char a[1100][1100];

  lp(i,1100)lp(j,1100){

    dp[i][j]=false;

    a[i][j]='#';

  }

  int gx,gy;

  lp(i,h){

    lp(j,w){

      cin>>a[i+1][j+1];

      if(a[i+1][j+1]=='t'){

	gx=i+1;

	gy=j+1;

      }

    }

  }

  queue<pair<int,int>> q;

  q.push({1,1});

  dp[1][1]=true;

  int ax[4]={0,0,-1,1};

  int ay[4]={-1,1,0,0};

  int n;

  cin>>n;

  int hox[1010],hoy[1010];

  lp(i,n){

    cin>>hox[i]>>hoy[i];

  }

  lp(z,n+1){

    while(!q.empty()){

      int x,y;

      x=q.front().first;

      y=q.front().second;

      //cout<<x<<y<<endl;

      q.pop();

      lp(i,4){

	int nex=x+ax[i];

	int ney=y+ay[i];

	if(nex==gx&&ney==gy){

	  cout<<z<<endl;

	  return 0;

	}

	if(dp[nex][ney]==false){

	  dp[nex][ney]=true;

	  if(a[nex][ney]=='.'){

	    q.push({nex,ney});

	  }

	}

      }

    }

    if(z==n) break;/*

    lp(i,10){

      lp(j,10){

	if(dp[i+1][j+1]==false){

	  cout<<0;

	}

	else cout<<1;

      }

      cout<<endl;

    }

    lp(i,10){

      lp(j,10){

	cout<<a[i+1][j+1]

      }

      cout<<endl;

      }*/

    int bx,by;

    bx=hoy[z];

    by=hox[z];

    bx++;

    by++;

    if(a[bx][by]=='#'){

      a[bx][by]='.';

      if(dp[bx][by]==true){

	q.push({bx,by});

      }

    }

  }

  cout<<-1<<endl;

  return 0;

}






// Fastest known solution for this problem:
// Original C++ solution (slower):
#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);

	}

}

// Optimized solution to the same problem (faster):
//??：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;

} 

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
//??：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;

} 

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
#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;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}




// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
//#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}

// Optimized solution to the same problem (faster):
//#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
//#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;

}


// Fastest known solution for this problem: