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

using namespace std;



#define mp make_pair

#define pb push_back



typedef pair<int, int> ii;

typedef long long ll;

typedef pair<ll, ll> l4;



const int maxn = 2e5+1;

int a[maxn], n;

inline void end()

{

  puts("-1");

  exit(0);

}

int main()

{

  scanf("%d", &n);

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

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

  if (a[1] != 0)

    end();

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

    if (a[i] < a[i+1]-1)

      end();

  deque<int> dq;

  ll base = 0;

  ll ans = 0;

  for (int i = n; i >= 1; --i, --base)

    {

      while (!dq.empty() && dq.front()+base <= 0)

        dq.pop_front();

      if (a[i] == 0)

        continue;

      if (dq.empty() || dq.back()+base != a[i])

        dq.push_back(a[i]-base);

      ans += dq.size();

    }

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

}


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



const int maxn=200000;



int read()

{

  int x=0,f=1;

  char ch=getchar();

  while((ch<'0')||(ch>'9'))

    {

      if(ch=='-')

        {

          f=-f;

        }

      ch=getchar();

    }

  while((ch>='0')&&(ch<='9'))

    {

      x=x*10+ch-'0';

      ch=getchar();

    }

  return x*f;

}



int n,a[maxn+10];

long long ans;



int main()

{

  n=read();

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

    {

      a[i]=read();

      if(a[i]>=i)

        {

          puts("-1");

          return 0;

        }

    }

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

    {

      if(a[i]>a[i-1]+1)

        {

          puts("-1");

          return 0;

        }

      if(a[i]==a[i-1]+1)

        {

          ++ans;

        }

      else

        {

          ans+=a[i];

        }

    }

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

  return 0;

}

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

#define fi first

#define se second

#define LL long long



using namespace std;

const int maxn = 2e5 + 5;

typedef pair<int, int> P;



int a[maxn];



int main() {

#ifdef TT

    freopen("xxx.in", "r", stdin);

#endif // TT

    int n, i, x;

    LL ans = 0;

    scanf("%d", &n);

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

    for(i = n - 1, x = 0;i >= 0; i--) {

        if(a[i] > i || a[i] < x) return puts("-1"), 0;

        if(a[i] > x) {

            ans += a[i];

            x = a[i];

        }

        x = max(x - 1, 0);

    }

    cout << ans << endl;

    return 0;

}


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



const int maxn=200000;



int read()

{

  int x=0,f=1;

  char ch=getchar();

  while((ch<'0')||(ch>'9'))

    {

      if(ch=='-')

        {

          f=-f;

        }

      ch=getchar();

    }

  while((ch>='0')&&(ch<='9'))

    {

      x=x*10+ch-'0';

      ch=getchar();

    }

  return x*f;

}



int n,a[maxn+10];

long long ans;



int main()

{

  n=read();

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

    {

      a[i]=read();

      if(a[i]>=i)

        {

          puts("-1");

          return 0;

        }

    }

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

    {

      if(a[i]>a[i-1]+1)

        {

          puts("-1");

          return 0;

        }

      if(a[i]==a[i-1]+1)

        {

          ++ans;

        }

      else

        {

          ans+=a[i];

        }

    }

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

  return 0;

}

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

#define ll long long

using namespace std;

const int N = 2e5 + 5;

int a[N];

void kill() {

	cout << "-1\n";

	exit(0);

}

int main() {

	ios_base::sync_with_stdio(0);

	cin.tie(0);

	int n;

	cin >> n;

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

		cin >> a[i];

	a[0] = -1;

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

		if (a[i] - a[i - 1] > 1) kill();

	ll ans = 0;

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

		if (!a[i]) continue;

		ans++;

		if (a[i - 1] + 1 != a[i]) ans += a[i] - 1;

	}

	cout << ans << endl;

	return 0;

}




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



const int maxn=200000;



int read()

{

  int x=0,f=1;

  char ch=getchar();

  while((ch<'0')||(ch>'9'))

    {

      if(ch=='-')

        {

          f=-f;

        }

      ch=getchar();

    }

  while((ch>='0')&&(ch<='9'))

    {

      x=x*10+ch-'0';

      ch=getchar();

    }

  return x*f;

}



