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

using namespace std;

int a[3],b[3][3],c[3][3];

int main(){

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

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

            cin>>c[i][j];

        }

    }

    for(a[0]=0;a[0]<=100;++a[0]){

        for(a[1]=0;a[1]<=100;++a[1]){

            for(a[2]=0;a[2]<=100;++a[2]){

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

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

                        b[j][i]=c[i][j]-a[i];

                    }

                }

                bool ok=true;

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

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

                        if(b[i][j]!=b[i][0]){

                            ok=false;

                        }

                    }

                }

                if(ok){

                    cout<<"Yes"<<endl;

                    return 0;

                }

            }

        }

    }

    cout<<"No"<<endl;

    return 0;

}

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

#include<iomanip>

#include<cmath>

#include<cstdio>

#include<cstdlib>

#include<cstring>

#include<algorithm>

#include<set>

#include<map>

#include<queue>

#include<stack>

#include<vector>

#include<cctype>

#define szxb 13

#define F(a,b,c) for(register int (a)=(b);(a)<=(c);(a)++)

#define PDXD(a,b) (!(a-b))

#define PDBXD(a,b) (!(!(a-b)))

#define CON continue;

#define GO goto endreturn;

using namespace std;

int a[szxb][szxb];

int main()

{

	F(i,1,3){F(j,1,3){scanf("%d",&a[i][j]);}}

	int a1,a2,a3,b1,b2,b3,c1,c2,c3;

	F(i,0,100){a1=(a[1][1]-i);a2=(a[1][2]-i);a3=(a[1][3]-i);F(j,0,100){b1=(a[2][1]-j);b2=(a[2][2]-j);b3=(a[2][3]-j);if((PDBXD(a1,b1))||(PDBXD(a2,b2))||(PDBXD(a3,b3))){CON;}F(k,0,100){c1=(a[3][1]-k);c2=(a[3][2]-k);c3=(a[3][3]-k);if((PDXD(a1,c1))&&(PDXD(a2,c2))&&(PDXD(a3,c3))){printf("Yes");GO;}}}}

	printf("No");

	endreturn:return putchar(10),0;

}

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

#include <cstdio>

#include <algorithm>

#include <vector>

#include <queue>

#include <set>

#include <map>

using namespace std;

#define int long long

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

const int mo = 1e9 + 7;

int grid[3][3];

void solve()

{

    int c[3][3];

    rep(i,3)rep(j,3)cin>>c[i][j];

    int a[3],b[3];

    for(a[0]=0;a[0]<=100;a[0]++)

    {

        for(a[1]=0;a[1]<=100;a[1]++)

        {

            for(a[2]=0;a[2]<=100;a[2]++)

            {

                b[0]=c[0][0]-a[0];

                b[1]=c[0][1]-a[0];

                b[2]=c[0][2]-a[0];

                

                bool ok=1;

                rep(i,3)

                {

                    rep(j,3)

                    {

                        ok&=c[i][j]==a[i]+b[j];

                    }

                }

                if(ok)

                {

                    cout<<"Yes"<<endl;

                    return ;

                }

            }

        }

    }

    cout<<"No"<<endl;

}

main()

{

    cin.tie(0);

    ios::sync_with_stdio(0);

    solve();

    return 0;

}

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

#include <cstdio>

#include <algorithm>

#include <vector>

#include <queue>

#include <set>

#include <map>

using namespace std;

#define int long long

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

const int mo = 1e9 + 7;

int d[3][3];

void solve()

{

    rep(i,3)rep(j,3)cin>>d[i][j];

    int a=d[0][2]-d[0][1],b=d[1][2]-d[1][1],c=d[2][2]-d[2][1];

    if(a!=b||b!=c){puts("No");return;}

    a=d[0][1]-d[0][0],b=d[1][1]-d[1][0],c=d[2][1]-d[2][0];

    if(a!=b||b!=c){puts("No");return;}

    a=d[2][2]-d[1][2],b=d[2][1]-d[1][1],c=d[2][0]-d[1][0];

    if(a!=b||b!=c){puts("No");return;}

    a=d[1][2]-d[0][2],b=d[1][1]-d[0][1],c=d[1][0]-d[0][0];

    if(a!=b||b!=c){puts("No");return;}

    puts("Yes");

}

