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



using namespace std;



typedef pair<int,int> P;

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

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



int main(){

  int Tc,M,N;



  cin >> Tc;

  while(Tc--){

    vector<P> vec;

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

      vec.push_back(P(dx[i],dy[i]));

    }

    cin >> M >> N;

    vec.push_back(P(M,N));

    vec.push_back(P(-N,M));

    vec.push_back(P(-M,-N));

    vec.push_back(P(N,-M));

    int cnt = 0;



    for(int m = 0 ; m <= 100 ; m++){

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

        if(m == n && m == 0) continue;

        int X = m*m + n*n;

        if(!((m*M+n*N) % X == 0 && (m*N-n*M)%X == 0)) continue;

        int Y = (m*M+n*N)/X;

        int Z = (m*N-n*M)/X;

        if((M*M+N*N)/X == Y*Y+Z*Z){

          bool ok = true;

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

            if(vec[i].first == m && vec[i].second == n){

              ok = false;

              break;

            }

          }

          if(ok) cnt++;

        }

      }

    }

   

    if(cnt == 0) cout << "P" << endl;

    else cout << "C" << endl;

  }



  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 1.2929772274279x):
#include <bits/stdc++.h>



using namespace std;



typedef pair<int,int> P;

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

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



int main(){

  int Tc,M,N;



  cin >> Tc;

  while(Tc--){

    vector<P> vec;

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

      vec.push_back(P(dx[i],dy[i]));

    }

    cin >> M >> N;

    vec.push_back(P(M,N));

    vec.push_back(P(-N,M));

    vec.push_back(P(-M,-N));

    vec.push_back(P(N,-M));

    int cnt = 0;



    for(int m = 0 ; m <= 50 ; m++){

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

        if(m == n && m == 0) continue;

        int X = m*m + n*n;

        if(!((m*M+n*N) % X == 0 && (m*N-n*M)%X == 0)) continue;

        int Y = (m*M+n*N)/X;

        int Z = (m*N-n*M)/X;

        if((M*M+N*N)/X == Y*Y+Z*Z){

          bool ok = true;

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

            if(vec[i].first == m && vec[i].second == n){

              ok = false;

              break;

            }

          }

          if(ok) cnt++;

        }

      }

    }

   

    if(cnt == 0) cout << "P" << endl;

    else cout << "C" << endl;

  }



  return 0;

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

#include <fstream>

#include <vector>

#include <string>

#include <map>

#include <sstream>

#include <queue>

#include <cstdlib>

#include <algorithm>

#include <iterator>

#include <stack>

#include <list>

using namespace std;

#define INF 100000000

typedef long long int lli;

typedef pair<int,int> P;

int store[100001];

int point[10001];

long long int ans[10001];

int abs(int x){

	if(x>0) return x;

	else return x*-1;

}



int main(){

	lli d;

	int n,m;

	while(cin >> d&&d){

		cin >> n >> m;

		store[0]=0;

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

			cin >> store[i];

		}

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

			cin >> point[i];

		}

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

			ans[i]=INF;

		}

		sort(store,store+n);

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

			int up=n,down=0;

			int count=0;

			/*for(int j=0; j<n; ++j){

				cout << store[j] << "\n";

			}*/

			//cout << "\n";

			while(1){

				int mid=(up+down)/2.0;

				if(ans[i]>abs(point[i]-store[mid])) ans[i]=abs(point[i]-store[mid]);

				if(count==5000) {

					break;

				}

				if(store[mid]>point[i]){

					up=mid;

				} else {

					down=mid;

				}

				++count;

			}

			if(d-point[i]<ans[i]) ans[i]=d-point[i];

			//cout << ans[i] << "\n";

		}

		long long int Ans=0;

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

			Ans+=ans[i];

		}

		cout << Ans << "\n";

	}

}

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

#include <fstream>

#include <vector>

#include <string>

#include <map>

#include <sstream>

#include <queue>

#include <cstdlib>

#include <algorithm>

#include <iterator>

#include <stack>

#include <list>

using namespace std;