int n,a[maxn+10];

long long ans;



int main()

{

  n=read();

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

    {

      a[i]=read();

      if(a[i]>=i)

        {

          puts("-1");

          return 0;

        }

    }

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

    {

      if(a[i]>a[i-1]+1)

        {

          puts("-1");

          return 0;

        }

      if(a[i]==a[i-1]+1)

        {

          ++ans;

        }

      else

        {

          ans+=a[i];

        }

    }

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

  return 0;

}

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

#include <string.h>



using namespace std;



int N[210000];

long long ans,n;



bool mtime()

{

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

    {

        if(N[i]-N[i-1]>1||N[i]>i)

            return true;

    }

    return false;

}



int main()

{

    cin>>n;

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

    {

        cin>>N[i];

    }

    if(N[0]!=0||mtime())

    {

        cout<<-1<<endl;

        return 0;

    }

    ans=0;

    ans+=N[n-1];

    for(int i=n-2; i>0; i--)

    {

        if(N[i]-N[i+1]>-1)

            ans+=N[i];

    }

    cout<<ans<<endl;

    return 0;

}

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



const int maxn=200000;



int read()

{

  int x=0,f=1;

  char ch=getchar();

  while((ch<'0')||(ch>'9'))

    {

      if(ch=='-')

        {

          f=-f;

        }

      ch=getchar();

    }

  while((ch>='0')&&(ch<='9'))

    {

      x=x*10+ch-'0';

      ch=getchar();

    }

  return x*f;

}



int n,a[maxn+10];

long long ans;



int main()

{

  n=read();

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

    {

      a[i]=read();

      if(a[i]>=i)

        {

          puts("-1");

          return 0;

        }

    }

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

    {

      if(a[i]>a[i-1]+1)

        {

          puts("-1");

          return 0;

        }

      if(a[i]==a[i-1]+1)

        {

          ++ans;

        }

      else

        {

          ans+=a[i];

        }

    }

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

  return 0;

}

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

#include<sstream>

#include<algorithm>

#include<set>

#include<map>

#include<queue>

#include<complex>

#include<cstdio>

#include<cstdlib>

#include<cstring>

#include<cassert>

using namespace std;



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

#define each(i,c) for(__typeof(c.begin()) i=c.begin();i!=c.end();i++)

#define pb push_back

#define mp make_pair

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

#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl



typedef long long ll;

typedef vector<int> vi;

typedef pair<int,int> pi;

const int inf=(int)1e9;

const double EPS=1e-9, INF=1e12;



const int mod = (int)1e8 + 7;

int h, w, pw[11];

char in[12][12];

int dp[2][11][3][60000];



int main(){

	pw[0] = 1;

	rep(i, 10) pw[i + 1] = pw[i] * 3;

	

	cin >> h >> w;

	rep(i, h) cin >> in[i];

	

	int cur = 0, next = 1;

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

	

	rep(i, h){

		memset(dp[next], 0, sizeof(dp[next]));

		rep(j, w){

			rep(l, 3) rep(u, pw[w]) if(dp[cur][j][l][u]){

				

				int tu = u / pw[j] % 3;

				

				if(in[i][j] == '.'){

					if(tu && l) continue;

					(dp[cur][j + 1][l][u] += dp[cur][j][l][u]) %= mod;

					continue;

				}

				int rest = in[i][j] - '0' - tu - l;

				rep(nl, 3){

					int nu = rest - nl;

					if(nu < 0 || nu > 2) continue;

					(dp[cur][j + 1][nl][u + pw[j] * (nu - tu)] += dp[cur][j][l][u]) %= mod;

				}

			}

		}

		rep(u, pw[w]) dp[next][0][0][u] = dp[cur][w][0][u];

		swap(cur, next);

	}

	cout << dp[cur][0][0][0] << endl;

	

	return 0;

}

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

#include<sstream>

#include<algorithm>

#include<set>

#include<map>

#include<queue>

#include<complex>

#include<cstdio>

#include<cstdlib>

#include<cstring>

#include<cassert>

using namespace std;



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

#define each(i,c) for(__typeof(c.begin()) i=c.begin();i!=c.end();i++)

#define pb push_back

