N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
mod = 10**9+7

dp = [[0 for i in range(M)] for j in range(N)]
sum_dp = [[0 for i in range(M)] for j in range(N)]


if S[0] == T[0]:
    dp[0][0] = 1
    sum_dp[0][0] = 1

for i in range(1, N):
    if S[i] == T[0]:
        dp[i][0] = 1
    sum_dp[i][0] = (sum_dp[i-1][0] + dp[i][0])%mod

for j in range(1, M):
    if S[0] == T[j]:
        dp[0][j] = 1
    sum_dp[0][j] = (sum_dp[0][j-1] + dp[0][j])%mod

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

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

dp = [[0 for i in range(M)] for j in range(N)]
sum_dp = [[0 for i in range(M)] for j in range(N)]


if S[0] == T[0]:
    dp[0][0] = 1
    sum_dp[0][0] = 1

for i in range(1, N):
    if S[i] == T[0]:
        dp[i][0] = 1
    sum_dp[i][0] = (sum_dp[i-1][0] + dp[i][0])%mod

for j in range(1, M):
    if S[0] == T[j]:
        dp[0][j] = 1
    sum_dp[0][j] = (sum_dp[0][j-1] + dp[0][j])%mod

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

print((sum_dp[N-1][M-1]+1)%mod)