main()

{

    cin.tie(0);

    ios::sync_with_stdio(0);

    solve();

    return 0;

}

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

#include <cstring>

#include <vector>

#include <map>

#include <string>

#include <algorithm>



 

using namespace std;



typedef long long ll;

typedef long double ld;

#define L(ID) ((ID*2)+1)

#define R(ID) ((ID*2)+2)

#define M(L,R) ((L+R)/2)

#define forr(start,end) for(int i = start; i < end; i++)

#define gap ' '

 

const int MAXN = 1e5 + 5;



ll largest(ll a, ll b){

	return (a<b)?b:a;

}

ll smallest(ll a, ll b){

	if(a < b)return a;

	return b;

}



int main(){

	int c[3][3];

	int a[3];

	int b[3];

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

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

			cin >> c[i][j];

		}	

	}

	for(a[0] = 0; a[0] <= 100; a[0]++){

		for(a[1] = 0; a[1] <= 100; a[1]++){

			for(a[2] = 0; a[2] <= 100; a[2]++){

				b[0] = c[0][0] - a[0];

        		b[1] = c[0][1] - a[0];

        		b[2] = c[0][2] - a[0];

        		bool correct = true;

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

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

        				correct &= c[i][j] == a[i] + b[j];

         			}

        		}

        		if(correct){

        			cout << "Yes" << endl;

        			return 0;

        		}

			}

		}

	}

	cout << "No" << endl;



    return 0;

}


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

#include <cstring>

#include <vector>

#include <map>

#include <string>

#include <algorithm>



 

using namespace std;



typedef long long ll;

typedef long double ld;

#define L(ID) ((ID*2)+1)

#define R(ID) ((ID*2)+2)

#define M(L,R) ((L+R)/2)

#define forr(start,end) for(int i = start; i < end; i++)

#define gap ' '

 

const int MAXN = 1e5 + 5;



ll largest(ll a, ll b){

	return (a<b)?b:a;

}

ll smallest(ll a, ll b){

	if(a < b)return a;

	return b;

}



int main(){

	int c[3][3];

	int a[3];

	int b[3];

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

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

			cin >> c[i][j];

		}	

	}

	for(a[0] = 0; a[0] <= 100; a[0]++){

		for(a[1] = 0; a[1] <= 100; a[1]++){

			for(a[2] = 0; a[2] <= 100; a[2]++){

				b[0] = c[0][0] - a[0];

        		b[1] = c[0][1] - a[0];

        		b[2] = c[0][2] - a[0];

        		bool correct = true;

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

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

        				if(c[i][j] != a[i] + b[j]){

        					correct = false;

        				}

         			}

        		}

        		if(correct){

        			cout << "Yes" << endl;

        			return 0;

        		}

			}

		}

	}

	cout << "No" << endl;



    return 0;

}


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

#include <string>

#include <algorithm>

#include <map>

#include <math.h>

#include <iomanip>

#include <vector>

#include <queue>

#include <functional>

#include <random>

#include <time.h>

using namespace std;

typedef long long int ll;

typedef pair<ll, ll> P;

int main() {

	ll c[4][4];

	for (int i = 1; i <= 3; i++)for (int j = 1; j <= 3; j++)cin >> c[i][j];

	for (int i = -200; i <= 200; i++) {

		for (int j = -200; j <= 200; j++) {

			for (int k = -200; k <= 200; k++) {

				ll a[4], b[4];

				a[1] = i, a[2] = j, a[3] = k;

				b[1] = c[1][1] - a[1];

				b[2] = c[2][2] - a[2];

				b[3] = c[3][3] - a[3];

				bool f = 1;

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

					if (a[i] + b[j] != c[i][j]) {

						f = 0;

						break;

					}

				}

				if (f) {

					cout << "Yes" << endl;

					return 0;

				}

			}

		}

	}

	cout << "No" << endl;

	return 0;

}


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