#define mp make_pair

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

#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl



typedef long long ll;

typedef vector<int> vi;

typedef pair<int,int> pi;

const int inf=(int)1e9;

const double EPS=1e-9, INF=1e12;



const int mod = (int)1e8 + 7;

int h, w, pw[11];

char in[12][12];

int dp[2][3][60000];



int main(){

	pw[0] = 1;

	rep(i, 10) pw[i + 1] = pw[i] * 3;

	

	cin >> h >> w;

	rep(i, h) cin >> in[i];

	

	int cur = 0, next = 1;

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

	

	rep(i, h) rep(j, w){

		memset(dp[next], 0, sizeof(dp[next]));

		rep(l, 3) rep(u, pw[w]) if(dp[cur][l][u]){

			

			int tu = u / pw[j] % 3;

			

			if(in[i][j] == '.'){

				if(tu && l) continue;

				if(l == 0 || j < w - 1) (dp[next][l][u] += dp[cur][l][u]) %= mod;

				continue;

			}

			int rest = in[i][j] - '0' - tu - l;

			rep(nl, 3){

				int nu = rest - nl;

				if(nu < 0 || nu > 2) continue;

				if(nl == 0 || j < w - 1)

					(dp[next][nl][u + pw[j] * (nu - tu)] += dp[cur][l][u]) %= mod;

			}

		}

		swap(cur, next);

	}

	cout << dp[cur][0][0] << endl;

	

	return 0;

}

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

#include<cstdio>

#include<cstring>

#include<string>

#include<algorithm>

#include<queue>

#include<stack>

#include<vector>

#include<set>

#include<map>

using namespace std;

typedef long long ll;

int main()

{

    int s[5][5];

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

    {

        for(int j=1; j<=3; j++)

        {

            cin>>s[i][j];

        }

    }

    int n;

    int b[5][5]= {0};

    cin>>n;

    while(n--)

    {

        int x;

        cin>>x;

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

        {

            int ff=0;

            for(int j=1; j<=3; j++)

            {

                if(s[i][j]==x&&b[i][j]==0)

                {

                    b[i][j]=1;

                    ff=1;

                    break;

                }

            }

            if(ff==1)

                break;

        }

    }

    int flag=0;

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

    {

        if(b[i][1]==1&&b[i][2]==1&&b[i][3]==1)

        {flag=1;break;}

        if(b[1][i]==1&&b[2][i]==1&&b[3][i]==1)

        {flag=1;break;}

    }

    if(b[1][1]==1&&b[2][2]==1&&b[3][3]==1)

        flag=1;

    if(b[1][3]==1&&b[2][2]==1&&b[3][1]==1)

        flag=1;

    if(flag==1)

        cout<<"Yes"<<endl;

    else cout<<"No"<<endl;

    return 0;

}


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

int main(){

	int na;

	int a[10];

	int angka[3][3];

	int tanda[3][3];

	

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

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

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

		}

	}

	scanf("%d", &na);

	for(int c=0;c<na;c++){

		scanf("%d", &a[c]);

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

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

            if( a[c] == angka[l][k] ){

                tanda[l][k] = 1;

                }

            }

        }

    }



    if( (tanda[1][1] == 1 && tanda[2][2] == 1 && tanda[0][0] == 1  )

    || (tanda[2][0] == 1 && tanda[1][1] == 1 && tanda[0][2] == 1  )

    || (tanda[0][0] == 1 && tanda[0][1] == 1 && tanda[0][2] == 1  )

    || (tanda[1][0] == 1 && tanda[1][1] == 1 && tanda[1][2] == 1  )

    || (tanda[2][0] == 1 && tanda[2][1] == 1 && tanda[2][2] == 1  )

    || (tanda[0][0] == 1 && tanda[1][0] == 1 && tanda[2][0] == 1  )

    || (tanda[0][1] == 1 && tanda[1][1] == 1 && tanda[2][1] == 1  )

    || (tanda[0][2] == 1 && tanda[1][2] == 1 && tanda[2][2] == 1  )

    ) {

        printf("Yes\n");

    } else {

        printf("No\n");

    }

	return 0;

}

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

#include<algorithm>

using namespace std;

int a[5][5];

int b[15];

