N, M = (int(i) for i in input().split())
MOD = 10**9 + 7
S = [int(i) for i in input().split()]
T = [int(i) for i in input().split()]

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

DP = [[0] * (M+1) for counter1 in range(N+1)]
DP[0][0] = 1
for i in range(N):
    DP[i+1][0] = 1
for i in range(M):
    DP[0][i+1] = 1
for i in range(N):
    for j in range(M):
        if S[i] != T[j]:
            DP[i+1][j+1] = DP[i+1][j] + DP[i][j+1] - DP[i][j]
            DP[i+1][j+1] %= MOD
        else:
            DP[i+1][j+1] = DP[i+1][j] + DP[i][j+1]
            DP[i+1][j+1] %= MOD
print(DP[N][M])