N,M = map(int, input().split())
Ss = list(map(int, input().split()))
Ts = list(map(int, input().split()))
mod = 10**9 + 7

x = 2160
dp = [[0]*x for i in range(x)]
sum2d = [[0]*x for i in range(x)]
for i in range(N):
    for j in range(M):
        if Ss[i] == Ts[j]:
            dp[i+1][j+1] = sum2d[i][j] + 1
        sum2d[i+1][j+1] = (dp[i+1][j+1]+sum2d[i][j+1]+sum2d[i+1][j]-sum2d[i][j])%mod
print((sum2d[N][M]+1)%mod) N,M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M Ss = list(map(int, input().split())) Ss list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split Ts = list(map(int, input().split())) Ts 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 x = 2160 x 2160 [0]*x for i in range(x) for i in range(x) i range(x) range x for i in range(x) [0]*x [0] 0 x dp = [[0]*x for i in range(x)] dp [[0]*x for i in range(x)] [0]*x for i in range(x) for i in range(x) i range(x) range x for i in range(x) [0]*x [0] 0 x sum2d = [[0]*x for i in range(x)] sum2d [[0]*x for i in range(x)] for i in range(N):
    for j in range(M):
        if Ss[i] == Ts[j]:
            dp[i+1][j+1] = sum2d[i][j] + 1
        sum2d[i+1][j+1] = (dp[i+1][j+1]+sum2d[i][j+1]+sum2d[i+1][j]-sum2d[i][j])%mod i range(N) range N for j in range(M):
        if Ss[i] == Ts[j]:
            dp[i+1][j+1] = sum2d[i][j] + 1
        sum2d[i+1][j+1] = (dp[i+1][j+1]+sum2d[i][j+1]+sum2d[i+1][j]-sum2d[i][j])%mod j range(M) range M if Ss[i] == Ts[j]:
            dp[i+1][j+1] = sum2d[i][j] + 1
         Ss[i] == Ts[j] Ss[i] Ss i Ts[j] Ts j dp[i+1][j+1] = sum2d[i][j] + 1 dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 sum2d[i][j] + 1 sum2d[i][j] [i] sum2d i j 1 sum2d[i+1][j+1] = (dp[i+1][j+1]+sum2d[i][j+1]+sum2d[i+1][j]-sum2d[i][j])%mod sum2d[i+1][j+1] [i+1] sum2d i+1 i 1 j+1 j 1 (dp[i+1][j+1]+sum2d[i][j+1]+sum2d[i+1][j]-sum2d[i][j])%mod dp[i+1][j+1]+sum2d[i][j+1]+sum2d[i+1][j]-sum2d[i][j] dp[i+1][j+1]+sum2d[i][j+1]+sum2d[i+1][j] dp[i+1][j+1]+sum2d[i][j+1] dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 sum2d[i][j+1] [i] sum2d i j+1 j 1 sum2d[i+1][j] [i+1] sum2d i+1 i 1 j sum2d[i][j] [i] sum2d i j mod print((sum2d[N][M]+1)%mod) print (sum2d[N][M]+1)%mod sum2d[N][M]+1 sum2d[N][M] [N] sum2d N M 1 mod N,M = map(int, input().split()) map(int, input().split()) N x = 2160 2160 x Ss = list(map(int, input().split())) list(map(int, input().split())) Ss mod = 10**9 + 7 10**9 + 7 mod sum2d = [[0]*x for i in range(x)] [[0]*x for i in range(x)] sum2d M = map(int, input().split()) map(int, input().split()) M Ts = list(map(int, input().split())) list(map(int, input().split())) Ts dp = [[0]*x for i in range(x)] [[0]*x for i in range(x)] dp
N,M = map(int, input().split())
Ss = list(map(int, input().split()))
Ts = list(map(int, input().split()))
mod = 10**9 + 7

x = 2160
dp = [[0]*x for i in range(x)]
sum2d = [[0]*x for i in range(x)]
for i in range(N):
    for j in range(M):
        if Ss[i] == Ts[j]:
            dp[i+1][j+1] = sum2d[i][j] + 1
        sum2d[i+1][j+1] = (dp[i+1][j+1]+sum2d[i][j+1]+sum2d[i+1][j]-sum2d[i][j])%mod
print((sum2d[N][M]+1)%mod)