int ans=0,t=0,teil=0,head=0;

int main()

{

	int n;

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

	{

		for(int j=1;j<=3;j++)

		{

			cin>>a[i][j];

		}

	}

	cin>>n;

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

	{

		cin>>b[i];

	}

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

	{

		ans=0;

		t=0;

		for(int j=1;j<=3;j++)

		{

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

			{

				if(a[i][j]==b[k])

				{

					ans++;

				}

				if(a[j][i]==b[k])

				{

					t++;

				}

			}

		}

		if(ans==3||t==3) break;

	}

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

	{

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

		{

			if(a[i][i]==b[j])

			{

				teil++;

			}

			if(a[4-i][i]==b[j])

			{

				head++;

			}

		}

	}

	if(teil==3||head==3||ans==3||t==3) cout<<"Yes"<<endl;

	else cout<<"No"<<endl;

	return 0;

}


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

int main(){

	int na;

	int a[10];

	int angka[3][3];

	int tanda[3][3];

	

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

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

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

		}

	}

	scanf("%d", &na);

	for(int c=0;c<na;c++){

		scanf("%d", &a[c]);

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

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

            if( a[c] == angka[l][k] ){

                tanda[l][k] = 1;

                }

            }

        }

    }



    if( (tanda[1][1] == 1 && tanda[2][2] == 1 && tanda[0][0] == 1  )

    || (tanda[2][0] == 1 && tanda[1][1] == 1 && tanda[0][2] == 1  )

    || (tanda[0][0] == 1 && tanda[0][1] == 1 && tanda[0][2] == 1  )

    || (tanda[1][0] == 1 && tanda[1][1] == 1 && tanda[1][2] == 1  )

    || (tanda[2][0] == 1 && tanda[2][1] == 1 && tanda[2][2] == 1  )

    || (tanda[0][0] == 1 && tanda[1][0] == 1 && tanda[2][0] == 1  )

    || (tanda[0][1] == 1 && tanda[1][1] == 1 && tanda[2][1] == 1  )

    || (tanda[0][2] == 1 && tanda[1][2] == 1 && tanda[2][2] == 1  )

    ) {

        printf("Yes\n");

    } else {

        printf("No\n");

    }

	return 0;

}

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

using namespace std;

typedef long long ll;

int main(){

    int arr[3][3];

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

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

            cin>>arr[i][j];

        }

    }

    int t,stop=0,win=0;

    cin>>t;

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

        int b;

        cin>>b;

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

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

            if (arr[i][j]==b)

                arr[i][j]=-1;

            }

        }

    }

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

        if (arr[i][0]==arr[i][1] and arr[i][1]==arr[i][2] and arr[i][2]==-1)

            win =1;

        else if (arr[0][i]==arr[1][i] and arr[1][i]==arr[2][i] and arr[2][i]==-1)

            win =1;

     }

    if (arr[0][0]==arr[1][1] and arr[1][1]==arr[2][2] and arr[2][2]==-1)

            win=1;

    if (arr[0][2]==arr[1][1] and arr[1][1]==arr[2][0] and arr[2][0]==-1)

            win=1;

    if (win){

         cout<<"Yes";

         return 0;

    }

    cout<<"No"<<endl;

}

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

int main(){

	int na;

	int a[10];

	int angka[3][3];

	int tanda[3][3];

	

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

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

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

		}

	}

	scanf("%d", &na);

	for(int c=0;c<na;c++){

		scanf("%d", &a[c]);

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

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

            if( a[c] == angka[l][k] ){

                tanda[l][k] = 1;

                }

            }

        }

    }



    if( (tanda[1][1] == 1 && tanda[2][2] == 1 && tanda[0][0] == 1  )

    || (tanda[2][0] == 1 && tanda[1][1] == 1 && tanda[0][2] == 1  )

    || (tanda[0][0] == 1 && tanda[0][1] == 1 && tanda[0][2] == 1  )

    || (tanda[1][0] == 1 && tanda[1][1] == 1 && tanda[1][2] == 1  )

    || (tanda[2][0] == 1 && tanda[2][1] == 1 && tanda[2][2] == 1  )

    || (tanda[0][0] == 1 && tanda[1][0] == 1 && tanda[2][0] == 1  )

    || (tanda[0][1] == 1 && tanda[1][1] == 1 && tanda[2][1] == 1  )

    || (tanda[0][2] == 1 && tanda[1][2] == 1 && tanda[2][2] == 1  )

    ) {

        printf("Yes\n");

    } else {

        printf("No\n");

    }

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#define _USE_MATH_DEFINES