#define INF 100000000

typedef long long int lli;

typedef pair<int,int> P;

int store[100001];

int point[10001];

long long int ans[10001];

int abs(int x){

	if(x>0) return x;

	else return x*-1;

}



int main(){

	lli d;

	int n,m;

	while(cin >> d&&d){

		cin >> n >> m;

		store[0]=0;

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

			cin >> store[i];

		}

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

			cin >> point[i];

		}

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

			ans[i]=INF;

		}

		sort(store,store+n);

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

			int up=n,down=0;

			int count=0;

			/*for(int j=0; j<n; ++j){

				cout << store[j] << "\n";

			}*/

			//cout << "\n";

			while(1){

				int mid=(up+down)/2.0;

				if(ans[i]>abs(point[i]-store[mid])) ans[i]=abs(point[i]-store[mid]);

				if(count==1000) {

					break;

				}

				if(store[mid]>point[i]){

					up=mid;

				} else {

					down=mid;

				}

				++count;

			}

			if(d-point[i]<ans[i]) ans[i]=d-point[i];

			//cout << ans[i] << "\n";

		}

		long long int Ans=0;

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

			Ans+=ans[i];

		}

		cout << Ans << "\n";

	}

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

#include<algorithm>

#include<iostream>

#include<string>

#include<cstdio>

#include<cstdlib>

#include<cstring>

#include<cmath>

using namespace std;

int main(){

  int i,j;

  int d,m,n,p;

  int sm;

  vector<int> a;

  while(cin>>d&&d){

    cin>>m>>n;

    a.clear();

    a.push_back(0);

    for(i=0;i<m-1;i++){

      int c;

      cin>>c;

      a.push_back(c);

    }

    a.push_back(d);

    sort(a.begin(),a.end());

    sm=0;

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

      cin>>p;

      for(j=0;;j++){

	if(a[j]<=p&&p<a[j+1])

	  break;

      }

      sm+=min(p-a[j],a[j+1]-p);

    }

    cout<<sm<<endl;

  }

  return 0;

}

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

#include<cstdio>

using namespace std;

int main(){

  int i;

  int d;

  while(scanf("%d",&d),d){

    int m,n;

    scanf("%d%d",&m,&n);

    int a[100001];

    a[0]=0;

    a[m]=d;

    for(i=1;i<m;++i)

      scanf("%d",a+i);

    sort(a,a+m+1);

    int sm=0;

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

      int p,q;

      scanf("%d",&p);

      q=upper_bound(a,a+m+1,p)-a;

      sm+=min(p-a[q-1],a[q]-p);

    }

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

  }

  return 0;

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

#include<iostream>

#include<string>

#include<cstdlib>

#include<cstring>

#include<cmath>

using namespace std;

int main(){

  int i,j;

  int a[100001],d,m,n,p;

  int sm;

  while(cin>>d&&d){

    cin>>m>>n;

    a[0]=0;

    for(i=1;i<m;i++)

      cin>>a[i];

    a[i]=d;

    sort(a,a+m+1);

    sm=0;

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

      cin>>p;

      for(j=0;a[j]>p||p>=a[j+1];j++);

      sm+=min(p-a[j],a[j+1]-p);

    }

    cout<<sm<<endl;

  }

  return 0;

}

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

#include<cstdio>

using namespace std;

int main(){

  int i;

  int d;

  while(scanf("%d",&d),d){

    int m,n;

    scanf("%d%d",&m,&n);

    int a[100001];

    a[0]=0;

    a[m]=d;

    for(i=1;i<m;++i)

      scanf("%d",a+i);

    sort(a,a+m+1);

    int sm=0;

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

      int p,q;

      scanf("%d",&p);

      q=upper_bound(a,a+m+1,p)-a;

      sm+=min(p-a[q-1],a[q]-p);

    }

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

  }

  return 0;

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

#include<algorithm>

#include<vector>

#include<queue>

using namespace std;

typedef long long ll;



