mod = 10**9+7
N,M = map(int,input().split())
S = list(map(int,input().split()))
T = list(map(int,input().split()))
dp = [[0]*(len(T)+1) for _ in range(len(S)+1)]
for s in range(len(S)+1):
    for t in range(len(T)+1):
        if s == 0 or t == 0:
            dp[s][t] = 1

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

for s in range(len(S)):
    for t in range(len(T)):
        if S[s]==T[t]:
            dp[s+1][t+1] = (dp[s+1][t]+dp[s][t+1])%mod
        else:
            dp[s+1][t+1] = (dp[s+1][t]+dp[s][t+1]-dp[s][t])%mod
print(dp[len(S)][len(T)])