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)]
for si in range(n+1):
    dp[si][0] = 1
for ti in range(m+1):
    dp[0][ti] = 1

for si in range(n):
    for ti in range(m):
        if s[si] == t[ti]:
            dp[si+1][ti+1] = dp[si][ti+1] + dp[si+1][ti]
            dp[si+1][ti+1] %= MOD 
        else:
            dp[si+1][ti+1] = dp[si][ti+1] + dp[si+1][ti] - dp[si][ti] 
            dp[si+1][ti+1] %= MOD

print(dp[-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]*(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)] for si in range(n+1):
    dp[si][0] = 1 si range(n+1) range n+1 n 1 dp[si][0] = 1 dp[si][0] [si] dp si 0 1 for ti in range(m+1):
    dp[0][ti] = 1 ti range(m+1) range m+1 m 1 dp[0][ti] = 1 dp[0][ti] [0] dp 0 ti 1 for si in range(n):
    for ti in range(m):
        if s[si] == t[ti]:
            dp[si+1][ti+1] = dp[si][ti+1] + dp[si+1][ti]
            dp[si+1][ti+1] %= MOD 
        else:
            dp[si+1][ti+1] = dp[si][ti+1] + dp[si+1][ti] - dp[si][ti] 
            dp[si+1][ti+1] %= MOD si range(n) range n for ti in range(m):
        if s[si] == t[ti]:
            dp[si+1][ti+1] = dp[si][ti+1] + dp[si+1][ti]
            dp[si+1][ti+1] %= MOD 
        else:
            dp[si+1][ti+1] = dp[si][ti+1] + dp[si+1][ti] - dp[si][ti] 
            dp[si+1][ti+1] %= MOD ti range(m) range m if s[si] == t[ti]:
            dp[si+1][ti+1] = dp[si][ti+1] + dp[si+1][ti]
            dp[si+1][ti+1] %= MOD 
        else:
            dp[si+1][ti+1] = dp[si][ti+1] + dp[si+1][ti] - dp[si][ti] 
            dp[si+1][ti+1] %= MOD s[si] == t[ti] s[si] s si t[ti] t ti dp[si+1][ti+1] = dp[si][ti+1] + dp[si+1][ti] dp[si+1][ti+1] [si+1] dp si+1 si 1 ti+1 ti 1 dp[si][ti+1] + dp[si+1][ti] dp[si][ti+1] [si] dp si ti+1 ti 1 dp[si+1][ti] [si+1] dp si+1 si 1 ti dp[si+1][ti+1] %= MOD dp[si+1][ti+1] [si+1] dp si+1 si 1 ti+1 ti 1 MOD dp[si+1][ti+1] = dp[si][ti+1] + dp[si+1][ti] - dp[si][ti] dp[si+1][ti+1] [si+1] dp si+1 si 1 ti+1 ti 1 dp[si][ti+1] + dp[si+1][ti] - dp[si][ti] dp[si][ti+1] + dp[si+1][ti] dp[si][ti+1] [si] dp si ti+1 ti 1 dp[si+1][ti] [si+1] dp si+1 si 1 ti dp[si][ti] [si] dp si ti dp[si+1][ti+1] %= MOD dp[si+1][ti+1] [si+1] dp si+1 si 1 ti+1 ti 1 MOD print(dp[-1][-1] % MOD) print dp[-1][-1] % MOD dp[-1][-1] [-1] dp -1 -1 MOD n, m = map(int, input().split()) map(int, input().split()) n 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 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
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)]
for si in range(n+1):
    dp[si][0] = 1
for ti in range(m+1):
    dp[0][ti] = 1

for si in range(n):
    for ti in range(m):
        if s[si] == t[ti]:
            dp[si+1][ti+1] = dp[si][ti+1] + dp[si+1][ti]
            dp[si+1][ti+1] %= MOD 
        else:
            dp[si+1][ti+1] = dp[si][ti+1] + dp[si+1][ti] - dp[si][ti] 
            dp[si+1][ti+1] %= MOD

print(dp[-1][-1] % MOD)