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

DP = [[0] * n for _ in range(m)]

t0 = T[0]
count = 0
for i in range(n):
    if S[i] == t0:
        count += 1
    DP[0][i] = count

s0 = S[0]
count = 0
for j in range(m):
    if T[j] == s0:
        count += 1
    DP[j][0] = count

for j in range(1, m):
    for i in range(1, n):
        total = DP[j-1][i] + DP[j][i-1] - DP[j-1][i-1]
        if T[j] == S[i]:
            total += DP[j-1][i-1] + 1
        total %= mod
        DP[j][i] = total

ans = DP[m-1][n-1] + 1
print(ans) 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] * n for _ in range(m) for _ in range(m) _ range(m) range m for _ in range(m) [0] * n [0] 0 n DP = [[0] * n for _ in range(m)] DP [[0] * n for _ in range(m)] t0 = T[0] t0 T[0] T 0 count = 0 count 0 for i in range(n):
    if S[i] == t0:
        count += 1
    DP[0][i] = count i range(n) range n if S[i] == t0:
        count += 1
     S[i] == t0 S[i] S i t0 count += 1 count 1 DP[0][i] = count DP[0][i] [0] DP 0 i count s0 = S[0] s0 S[0] S 0 count = 0 count 0 for j in range(m):
    if T[j] == s0:
        count += 1
    DP[j][0] = count j range(m) range m if T[j] == s0:
        count += 1
     T[j] == s0 T[j] T j s0 count += 1 count 1 DP[j][0] = count DP[j][0] [j] DP j 0 count for j in range(1, m):
    for i in range(1, n):
        total = DP[j-1][i] + DP[j][i-1] - DP[j-1][i-1]
        if T[j] == S[i]:
            total += DP[j-1][i-1] + 1
        total %= mod
        DP[j][i] = total j range(1, m) range 1 m for i in range(1, n):
        total = DP[j-1][i] + DP[j][i-1] - DP[j-1][i-1]
        if T[j] == S[i]:
            total += DP[j-1][i-1] + 1
        total %= mod
        DP[j][i] = total i range(1, n) range 1 n total = DP[j-1][i] + DP[j][i-1] - DP[j-1][i-1] total DP[j-1][i] + DP[j][i-1] - DP[j-1][i-1] DP[j-1][i] + DP[j][i-1] DP[j-1][i] [j-1] DP j-1 j 1 i DP[j][i-1] [j] DP j i-1 i 1 DP[j-1][i-1] [j-1] DP j-1 j 1 i-1 i 1 if T[j] == S[i]:
            total += DP[j-1][i-1] + 1
         T[j] == S[i] T[j] T j S[i] S i total += DP[j-1][i-1] + 1 total DP[j-1][i-1] + 1 DP[j-1][i-1] [j-1] DP j-1 j 1 i-1 i 1 1 total %= mod total mod DP[j][i] = total DP[j][i] [j] DP j i total ans = DP[m-1][n-1] + 1 ans DP[m-1][n-1] + 1 DP[m-1][n-1] [m-1] DP m-1 m 1 n-1 n 1 1 print(ans) print ans T = list(map(int, input().split())) list(map(int, input().split())) T s0 = S[0] S[0] s0 total %= mod mod total total += DP[j-1][i-1] + 1 DP[j-1][i-1] + 1 total t0 = T[0] T[0] t0 total = DP[j-1][i] + DP[j][i-1] - DP[j-1][i-1] DP[j-1][i] + DP[j][i-1] - DP[j-1][i-1] total S = list(map(int, input().split())) list(map(int, input().split())) S ans = DP[m-1][n-1] + 1 DP[m-1][n-1] + 1 ans DP = [[0] * n for _ in range(m)] [[0] * n for _ in range(m)] DP count = 0 0 count n, m = map(int, input().split()) map(int, input().split()) n m = map(int, input().split()) map(int, input().split()) m count = 0 0 count mod = 10**9 + 7 10**9 + 7 mod count += 1 1 count count += 1 1 count
n, m = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
mod = 10**9 + 7

DP = [[0] * n for _ in range(m)]

t0 = T[0]
count = 0
for i in range(n):
    if S[i] == t0:
        count += 1
    DP[0][i] = count

s0 = S[0]
count = 0
for j in range(m):
    if T[j] == s0:
        count += 1
    DP[j][0] = count

for j in range(1, m):
    for i in range(1, n):
        total = DP[j-1][i] + DP[j][i-1] - DP[j-1][i-1]
        if T[j] == S[i]:
            total += DP[j-1][i-1] + 1
        total %= mod
        DP[j][i] = total

ans = DP[m-1][n-1] + 1
print(ans)