#include <random>

#include <time.h>

#include <vector>

#include <queue>

#include <functional>

#include <map>

#include <string>

#include <cstdlib>

#include <typeinfo>

#include <math.h>

#include <algorithm>

#include <iostream>

using namespace std;

typedef long long ll;

typedef pair<ll, ll> P;



int main() {

	ll c[3][3];

	for (int i = 0; i < 3; i++)for (int j = 0; j < 3; j++)cin >> c[i][j];

	cout << (c[0][0] + c[1][1] + c[2][2] == c[0][1] + c[1][2] + c[2][0] && c[0][0] + c[1][1] + c[2][2] == c[0][2] + c[1][0] + c[2][1] ? "Yes" : "No") << endl;

	return 0;

}


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

using namespace std;



#define    ll     long long int



int grid[4][4];

int a[4];

int b[4];



int main( )

{

    int i, j, k;

    int p, q, r;

    int x, y, z;

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

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

            cin >> grid[i][j];

        }

    }

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

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

            for (k = 0; k <= 100; k++) {

                b[0] = grid[0][0] - i;

                b[1] = grid[1][1] - j;

                b[2] = grid[2][2] - k;

                a[0] = i;

                a[1] = j;

                a[2] = k;

                int fl = 1;

                for (x = 0; fl && x < 3; x++) {

                    for (y = 0; fl && y < 3; y++) {

                        if (a[x] + b[y] != grid[x][y]) {

                            fl = 0;

                            break;

                        }

                    }

                }

                if (fl) {

                    cout << "Yes\n";

                    return 0;

                }

            }

        }

    }

    cout << "No\n";

    return 0;

}




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

#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL)

#define endl "\n"

#define ll long long

#define N ((int)(1e5 + 5))

#define MAX ((int)(1e9 + 5))

#define MOD ((int)(7901 + 0))





using namespace std;





/*fast io

ios_base::sync_with_stdio(false);

cin.tie(NULL);

*/







int main()

{

    int t;

    t = 1;

    while(t--){

        int arr[5][5];

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

            for(int j = 1 ; j<4 ; j++) cin>>arr[i][j];

        }

        int b[5] , a[5];

        a[1] = 0;

        for(int i = 1 ; i<4 ; i++) b[i] = arr[1][i] - a[1];

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

            a[i] = arr[i][1] - b[1];

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

                if( a[i] + b[j] != arr[i][j] ){

                    cout<<"No\n";

                    return 0;

                }

            }

        }

        cout<<"Yes\n";

    }

    return 0;

}


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

#include<algorithm>

#include<string.h>

#include<string>

using namespace std;

int a[4][4];

int main()

{

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

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

			cin >> a[i][j];

	for (int k = -2000; k <= 2000; k++) {

		int a2, a3, b1, b2, b3;

		int a1 = k;

		b1 = a[1][1] - k;

		b2 = a[1][2] - k;

		b3 = a[1][3] - k;

		a2 = a[2][1] - b1;

		a3 = a[3][1] - b1;

		int flag = 0;

		if (a[2][2] != a2 + b2) 

			flag = 1;

		if (a[2][3] != a2 + b3) 

			flag = 1;

		if (a[3][2] != a3 + b2) 

			flag = 1;

		if (a[3][3] != a3 + b3) 

			flag = 1;

		if (!flag) 

		{

			cout << "Yes" << endl; 

			return 0;

		}

	}

	cout << "No" << endl;

	return 0;

}

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

#include <stdlib.h>

#include <math.h> 

int main ()

{

	int a[3][3];

	int n,i,j;

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

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

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

	if (a[0][0]-a[1][0]==a[0][1]-a[1][1]&&a[0][0]-a[1][0]==a[0][2]-a[1][2]&&a[1][0]-a[2][0]==a[1][1]-a[2][1]&&a[1][0]-a[2][0]==a[1][2]-a[2][2])

	printf ("Yes\n");

	else printf ("No\n");

	return 0;

}

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

#include <cstdio>

#include <algorithm>



int a[5], b[5], c[5][5];

