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)]
dps = [[0]*(M+1) for i in range(N+1)]
for n in range(N):
    for m in range(M):
        if S[n] == T[m]:
            dp[n+1][m+1] = (dps[n][m]+1)%mod
        dps[n+1][m+1] = (dp[n+1][m+1]+dps[n+1][m]+dps[n][m+1]-dps[n][m])%mod

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

print(dps[-1][-1]+1)
