N, M = map(int, input().split())
MOD = 10**9 + 7
s = list(map(int, input().split()))
t = list(map(int, input().split()))

dp = [[0 for i in range(M+1)] for j in range(N+1)]
for j in range(M):
    dp[1][j + 1] = dp[1][j] + 1 if s[0] == t[j] else dp[1][j]

for i in range(N):
    dp[i + 1][1] = dp[i][1] + 1 if t[0] == s[i] else dp[i][1]

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

dp = [[0 for i in range(M+1)] for j in range(N+1)]
for j in range(M):
    dp[1][j + 1] = dp[1][j] + 1 if s[0] == t[j] else dp[1][j]

for i in range(N):
    dp[i + 1][1] = dp[i][1] + 1 if t[0] == s[i] else dp[i][1]

for i in range(1, N):
    for j in range(1, M):
        if s[i] == t[j]:
            dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] + 1)%MOD
        else:
            dp[i + 1][j + 1] = (dp[i][j+1] + dp[i+1][j] - dp[i][j])%MOD
    
print((dp[N][M] + 1)%MOD)