using namespace std;

int main(){

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

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

			cin>>c[i][j];

	for(int a1 = 0; a1 < 101; a1++)

		for(int a2 = 0; a2 < 101; a2++)

			for(int a3 = 0; a3 < 101; a3++){

        int b1 = c[0][0] - a1;

        int b2 = c[0][1] - a1;

        int b3 = c[0][2] - a1;

 

        a[0] = a1;

        a[1] = a2;

        a[2] = a3;

        b[0] = b1;

        b[1] = b2;

        b[2] = b3;

 

        bool flag = true;

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

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

				if (a[i] + b[j] != c[i][j])

					flag = false;

        if (flag) {

            printf("Yes\n");

            return 0;

        }

    }

 

    printf("No\n");

    return 0;

}

	

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

#include <stdlib.h>

#include <math.h> 

int main ()

{

	int a[3][3];

	int n,i,j;

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

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

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

	if (a[0][0]-a[1][0]==a[0][1]-a[1][1]&&a[0][0]-a[1][0]==a[0][2]-a[1][2]&&a[1][0]-a[2][0]==a[1][1]-a[2][1]&&a[1][0]-a[2][0]==a[1][2]-a[2][2])

	printf ("Yes\n");

	else printf ("No\n");

	return 0;

}

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

using namespace std;



int main() {

  int c[4][4];

  for (int i = 1; i <= 3; i++) for (int j = 1; j <= 3; j++) cin >> c[i][j];



  int a1, a2, a3;

  int correct = 0;

  for (a1 = 0; a1 <= 100; a1++) {

    for (a2 = 0; a2 <= 100; a2++) {

      for (a3 = 0; a3 <= 100; a3++) {

        int b1_1 = c[1][1] - a1; int b1_2 = c[2][1] - a2; int b1_3 = c[3][1] - a3;

        int b2_1 = c[1][2] - a1; int b2_2 = c[2][2] - a2; int b2_3 = c[3][2] - a3;

        int b3_1 = c[1][3] - a1; int b3_2 = c[2][3] - a2; int b3_3 = c[3][3] - a3;



        if (b1_1 == b1_2 && b1_2 == b1_3 &&

          b2_1 == b2_2 && b2_2 == b2_3 &&

          b3_1 == b3_2 && b3_2 == b3_3) correct = 1;

      }

    }

  }



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

  else cout << "No" << endl;



  return 0;

}

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

using namespace std;



int main() {

  int c[4][4];

  for (int i = 1; i <= 3; i++) for (int j = 1; j <= 3; j++) cin >> c[i][j];



  int a[4] = {0,1}, b[4];

  for (int i = 1; i <= 3; i++) b[i] = c[1][i] - a[1];

  for (int i = 2; i <= 3; i++) a[i] = c[i][1] - b[1];



  int f = 1;

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

    for (int j = 1; j <= 3; j++) if (c[i][j] != a[i] + b[j]) f = 0;

  }



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

  else cout << "No" << endl;



  return 0;

}

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

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

typedef long long ll;

using namespace std;



int main() {

    int c[3][3];

    rep(i, 3) rep(j, 3) cin >> c[i][j];



    rep(a1, 101) rep(a2, 101) rep(a3, 101) {

        bool ok = true;



        rep(i, 3) {

            int b1 = c[0][i] - a1;

            int b2 = c[1][i] - a2;

            int b3 = c[2][i] - a3;

            if (!(b1 == b2 && b2 == b3 && b1 == b3)) ok = false;

        }



        if (ok) {

            cout << "Yes" << endl;

            return 0;

        }

    }



    cout << "No" << endl;

    return 0;

}


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

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

typedef long long ll;

using namespace std;



int main() {

    int c[3][3];

    rep(i, 3) rep(j, 3) cin >> c[i][j];



    rep(a1, 101) rep(a2, 101) rep(a3, 101) {

        if (c[0][0] - a1 == c[0][1] - a2 && c[0][1] - a2 == c[0][2] - a3 &&

            c[1][0] - a1 == c[1][1] - a2 && c[1][1] - a2 == c[1][2] - a3 &&

            c[2][0] - a1 == c[2][1] - a2 && c[2][1] - a2 == c[2][2] - a3) {

            cout << "Yes" << endl;

            return 0;

        }

    }



    cout << "No" << endl;

    return 0;

}


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



