N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
MOD = 10 ** 9 + 7
dp = [[0] * (M + 1) for i in range(N + 1)]
s = [[0] * (M + 1) for i in range(N + 1)]
dp[0][0] = 1

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

ans = 0
for i in range(N + 1):
    for j in range(M + 1):
        ans += dp[i][j]
        ans %= MOD
print(ans) 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 MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 [0] * (M + 1) for i in range(N + 1) for i in range(N + 1) i range(N + 1) range N + 1 N 1 for i in range(N + 1) [0] * (M + 1) [0] 0 M + 1 M 1 dp = [[0] * (M + 1) for i in range(N + 1)] dp [[0] * (M + 1) for i in range(N + 1)] [0] * (M + 1) for i in range(N + 1) for i in range(N + 1) i range(N + 1) range N + 1 N 1 for i in range(N + 1) [0] * (M + 1) [0] 0 M + 1 M 1 s = [[0] * (M + 1) for i in range(N + 1)] s [[0] * (M + 1) for i in range(N + 1)] dp[0][0] = 1 dp[0][0] [0] dp 0 0 1 for i in range(N):
    for j in range(M):
        if S[i] == T[j]:
            dp[i + 1][j + 1] = s[i][j] + 1
            dp[i + 1][j + 1] %= MOD
        s[i + 1][j + 1] = s[i + 1][j] + s[i][j + 1] - s[i][j] + dp[i + 1][j + 1]
        s[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] = s[i][j] + 1
            dp[i + 1][j + 1] %= MOD
        s[i + 1][j + 1] = s[i + 1][j] + s[i][j + 1] - s[i][j] + dp[i + 1][j + 1]
        s[i + 1][j + 1] %= MOD j range(M) range M if S[i] == T[j]:
            dp[i + 1][j + 1] = s[i][j] + 1
            dp[i + 1][j + 1] %= MOD
         S[i] == T[j] S[i] S i T[j] T j dp[i + 1][j + 1] = s[i][j] + 1 dp[i + 1][j + 1] [i + 1] dp i + 1 i 1 j + 1 j 1 s[i][j] + 1 s[i][j] [i] s i j 1 dp[i + 1][j + 1] %= MOD dp[i + 1][j + 1] [i + 1] dp i + 1 i 1 j + 1 j 1 MOD s[i + 1][j + 1] = s[i + 1][j] + s[i][j + 1] - s[i][j] + dp[i + 1][j + 1] s[i + 1][j + 1] [i + 1] s i + 1 i 1 j + 1 j 1 s[i + 1][j] + s[i][j + 1] - s[i][j] + dp[i + 1][j + 1] s[i + 1][j] + s[i][j + 1] - s[i][j] s[i + 1][j] + s[i][j + 1] s[i + 1][j] [i + 1] s i + 1 i 1 j s[i][j + 1] [i] s i j + 1 j 1 s[i][j] [i] s i j dp[i + 1][j + 1] [i + 1] dp i + 1 i 1 j + 1 j 1 s[i + 1][j + 1] %= MOD s[i + 1][j + 1] [i + 1] s i + 1 i 1 j + 1 j 1 MOD ans = 0 ans 0 for i in range(N + 1):
    for j in range(M + 1):
        ans += dp[i][j]
        ans %= MOD i range(N + 1) range N + 1 N 1 for j in range(M + 1):
        ans += dp[i][j]
        ans %= MOD j range(M + 1) range M + 1 M 1 ans += dp[i][j] ans dp[i][j] [i] dp i j ans %= MOD ans MOD print(ans) print ans N, M = map(int, input().split()) map(int, input().split()) N ans = 0 0 ans S = list(map(int, input().split())) list(map(int, input().split())) S ans %= MOD MOD ans dp = [[0] * (M + 1) for i in range(N + 1)] [[0] * (M + 1) for i in range(N + 1)] dp MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD s = [[0] * (M + 1) for i in range(N + 1)] [[0] * (M + 1) for i in range(N + 1)] s M = map(int, input().split()) map(int, input().split()) M T = list(map(int, input().split())) list(map(int, input().split())) T ans += dp[i][j] dp[i][j] ans
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
MOD = 10 ** 9 + 7
dp = [[0] * (M + 1) for i in range(N + 1)]
s = [[0] * (M + 1) for i in range(N + 1)]
dp[0][0] = 1

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

ans = 0
for i in range(N + 1):
    for j in range(M + 1):
        ans += dp[i][j]
        ans %= MOD
print(ans)