# coding: utf-8
# Your code here!
N,M = map(int,input().split())
S = list(map(int,input().split()))
T = list(map(int,input().split()))
LAST = 10**6
MOD = 10**9 + 7
S.append(LAST)
T.append(LAST)
total = [[0 for j in range(M+2)] for i in range(N+2)]
for i in range(N+1):
    for j in range(M+1):
        I,J = i+1,j+1
        if S[i] != T[j]:
            total[I][J] = (total[I][J-1] + total[I-1][J] - total[I-1][J-1]) % MOD
        else:
            total[I][J] = (total[I][J-1] + total[I-1][J] + 1) % MOD
        
print((total[N][M] + 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 LAST = 10**6 LAST 10**6 10 6 MOD = 10**9 + 7 MOD 10**9 + 7 10**9 10 9 7 S.append(LAST) S.append S append LAST T.append(LAST) T.append T append LAST [0 for j in range(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 for j in range(M+2)] total = [[0 for j in range(M+2)] for i in range(N+2)] total [[0 for j in range(M+2)] for i in range(N+2)] for i in range(N+1):
    for j in range(M+1):
        I,J = i+1,j+1
        if S[i] != T[j]:
            total[I][J] = (total[I][J-1] + total[I-1][J] - total[I-1][J-1]) % MOD
        else:
            total[I][J] = (total[I][J-1] + total[I-1][J] + 1) % MOD
         i range(N+1) range N+1 N 1 for j in range(M+1):
        I,J = i+1,j+1
        if S[i] != T[j]:
            total[I][J] = (total[I][J-1] + total[I-1][J] - total[I-1][J-1]) % MOD
        else:
            total[I][J] = (total[I][J-1] + total[I-1][J] + 1) % MOD
         j range(M+1) range M+1 M 1 I,J = i+1,j+1 I i+1 i 1 J j+1 j 1 if S[i] != T[j]:
            total[I][J] = (total[I][J-1] + total[I-1][J] - total[I-1][J-1]) % MOD
        else:
            total[I][J] = (total[I][J-1] + total[I-1][J] + 1) % MOD
         S[i] != T[j] S[i] S i T[j] T j total[I][J] = (total[I][J-1] + total[I-1][J] - total[I-1][J-1]) % MOD total[I][J] [I] total I J (total[I][J-1] + total[I-1][J] - total[I-1][J-1]) % MOD total[I][J-1] + total[I-1][J] - total[I-1][J-1] total[I][J-1] + total[I-1][J] total[I][J-1] [I] total I J-1 J 1 total[I-1][J] [I-1] total I-1 I 1 J total[I-1][J-1] [I-1] total I-1 I 1 J-1 J 1 MOD total[I][J] = (total[I][J-1] + total[I-1][J] + 1) % MOD total[I][J] [I] total I J (total[I][J-1] + total[I-1][J] + 1) % MOD total[I][J-1] + total[I-1][J] + 1 total[I][J-1] + total[I-1][J] total[I][J-1] [I] total I J-1 J 1 total[I-1][J] [I-1] total I-1 I 1 J 1 MOD print((total[N][M] + 1) % MOD) print (total[N][M] + 1) % MOD total[N][M] + 1 total[N][M] [N] total N M 1 MOD J = i+1,j+1 j+1 J LAST = 10**6 10**6 LAST M = map(int,input().split()) map(int,input().split()) M N,M = map(int,input().split()) map(int,input().split()) N S = list(map(int,input().split())) list(map(int,input().split())) S total = [[0 for j in range(M+2)] for i in range(N+2)] [[0 for j in range(M+2)] for i in range(N+2)] total T = list(map(int,input().split())) list(map(int,input().split())) T MOD = 10**9 + 7 10**9 + 7 MOD I,J = i+1,j+1 i+1 I
# coding: utf-8
# Your code here!
N,M = map(int,input().split())
S = list(map(int,input().split()))
T = list(map(int,input().split()))
LAST = 10**6
MOD = 10**9 + 7
S.append(LAST)
T.append(LAST)
total = [[0 for j in range(M+2)] for i in range(N+2)]
for i in range(N+1):
    for j in range(M+1):
        I,J = i+1,j+1
        if S[i] != T[j]:
            total[I][J] = (total[I][J-1] + total[I-1][J] - total[I-1][J-1]) % MOD
        else:
            total[I][J] = (total[I][J-1] + total[I-1][J] + 1) % MOD
        
print((total[N][M] + 1) % MOD)