int main(){

	int d,n,m,x[100000],c[10000];

	while(scanf("%d",&d),d){

		scanf("%d%d",&n,&m);

		x[0]=0;

		for(int i=1;i<n;i++) scanf("%d",&x[i]);

		for(int i=0;i<m;i++) scanf("%d",&c[i]);

		int p[100001];

		for(int i=0;i<n;i++) p[i]=x[i];

		p[n]=d;

		sort(p,p+n+1);

		int res=0;

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

			int *lb=lower_bound(p,p+n+1,c[i]);

			if(c[i]!=0) res+=min(lb[0]-c[i],c[i]-lb[-1]);

		}

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

	}

}

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

#include<algorithm>

using namespace std;



int l, n, m, d[100002], k[10000];



int main() {

  while (scanf("%d", &l), l) {

    int ans = 0;

    scanf("%d%d", &n, &m);

    for (int i = 1; i < n; i++) scanf("%d", &d[i]);

    d[n] = l;

    sort(d, d+n+1);

    for (int i = 0; i < m; i++) scanf("%d", &k[i]);

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

      if (k[i] == 0) continue;

      int x = lower_bound(d, d+n+1, k[i]) - d;

      int len = min(d[x] - k[i], k[i] - d[x-1]);

      ans += len;

    }

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

  }

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

#include <algorithm>

#include <string>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>

#include <queue>

#include <iomanip>



using namespace std;

typedef long long ll;



int main() {

	int H, W, N;

	int sr, sc;

	cin >> H >> W >> N;

	cin >> sr >> sc;

	getchar();

	string s, t;

	getline(cin, s);

	getline(cin, t);

	int position = sc;

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

		if (s[i] == 'R') position++;

		if (position > W) { cout << "NO" << endl; return 0; }

		if (t[i] == 'L' && position > 1) position--;

	}

	position = sc;

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

		if (s[i] == 'L') position--;

		if (position < 1) { cout << "NO" << endl; return 0; }

		if (t[i] == 'R' && position <W) position++;

	}

	position = sr;

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

		if (s[i] == 'U') position--;

		if (position < 1) { cout << "NO" << endl; return 0; }

		if (t[i] == 'D' && position<H) position++;

	}

	position = sr;

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

		if (s[i] == 'D') position++;

		if (position > H) { cout << "NO" << endl; return 0; }

		if (t[i] == 'U'&& position > 1) position--;

	}

	cout << "YES" << endl;

	return 0;

}

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

#include<algorithm>

using namespace std;



char s1[200001],s2[200001];