#include <iostream>

#include <math.h> 

#include <vector>

#include <algorithm>

#include <iomanip>      // std::setprecision

#include <map>

#include <unordered_map>

#include <string>

#include <set>

#include <unordered_set>

#include <sstream>



using namespace std;



int main()

{

	int N;

	std::set<int> nums;

	vector<vector<int>> card(3,std::vector<int>(3,0));

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

	{

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

		{

			int input;

			std::cin >> input;

			card[i][j] = input;

		}

	}



	std::cin >> N;

	for (int k = 0; k < N; ++k)

	{

		int num;

		std::cin >> num;

		nums.insert(num);

	}

	//check rows

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

	{

		int counter = 0;

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

		{

			if (nums.find(card[i][j]) != nums.end())

			{

				counter++;

			}

			else

			{

				break;

			}

		}

		if (counter == 3)

		{

			std::cout << "Yes\n";

			return 0;

		}

	}

	//check columns

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

	{

		int counter = 0;

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

		{

			if (nums.find(card[j][i]) != nums.end())

			{

				counter++;

			}

			else

			{

				break;

			}

		}

		if (counter == 3)

		{

			std::cout << "Yes\n";

			return 0;

		}

	}



		int counter = 0;

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

		{

			if (nums.find(card[j][j]) != nums.end())

			{

				counter++;

			}

			else

			{

				break;

			}

		}

		if (counter == 3)

		{

			std::cout << "Yes\n";

			return 0;

		}

		counter = 0;

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

		{

			if (nums.find(card[j][2-j]) != nums.end())

			{

				counter++;

			}

			else

			{

				break;

			}

		}

		if (counter == 3)

		{

			std::cout << "Yes\n";

			return 0;

		}

	std::cout << "No\n";



}


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

int main(){

    int N, G[10];

    int a[3][3], ck[3][3];

 

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

        scanf("%d %d %d",&a[i][0],&a[i][1],&a[i][2]);

    }



    scanf("%d",&N);



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

        scanf("%d",&G[j]);

 

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

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

                if( G[j] == a[x][z] ) {

                    ck[x][z] = 1;

                }

            }

        }

    }



    if( (ck[1][1] == 1 && ck[2][2] == 1 && ck[0][0] == 1  )

    ||(ck[2][0] == 1 && ck[1][1] == 1 && ck[0][2] == 1  )

    ||(ck[0][0] == 1 && ck[0][1] == 1 && ck[0][2] == 1  )

    ||(ck[1][0] == 1 && ck[1][1] == 1 && ck[1][2] == 1  )

    ||(ck[2][0] == 1 && ck[2][1] == 1 && ck[2][2] == 1  )

    ||(ck[0][0] == 1 && ck[1][0] == 1 && ck[2][0] == 1  )

    ||(ck[0][1] == 1 && ck[1][1] == 1 && ck[2][1] == 1  )

    || (ck[0][2] == 1 && ck[1][2] == 1 && ck[2][2] == 1  )

    ) {

        printf("Yes\n");

    } else {

        printf("No\n");

    }





    return 0;

}

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

#include<fstream>

#include<cstdio>

#include<algorithm>

#include<cstring>

#include<cmath>

#include<vector>

#include<map>

using namespace std;

typedef long long ll;

int main()