using namespace std;



int main()

{

  int a[3];

  int b[3];

  int c[3][3];



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

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

      cin >> c[i][j];



  for (int i1 = 0; i1 < 101; i1++)

  {

    for (int i2 = 0; i2 < 101; i2++)

    {

      for (int i3 = 0; i3 < 101; i3++)

      {

        a[0] = i1;

        a[1] = i2;

        a[2] = i3;



        b[0] = c[0][0] - a[0];

        b[1] = c[0][1] - a[0];

        b[2] = c[0][2] - a[0];



        int cnt = 0;

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

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

          {

            if (c[i][j] == a[i] + b[j]) cnt++;

          }



        if (cnt == 9)

        {

          cout << "Yes\n";

          return 0;

        }



      }

    }

  }

  cout << "No\n";

  return 0;

}


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

#include <vector>

#include <numeric>

#include <functional>



//using namespace std;

using namespace std;



int main()

{

  int c[3][3] = { 0 };



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

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

      cin >> c[i][j];

   

  bool endFlag = false;



  for (int a0 = 0; a0 < 101; a0++)

  {

    for (int a1 = 0; a1 < 101; a1++)

    {

      for (int a2 = 0; a2 < 101; a2++)

      {

        //3 * 3 のグリッドに対する処理

        int a[3] = { a0, a1, a2 };

        int b[3] = { 0 };



        //全iに対してのb[j]を決める

        int bmCount = 0;



        auto Match3Elems = [&](int j) -> bool

        {

          if (c[0][j] - a[0] == c[1][j] - a[1] && c[1][j] - a[1] == c[2][j] - a[2])

            return true;

          else

            return false;

        };



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

          if (Match3Elems(j)) bmCount++; //3つのb[j]がそれぞれ一致しているか



        if (bmCount == 3)

        {

          b[0] = c[0][0] - a[0];

          b[1] = c[0][1] - a[0];

          b[2] = c[0][2] - a[0];



          int cmCount = 0;

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

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

              if (c[i][j] == a[i] + b[j]) cmCount++;



          if (cmCount == 9)

          {

            endFlag = true;

            break;

          }

        }



      }

    }

  }



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

  else cout << "No" << endl;



  return 0;

}

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

using namespace std;

typedef long long ll;

typedef pair<ll, ll> lpair;

const ll MOD = 1e9 + 7;

const ll INF = 1e18;

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

#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)

#define print(x) cout << (x) << endl;

#define print2(x,y) cout << (x) << " " << (y) << endl;

#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;

ll dp[2010][2010] = {};

int main(){

    cin.tie(0);

    ios::sync_with_stdio(false);

    ll N,M;

    cin >> N >> M;

    ll S[2010], T[2010];

    rep(i,0,N) cin >> S[i];

    rep(i,0,M) cin >> T[i];

    dp[0][0] = 1;

    ll sb[2010], tb[2010];

    memset(sb,-1,sizeof(sb));

    memset(tb,-1,sizeof(tb));

    ll pos[100010] = {};

    memset(pos,-1, sizeof(pos));

    rep(i,0,N){

        if(pos[S[i]] == -1){

            sb[i] = -1;

        }else{

            sb[i] = pos[S[i]];

        }

        pos[S[i]] = i;

    }

    memset(pos,-1, sizeof(pos));

    rep(i,0,M){

        if(pos[T[i]] == -1){

            tb[i] = -1;

        }else{

            tb[i] = pos[T[i]];

        }

        pos[T[i]] = i;

    }

    rep(i,1,N+1){

        dp[i][0] = 1;

    }

    rep(i,1,M+1){

        dp[0][i] = 1;

    }

    rep(i,0,N){

        rep(j,0,M){

            if(S[i] == T[j]){

                dp[i+1][j+1] = (dp[i+1][j] + dp[i][j+1]) % MOD;

            }else{

                dp[i+1][j+1] = (dp[i+1][j] + dp[i][j+1] - dp[i][j] + MOD) % MOD;

            }

        }

    }

    print(dp[N][M]);





    

    



}

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