int main(){

	int n,m,k;

	int x,y;

	scanf("%d%d%d",&n,&m,&k);

	scanf("%d%d%s%s",&x,&y,s1+1,s2+1);

	int l1=1,r1=n,l2=1,r2=m;

	for(int i=k;i;i--){

		if(s2[i]=='U')r1=min(n,r1+1);

		if(s2[i]=='D')l1=max(1,l1-1);

		if(s2[i]=='L')r2=min(m,r2+1);

		if(s2[i]=='R')l2=max(1,l2-1);

		if(s1[i]=='U')l1++;

		if(s1[i]=='D')r1--;

		if(s1[i]=='L')l2++;

		if(s1[i]=='R')r2--;

		//printf("%d %d %d %d\n",l1,r1,l2,r2);

		if(l1>r1||l2>r2){

			printf("NO\n");

			return 0;

		}

	}

	if(x>=l1&&x<=r1&&y>=l2&&y<=r2)

		printf("YES\n");

	else printf("NO\n");

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

#include <cstdlib>



using namespace std;



char s[200005], t[200005];

int x, y, n, l, c;



void incearcaSus();

void incearcaJos();

void incearcaDreapta();

void incearcaStanga();



int main()

{

    int i;



    cin >> l >> c >> n;

    cin >> x >> y;

    int cx=x, cy=y;

    cin >> s >> t;

    x = cx; y = cy;

    incearcaSus();

    x = cx; y = cy;

    incearcaJos();

    x = cx; y = cy;

    incearcaDreapta();

    x = cx; y = cy;

    incearcaStanga();

    cout << "YES\n";

    return 0;

}



void incearcaSus()

{

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

    {

        if (s[i] == 'U')

            x--;

        if (x == 0)

        {

            cout << "NO\n";

            exit(0);

        }

        if (t[i] == 'D' && x < l)

            x++;

    }

}

void incearcaJos()

{

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

    {

        if (s[i] == 'D')

            x++;

        if (x == l+1)

        {

            cout << "NO\n";

            exit(0);

        }

        if (t[i] == 'U' && x > 1)

            x--;

    }

}

void incearcaStanga()

{

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

    {

        if (s[i] == 'L')

            y--;

        if (y == 0)

        {

            cout << "NO\n";

            exit(0);

        }

        if (t[i] == 'R' && y < c)

            y++;

    }

}

void incearcaDreapta()

{

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

    {

        if (s[i] == 'R')

            y++;

        if (y == c+1)

        {

            cout << "NO\n";

            exit(0);

        }

        if (t[i] == 'L' && y > 1)

            y--;

    }

}

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

#include<algorithm>

using namespace std;



char s1[200001],s2[200001];

int main(){

	int n,m,k;

	int x,y;

	scanf("%d%d%d",&n,&m,&k);

	scanf("%d%d%s%s",&x,&y,s1+1,s2+1);

	int l1=1,r1=n,l2=1,r2=m;

	for(int i=k;i;i--){

		if(s2[i]=='U')r1=min(n,r1+1);

		if(s2[i]=='D')l1=max(1,l1-1);

		if(s2[i]=='L')r2=min(m,r2+1);

		if(s2[i]=='R')l2=max(1,l2-1);

		if(s1[i]=='U')l1++;

		if(s1[i]=='D')r1--;

		if(s1[i]=='L')l2++;

		if(s1[i]=='R')r2--;

		//printf("%d %d %d %d\n",l1,r1,l2,r2);

		if(l1>r1||l2>r2){

			printf("NO\n");

			return 0;

		}

	}

	if(x>=l1&&x<=r1&&y>=l2&&y<=r2)

		printf("YES\n");

	else printf("NO\n");

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



const int N=int(2e5)+10;

int H,W,n,sr,sc,suf[N];

char s[N],t[N];

bool check(char a,char b,int dis,int lim) {

	suf[n+1]=0;

	int sum=0;

	for (int i=n;i>=1;--i) {

		suf[i]=suf[i+1];

		if (s[i]==b) {

			suf[i]=std::min(suf[i],sum-1);

			--sum;

		}

		if (t[i]==a) {

			if (sum<0) ++sum;

		}

	}

	int pos=dis;

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

		if (s[i]==a) ++pos;

		if (pos>lim) return 0;

		if (t[i]==b) {

			if (pos-1+suf[i+1]>=1) --pos;

		}

	}

	return 1;

}

int main() {

	scanf("%d%d%d%d%d",&H,&W,&n,&sr,&sc);

	scanf("%s",s+1);

	scanf("%s",t+1);

	if (!check('D','U',sr,H)||!check('U','D',H-sr+1,H)||!check('R','L',sc,W)||!check('L','R',W+1-sc,W))

		puts("NO");

	else puts("YES");

}

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

#include<algorithm>

using namespace std;



char s1[200001],s2[200001];

int main(){

	int n,m,k;

	int x,y;

	scanf("%d%d%d",&n,&m,&k);

	scanf("%d%d%s%s",&x,&y,s1+1,s2+1);

	int l1=1,r1=n,l2=1,r2=m;

	for(int i=k;i;i--){

		if(s2[i]=='U')r1=min(n,r1+1);

		if(s2[i]=='D')l1=max(1,l1-1);

		if(s2[i]=='L')r2=min(m,r2+1);

		if(s2[i]=='R')l2=max(1,l2-1);

		if(s1[i]=='U')l1++;

		if(s1[i]=='D')r1--;

		if(s1[i]=='L')l2++;

		if(s1[i]=='R')r2--;

		//printf("%d %d %d %d\n",l1,r1,l2,r2);

		if(l1>r1||l2>r2){

			printf("NO\n");

			return 0;

		}

	}

	if(x>=l1&&x<=r1&&y>=l2&&y<=r2)

		printf("YES\n");

	else printf("NO\n");

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

#include <iostream>

#include <algorithm>

#include <cstring>

#include <queue>

#include <vector>

#include <cmath>

using namespace std;



const int maxn = 2e5+100;



int h,w,n,x,y;

char s1[maxn];

char s2[maxn];

int ans=0;

int L[maxn],R[maxn],U[maxn],D[maxn];

int main()

{

	cin>>h>>w>>n;

	cin>>x>>y;

	scanf("%s",s1+1);

	scanf("%s",s2+1);

	ans=0;

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

	{

		if(s[i]=='L') L[i]++;

		if(s[i]=='R') R[i]++;

		if(s[i]=='U') U[i]++;

		if(s[i]=='D') D[i]++;

		L[i]+=L[i-1];R[i]+=R[i-1];

		U[i]+=U[i-1];D[i]+=D[i-1];

	}*/

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

	{

		if(s1[i]=='L') ans++;

		if(ans>=y){

			cout<<"NO"<<endl;

			return 0;

		}

		if(s2[i]=='R')

		{

			if(ans<0&&abs(ans-1)==w-y+1) continue;

			ans--;

		} 

	}

	ans=0;

	//cout<<"111111"<<endl;

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

	{

		if(s1[i]=='U') ans++;

		if(ans>=x){

			cout<<"NO"<<endl;

			return 0;

		}

		if(s2[i]=='D')

		{

			if(ans<0&&abs(ans-1)==h-x+1) continue;

			ans--;

		} 

	}

	//cout<<"22222222222"<<endl;

	ans=0;

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

	{

		if(s1[i]=='R') ans++;

		if(ans>=w-y+1){

			cout<<"NO"<<endl;

			return 0;

		}

		if(s2[i]=='L')

		{

			if(ans<0&&abs(ans-1)==y) continue;

			ans--;

		} 

	}

	//cout<<"333333333333333"<<endl;

	ans=0;

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

	{

		if(s1[i]=='D') ans++;

		if(ans>=h-x+1){

			cout<<"NO"<<endl;

			return 0;

		}

		if(s2[i]=='U')

		{

			if(ans<0&&abs(ans-1)==x) continue;

			ans--;

		} 

	}

	//cout<<"4444444444444444444444444444444444444"<<endl;

	cout<<"YES"<<endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.278706062524954x):
#include <stdio.h>

using namespace std;

const int N = 2e5 + 5;

char s[N], t[N];



int main()

{

    int h, w, n, x, y;

    scanf("%d%d%d%d%d%s%s", &h, &w, &n, &x, &y, &s, &t);



    bool flag = true;

    int l = y, r = y, u = x, d = x;

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

    {

        switch (s[i])

        {

        case 'U': u--; break;

        case 'D': d++; break;

        case 'R': r++; break;

        case 'L': l--; break;

        }

        if (u == 0 || d == h + 1 || l == 0 || r == w + 1)

        {

            flag = false;

            break;

        }

        switch (t[i])

        {

        case 'U': if(d != 1) d--; break;

        case 'D': if(u != h) u++; break;

        case 'R': if(l != w) l++; break;

        case 'L': if(r != 1) r--; break;

        }

    }

    if (flag) printf("YES\n");

    else printf("NO\n");

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

#include <iostream>

#include <map>

#include <vector>

#include <tuple>

#include <algorithm>

using namespace std;



int a[200010];

int prv[200010],nxt[200010];

bool win[200010];



int main(void){

	int n,m,q;

	cin >> n >> m >> q;



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

		prv[i]=(i+n-1)%n,nxt[i]=(i+1)%n;win[i]=true;

	}

	int cur=0;

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

		cin >> a[i];

		if(a[i]&1){

			for(int j=0;j<a[i];++j) cur=prv[cur];

		}else{

			for(int j=0;j<a[i];++j) cur=nxt[cur];

		}

		win[cur]=false;

		nxt[prv[cur]]=nxt[cur];

		prv[nxt[cur]]=prv[cur];

		cur=nxt[cur];

	}



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

		int in;

		cin >> in;

		cout << win[in] << endl;

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.19245198872316x):
#include <stdio.h>

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

int a[200010],v[200010][2],l[200010],n,m,q,c;

int main(void){

	scanf("%d %d %d",&n,&m,&q);

	rep(i,n)rep(j,2) v[i][j]=(i+n+1-2*j)%n;

	rep(i,m){

		scanf("%d",a+i);

		rep(j,a[i]) c=v[c][a[i]&1];

		l[c]=1;

		rep(j,2) v[v[c][j^1]][j]=v[c][j];

		c=v[c][0];

	}

	rep(i,q) scanf("%d",&c), printf("%d\n",1-l[c]);

	return 0;

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

#include <iostream>

#include <map>

#include <vector>

#include <tuple>

#include <algorithm>

using namespace std;



int a[200010];

int prv[200010],nxt[200010];

bool win[200010];



int main(void){

	int n,m,q;

	cin >> n >> m >> q;



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

		prv[i]=(i+n-1)%n,nxt[i]=(i+1)%n;win[i]=true;

	}

	int cur=0;

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

		cin >> a[i];

		if(a[i]&1){

			for(int j=0;j<a[i];++j) cur=prv[cur];

		}else{

			for(int j=0;j<a[i];++j) cur=nxt[cur];

		}

		win[cur]=false;

		nxt[prv[cur]]=nxt[cur];

		prv[nxt[cur]]=prv[cur];

		cur=nxt[cur];

	}



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

		int in;

		cin >> in;

		cout << win[in] << endl;

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.193076103200991x):
#include<stdio.h>

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

int a[1<<18],v[1<<18][3],n,m,q,c;

main(){scanf("%d%d%d",&n,&m,&q);rep(i,n)rep(j,2)v[i][j]=(i+n+1-2*j)%n;rep(i,m){scanf("%d",a+i);rep(j,a[i])c=v[c][a[i]&1];v[c][2]=1;rep(j,2)v[v[c][j^1]][j]=v[c][j];c=v[c][0];}rep(i,q) scanf("%d",&c),printf("%d\n",1-v[c][2]);}
// Slower C++ solution:
#include <cstdio>

#include <iostream>

#include <map>

#include <vector>

#include <tuple>

#include <algorithm>

using namespace std;



int a[200010];

int prv[200010],nxt[200010];

bool win[200010];



int main(void){

	int n,m,q;

	cin >> n >> m >> q;



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

		prv[i]=(i+n-1)%n,nxt[i]=(i+1)%n;win[i]=true;

	}

	int cur=0;

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

		cin >> a[i];

		if(a[i]&1){

			for(int j=0;j<a[i];++j) cur=prv[cur];

		}else{

			for(int j=0;j<a[i];++j) cur=nxt[cur];

		}

		win[cur]=false;

		nxt[prv[cur]]=nxt[cur];

		prv[nxt[cur]]=prv[cur];

		cur=nxt[cur];

	}



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

		int in;

		cin >> in;

		cout << win[in] << endl;

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.194181830822913x):
#include <stdio.h>

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