{

    int a[50][50],b[50],c[50][50]={0},d[50]={0};

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

    {

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

        cin>>a[i][j];

    }

    int n;

    cin>>n;

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

    cin>>b[i];

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

    {

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

        {

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

            {

                if(b[i]==a[j][k])

                {

                    c[j][k]=1;

                }

            }

        }

    }

    int sum1=0,sum2=0,sum3=0,sum4=0;

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

    {

        sum1=0;

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

        {

            if(c[i][j]==1)

            {

                sum1++;

            }

            if(sum1==3)

            break;

        }

        if(sum1==3)

        break;

    }

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

    {

        sum2=0;

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

        {

            if(c[j][i]==1)

            {

                sum2++;

            }

            if(sum2==3)

            break;

        }

        if(sum2==3)

        break;

    }

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

    {

        if(c[i][i]==1)

        {

            sum3++;

        }

    }

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

    {

        if(c[i][2-i]==1)

        {

            sum4++;

        }

    }

    if(sum1==3||sum2==3||sum3==3||sum4==3)

    cout<<"Yes";

    else 

    cout<<"No";

    return 0;

}

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

int main(){

    int N, G[10];

    int a[3][3], ck[3][3];

 

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

        scanf("%d %d %d",&a[i][0],&a[i][1],&a[i][2]);

    }



    scanf("%d",&N);



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

        scanf("%d",&G[j]);

 

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

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

                if( G[j] == a[x][z] ) {

                    ck[x][z] = 1;

                }

            }

        }

    }



    if( (ck[1][1] == 1 && ck[2][2] == 1 && ck[0][0] == 1  )

    ||(ck[2][0] == 1 && ck[1][1] == 1 && ck[0][2] == 1  )

    ||(ck[0][0] == 1 && ck[0][1] == 1 && ck[0][2] == 1  )

    ||(ck[1][0] == 1 && ck[1][1] == 1 && ck[1][2] == 1  )

    ||(ck[2][0] == 1 && ck[2][1] == 1 && ck[2][2] == 1  )

    ||(ck[0][0] == 1 && ck[1][0] == 1 && ck[2][0] == 1  )

    ||(ck[0][1] == 1 && ck[1][1] == 1 && ck[2][1] == 1  )

    || (ck[0][2] == 1 && ck[1][2] == 1 && ck[2][2] == 1  )

    ) {

        printf("Yes\n");

    } else {

        printf("No\n");

    }





    return 0;

}

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

using namespace std;



int a[5][5];

bool vis[5][5];



int main()

{

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

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

		for(int j=1;j<=3;j++){

			cin>>a[i][j];

		}

	}

	int n;cin>>n;

	int num;

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

		cin>>num;

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

			for(int j=1;j<=3;j++){

				if(num==a[k][j])vis[k][j]=1;

			}

		}

	}

	bool flag=0;

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

		if(vis[i][1]+vis[i][2]+vis[i][3]==3){

			flag=true;break;

		}

	}

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

		if(flag)break;

		if(vis[1][i]+vis[2][i]+vis[3][i]==3){

			flag=true;break;

		}

	}

	if(!flag&&(vis[1][1]+vis[2][2]+vis[3][3]==3||vis[3][1]+vis[2][2]+vis[1][3]==3))flag=true;

	if(flag)cout<<"Yes"<<endl;

	else cout<<"No"<<endl;

	return 0;

}

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

int main(){

    int N, G[10];

    int a[3][3], ck[3][3];

 

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

        scanf("%d %d %d",&a[i][0],&a[i][1],&a[i][2]);

    }



    scanf("%d",&N);



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

        scanf("%d",&G[j]);

 

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

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

                if( G[j] == a[x][z] ) {

                    ck[x][z] = 1;

                }

            }

        }

    }



    if( (ck[1][1] == 1 && ck[2][2] == 1 && ck[0][0] == 1  )

    ||(ck[2][0] == 1 && ck[1][1] == 1 && ck[0][2] == 1  )

    ||(ck[0][0] == 1 && ck[0][1] == 1 && ck[0][2] == 1  )

    ||(ck[1][0] == 1 && ck[1][1] == 1 && ck[1][2] == 1  )

    ||(ck[2][0] == 1 && ck[2][1] == 1 && ck[2][2] == 1  )

    ||(ck[0][0] == 1 && ck[1][0] == 1 && ck[2][0] == 1  )

    ||(ck[0][1] == 1 && ck[1][1] == 1 && ck[2][1] == 1  )

    || (ck[0][2] == 1 && ck[1][2] == 1 && ck[2][2] == 1  )

    ) {

        printf("Yes\n");

    } else {

        printf("No\n");

    }





    return 0;

}

// Fastest known solution for this problem: