stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 1.2650872589373026x):
#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 = -100; i <= 100; i++) {

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

			for (int k = -100; k <= 100; 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;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 1.3702715165184576x):
#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;

}
// Slower C++ solution:
#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;

}




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



using namespace std;

int main()

{

    int a, b, c, d, e, f, g, h, i;

    cin >> a >> b >> c >> d >> e >> f >> g >> h >> i;



    if (a + e == b + d and b + f == e + c and d + h == e + g and e + i == f + h)

        cout << "Yes" << endl;

    else

        cout << "No" << endl;

}
// Slower C++ solution:
#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;

}




// Faster C++ solution for the same problem (measured speedup: 2.4906548519419967x):
#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;

}
// Slower C++ solution:
#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;

}




// Faster C++ solution for the same problem (measured speedup: 2.4900820684789555x):
#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] != arr[i][j] - b[j] ){

                    cout<<"No\n";

                    return 0;

                }

            }

        }

        cout<<"Yes\n";

    }

    return 0;

}
// Slower C++ solution:
#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;

}

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



int main()

{

    int c[3][3];

    int i,j;

    int flag=1;;



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

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

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



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

        if(flag&&((c[i][0]-c[i+1][0])!=(c[i][1]-c[i+1][1])||(c[i][2]-c[i+1][2])!=(c[i][1]-c[i+1][1])))

            flag=0;

        if(flag&&((c[0][i]-c[0][i+1])!=(c[1][i]-c[1][i+1])||(c[2][i]-c[2][i+1])!=(c[1][i]-c[1][i+1])))

            flag=0;

    }



    if(flag)

        printf("Yes");

    else

        printf("No");



    return 0;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 5.306879586218558x):
#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;

}
// Slower C++ solution:
#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;

}

	

// Faster C++ solution for the same problem (measured speedup: 5.313866586327317x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 2.0366028528920674x):
#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;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 1.9799543120404155x):
#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(j, 3) if (!(c[0][j] - a1 == c[1][j] - a2 &&

                        c[1][j] - a2 == c[2][j] - a3)) ok = false;

        if (ok) {

            cout << "Yes" << endl;

            return 0;

        }

    }



    cout << "No" << endl;

    return 0;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 1.9857940384221344x):
#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;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 2.4964494351757205x):
#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;

}
// Slower C++ solution:
#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]);





    

    



}

// Faster C++ solution for the same problem (measured speedup: 1.9093169163671513x):
#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]);





    

    



}