int a[1<<18],v[1<<18][3],n,m,q,c,i,j;

main(){scanf("%d%d%d",&n,&m,&q);rep(i,n)rep(j,2)v[i][j]=(i+n+1-2*j)%n;rep(i,m){scanf("%d",a+i);rep(j,a[i])c=v[c][a[i]&1];v[c][2]=1;rep(j,2)v[v[c][j^1]][j]=v[c][j];c=v[c][0];}rep(i,q)scanf("%d",&c),printf("%d\n",1-v[c][2]);}
// Slower C++ solution:
#include <cstdio>

#include <cmath>

#include <cstring>

#include <utility>

#include <queue>

#include <vector>

#include <string>

#include <set>

#include <functional>

#include <algorithm>

#include <iostream>

using namespace std;

typedef long long LL;

typedef pair<int,int> P;

struct Node {

	int val;

	Node *prev;

	Node *next;

	Node(int v) {

		val=v;

		prev=next=NULL;

	}

};

Node *head=NULL,*tail=NULL;

void add(int val) {

	Node *New=new Node(val);

	if(head==NULL) {

		head=tail=New;

	}else {

		tail->next=New;

		New->prev=tail;

		tail=New;

	}

}

void del(Node *node) {

	if(node->prev!=NULL) {

		node->prev->next=node->next;

	}else {

		head=node->next;

	}

	if(node->next!=NULL) {

		node->next->prev=node->prev;

	}else {

		tail=node->prev;

	}

	delete node;

}

bool OK[200000];

int main() {

	int N,M,Q;

	scanf("%d %d %d",&N,&M,&Q);

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

		add(i);

	}

	Node *cur=head;

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

		int a;

		scanf("%d",&a);

		if(a&1) {

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

				cur=cur->prev;

				if(cur==NULL) cur=tail;

			}

			Node *tmp=cur;

			cur=cur->next;

			if(cur==NULL) cur=head;

			del(tmp);

		}else {

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

				cur=cur->next;

				if(cur==NULL) cur=head;

			}

			Node *tmp=cur;

			cur=cur->next;

			if(cur==NULL) cur=head;

			del(tmp);

		}

	}

	for(Node *cur=head;cur!=NULL;cur=cur->next) {

		OK[cur->val]=1;

	}

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

		int q;

		scanf("%d",&q);

		printf("%d\n",OK[q]);

	}

}

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

#include <string>

#include <utility>

#include <set>

#include <queue>

#include <algorithm>

using namespace std;

int nxt[200000], prv[200000];

bool OK[200000];

int main() {

	int N, M, Q;

	scanf("%d %d %d", &N, &M, &Q);

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

		nxt[i] = (i + 1) % N;

		prv[i] = (i - 1 + N) % N;

	}

	int cur = 0;

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

		int a;

		scanf("%d", &a);

		if (a & 1) {

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

				cur = prv[cur];

			}

		}

		else {

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

				cur = nxt[cur];

			}

		}

		nxt[prv[cur]] = nxt[cur];

		prv[nxt[cur]] = prv[cur];

		cur = nxt[cur];

	}

	OK[cur] = 1;

	int tmp = cur;

	for (cur = nxt[cur]; cur != tmp; cur = nxt[cur]) {

		OK[cur] = 1;

	}

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

		int q;

		scanf("%d", &q);

		printf("%d\n", OK[q]);

	}

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

using namespace std;

int N, M, Q, p, r, a, prv[200007], nxt[200007];

int main() {

	cin >> N >> M >> Q;

	for (int i = 0; i < N; i++) prv[i] = (i + N - 1) % N, nxt[i] = (i + 1) % N;

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

		cin >> a;

		for (int j = 0; j < a; j++) p = a % 2 ? prv[p] : nxt[p];

		nxt[prv[p]] = nxt[p], prv[nxt[p]] = prv[p];

		r = nxt[p], prv[p] = nxt[p] = -1, p = r;

	}

	for (int i = 0; i < Q; i++) cin >> a, cout << (prv[a] != -1 ? 1 : 0) << endl;

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.26904279588626x):
#include <stdio.h>

int N, M, Q, p, r, a, prv[200007], nxt[200007];

int main() {

	scanf("%d%d%d", &N, &M, &Q);

	for (int i = 0; i < N; i++) prv[i] = (i + N - 1) % N, nxt[i] = (i + 1) % N;

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

		scanf("%d", &a);

		for (int j = 0; j < a; j++) p = a % 2 ? prv[p] : nxt[p];

		nxt[prv[p]] = nxt[p], prv[nxt[p]] = prv[p];

		r = nxt[p], prv[p] = nxt[p] = -1, p = r;

	}

	for (int i = 0; i < Q; i++) scanf("%d", &a), puts(prv[a] != -1 ? "1" : "0");

	return 0;

}