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