N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
S.append(0)
T.append(0)
MOD = 1000000007

dp0 = [[0 for _ in range(2005)] for _ in range(2005)]
dp1 = [[0 for _ in range(2005)] for _ in range(2005)]

dp0[0][0] = 1
for i in range(N + 1):
  for j in range(M + 1):
    dp0[i + 1][j] += dp0[i][j] % MOD
    dp1[i][j] += dp0[i][j] % MOD
    dp1[i][j + 1] += dp1[i][j] % MOD

    if S[i] == T[j]:
      dp0[i + 1][j + 1] += dp1[i][j] % MOD
ans = dp1[N][M]
print(ans % MOD) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M S = list(map(int, input().split())) S list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split T = list(map(int, input().split())) T list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split S.append(0) S.append S append 0 T.append(0) T.append T append 0 MOD = 1000000007 MOD 1000000007 [0 for _ in range(2005)] for _ in range(2005) for _ in range(2005) _ range(2005) range 2005 for _ in range(2005) [0 for _ in range(2005)] dp0 = [[0 for _ in range(2005)] for _ in range(2005)] dp0 [[0 for _ in range(2005)] for _ in range(2005)] [0 for _ in range(2005)] for _ in range(2005) for _ in range(2005) _ range(2005) range 2005 for _ in range(2005) [0 for _ in range(2005)] dp1 = [[0 for _ in range(2005)] for _ in range(2005)] dp1 [[0 for _ in range(2005)] for _ in range(2005)] dp0[0][0] = 1 dp0[0][0] [0] dp0 0 0 1 for i in range(N + 1):
  for j in range(M + 1):
    dp0[i + 1][j] += dp0[i][j] % MOD
    dp1[i][j] += dp0[i][j] % MOD
    dp1[i][j + 1] += dp1[i][j] % MOD

    if S[i] == T[j]:
      dp0[i + 1][j + 1] += dp1[i][j] % MOD i range(N + 1) range N + 1 N 1 for j in range(M + 1):
    dp0[i + 1][j] += dp0[i][j] % MOD
    dp1[i][j] += dp0[i][j] % MOD
    dp1[i][j + 1] += dp1[i][j] % MOD

    if S[i] == T[j]:
      dp0[i + 1][j + 1] += dp1[i][j] % MOD j range(M + 1) range M + 1 M 1 dp0[i + 1][j] += dp0[i][j] % MOD dp0[i + 1][j] [i + 1] dp0 i + 1 i 1 j dp0[i][j] % MOD dp0[i][j] [i] dp0 i j MOD dp1[i][j] += dp0[i][j] % MOD dp1[i][j] [i] dp1 i j dp0[i][j] % MOD dp0[i][j] [i] dp0 i j MOD dp1[i][j + 1] += dp1[i][j] % MOD dp1[i][j + 1] [i] dp1 i j + 1 j 1 dp1[i][j] % MOD dp1[i][j] [i] dp1 i j MOD if S[i] == T[j]:
      dp0[i + 1][j + 1] += dp1[i][j] % MOD S[i] == T[j] S[i] S i T[j] T j dp0[i + 1][j + 1] += dp1[i][j] % MOD dp0[i + 1][j + 1] [i + 1] dp0 i + 1 i 1 j + 1 j 1 dp1[i][j] % MOD dp1[i][j] [i] dp1 i j MOD ans = dp1[N][M] ans dp1[N][M] [N] dp1 N M print(ans % MOD) print ans % MOD ans MOD M = map(int, input().split()) map(int, input().split()) M N, M = map(int, input().split()) map(int, input().split()) N S = list(map(int, input().split())) list(map(int, input().split())) S MOD = 1000000007 1000000007 MOD T = list(map(int, input().split())) list(map(int, input().split())) T ans = dp1[N][M] dp1[N][M] ans dp0 = [[0 for _ in range(2005)] for _ in range(2005)] [[0 for _ in range(2005)] for _ in range(2005)] dp0 dp1 = [[0 for _ in range(2005)] for _ in range(2005)] [[0 for _ in range(2005)] for _ in range(2005)] dp1
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
S.append(0)
T.append(0)
MOD = 1000000007

dp0 = [[0 for _ in range(2005)] for _ in range(2005)]
dp1 = [[0 for _ in range(2005)] for _ in range(2005)]

dp0[0][0] = 1
for i in range(N + 1):
  for j in range(M + 1):
    dp0[i + 1][j] += dp0[i][j] % MOD
    dp1[i][j] += dp0[i][j] % MOD
    dp1[i][j + 1] += dp1[i][j] % MOD

    if S[i] == T[j]:
      dp0[i + 1][j + 1] += dp1[i][j] % MOD
ans = dp1[N][M]
print(ans % MOD)