using namespace std;

typedef long long ll;

typedef pair<ll, ll> lpair;

const ll MOD = 1e9 + 7;

const ll INF = 1e18;

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

#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)

#define print(x) cout << (x) << endl;

#define print2(x,y) cout << (x) << " " << (y) << endl;

#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;

ll dp[2010][2010] = {};

int main(){

    cin.tie(0);

    ios::sync_with_stdio(false);

    ll N,M;

    cin >> N >> M;

    ll S[2010], T[2010];

    rep(i,0,N) cin >> S[i];

    rep(i,0,M) cin >> T[i];

    rep(i,0,N+1){

        dp[i][0] = 1;

    }

    rep(i,0,M+1){

        dp[0][i] = 1;

    }

    rep(i,0,N){

        rep(j,0,M){

            if(S[i] == T[j]){

                dp[i+1][j+1] = (dp[i+1][j] + dp[i][j+1]) % MOD;

            }else{

                dp[i+1][j+1] = (dp[i+1][j] + dp[i][j+1] - dp[i][j] + MOD) % MOD;

            }

        }

    }

    print(dp[N][M]);





    

    



}

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



using namespace std;



using ll = long long;

using P = pair<ll, ll>;

using edge = pair<ll, P>;

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

#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)

#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)

using Graph = vector<vector<ll>>;

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

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

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

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

const ll MOD = 1000000007;

const ll INF = 1000000000000000000L;

#ifdef __DEBUG



#include "cpp-pyprint/pyprint.h"



#endif



ll dp[2005][2005];



void Main() {

    int N, M;

    cin >> N >> M;

    vector<int> S(N), T(M);

    rep(i, N) cin >> S[i];

    rep(i, M) cin >> T[i];

    dp[0][0] = 1;

    rep(i, 2005) dp[i][0] = 1;

    rep(i, 2005) dp[0][i] = 1;

    rep(i, N) {

        rep(j, M) {

            if (S[i] == T[j]) {

                dp[i + 1][j + 1] += dp[i+1][j] +  dp[i][j+1];

            } else {

                dp[i + 1][j + 1] += ((dp[i+1][j] +  dp[i][j+1])%MOD) -  dp[i][j];

            }

            if (dp[i+1][j+1] < 0 ) {

                dp[i+1][j+1] += MOD;

            }

            dp[i + 1][j + 1] %= MOD;

        }

    }

    cout << dp[N][M] %  MOD << endl;



}



int main() {

    cin.tie(0);

    ios::sync_with_stdio(false);

    cout << fixed << setprecision(15);

    Main();

}


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



using namespace std;



using ll = long long;

using P = pair<ll, ll>;

using edge = pair<ll, P>;

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

#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)

#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)

using Graph = vector<vector<ll>>;

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

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

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

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

const ll MOD = 1000000007;

const ll INF = 1000000000000000000L;

#ifdef __DEBUG



#include "cpp-pyprint/pyprint.h"



#endif



ll dp[2005][2005];



void Main() {

    int N, M;

    cin >> N >> M;

    vector<ll> S(N), T(M);

    rep(i, N) cin >> S[i];

    rep(i, M) cin >> T[i];

    rep(i, N) {

        rep(j, M){

            if (S[i] == T[j]) {

                dp[i+1][j+1] += dp[i][j] + 1;

            }

            dp[i+1][j+1] += dp[i+1][j] + dp[i][j+1] - dp[i][j];

            if(dp[i+1][j+1] < 0){

                dp[i+1][j+1] += MOD;

            }

            dp[i+1][j+1] %= MOD;

        }

    }

    cout << dp[N][M] + 1 << endl;

}



int main() {

    cin.tie(0);

    ios::sync_with_stdio(false);

    cout << fixed << setprecision(15);

    Main();

}


// Fastest known solution for this problem: