N, M = map(int, input().split())
S = list(input().split())
T = list(input().split())
MOD = 10**9+7
dp = [[0] * (M+1) for _ in range(N+1)]
sum = [[0] * (M+1) for _ in range(N+1)]
dp[0][0] = 1
for i in range(N+1):
    sum[i][0] = 1
for j in range(M+1):
    sum[0][j] = 1
for i in range(N):
    for j in range(M):
        if S[i] == T[j]:
            dp[i+1][j+1] = sum[i][j]
        sum[i+1][j+1] = (sum[i+1][j] + sum[i][j+1] - sum[i][j] + dp[i+1][j+1]) % MOD
print(sum[N][M]) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M S = list(input().split()) S list(input().split()) list input().split() ().split () input split T = list(input().split()) T list(input().split()) list input().split() ().split () input split MOD = 10**9+7 MOD 10**9+7 10**9 10 9 7 [0] * (M+1) for _ in range(N+1) for _ in range(N+1) _ range(N+1) range N+1 N 1 for _ in range(N+1) [0] * (M+1) [0] 0 M+1 M 1 dp = [[0] * (M+1) for _ in range(N+1)] dp [[0] * (M+1) for _ in range(N+1)] [0] * (M+1) for _ in range(N+1) for _ in range(N+1) _ range(N+1) range N+1 N 1 for _ in range(N+1) [0] * (M+1) [0] 0 M+1 M 1 sum = [[0] * (M+1) for _ in range(N+1)] sum [[0] * (M+1) for _ in range(N+1)] dp[0][0] = 1 dp[0][0] [0] dp 0 0 1 for i in range(N+1):
    sum[i][0] = 1 i range(N+1) range N+1 N 1 sum[i][0] = 1 sum[i][0] [i] sum i 0 1 for j in range(M+1):
    sum[0][j] = 1 j range(M+1) range M+1 M 1 sum[0][j] = 1 sum[0][j] [0] sum 0 j 1 for i in range(N):
    for j in range(M):
        if S[i] == T[j]:
            dp[i+1][j+1] = sum[i][j]
        sum[i+1][j+1] = (sum[i+1][j] + sum[i][j+1] - sum[i][j] + dp[i+1][j+1]) % MOD i range(N) range N for j in range(M):
        if S[i] == T[j]:
            dp[i+1][j+1] = sum[i][j]
        sum[i+1][j+1] = (sum[i+1][j] + sum[i][j+1] - sum[i][j] + dp[i+1][j+1]) % MOD j range(M) range M if S[i] == T[j]:
            dp[i+1][j+1] = sum[i][j]
         S[i] == T[j] S[i] S i T[j] T j dp[i+1][j+1] = sum[i][j] dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 sum[i][j] [i] sum i j sum[i+1][j+1] = (sum[i+1][j] + sum[i][j+1] - sum[i][j] + dp[i+1][j+1]) % MOD sum[i+1][j+1] [i+1] sum i+1 i 1 j+1 j 1 (sum[i+1][j] + sum[i][j+1] - sum[i][j] + dp[i+1][j+1]) % MOD sum[i+1][j] + sum[i][j+1] - sum[i][j] + dp[i+1][j+1] sum[i+1][j] + sum[i][j+1] - sum[i][j] sum[i+1][j] + sum[i][j+1] sum[i+1][j] [i+1] sum i+1 i 1 j sum[i][j+1] [i] sum i j+1 j 1 sum[i][j] [i] sum i j dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 MOD print(sum[N][M]) print sum[N][M] [N] sum N M N, M = map(int, input().split()) map(int, input().split()) N S = list(input().split()) list(input().split()) S M = map(int, input().split()) map(int, input().split()) M T = list(input().split()) list(input().split()) T sum = [[0] * (M+1) for _ in range(N+1)] [[0] * (M+1) for _ in range(N+1)] sum MOD = 10**9+7 10**9+7 MOD dp = [[0] * (M+1) for _ in range(N+1)] [[0] * (M+1) for _ in range(N+1)] dp
N, M = map(int, input().split())
S = list(input().split())
T = list(input().split())
MOD = 10**9+7
dp = [[0] * (M+1) for _ in range(N+1)]
sum = [[0] * (M+1) for _ in range(N+1)]
dp[0][0] = 1
for i in range(N+1):
    sum[i][0] = 1
for j in range(M+1):
    sum[0][j] = 1
for i in range(N):
    for j in range(M):
        if S[i] == T[j]:
            dp[i+1][j+1] = sum[i][j]
        sum[i+1][j+1] = (sum[i+1][j] + sum[i][j+1] - sum[i][j] + dp[i+1][j+1]) % MOD
print(sum[N][M])