N, M = map(int,input().split())
S = list(map(int,input().split()))
T = list(map(int,input().split()))

dp = [[0 for i in range(M+1)] for j in range(N+1)]
SUM = [[0 for i in range(M+1)] for j in range(N+1)]
mod = 10 ** 9 + 7

for i in range(N):
    for j in range(M):
        if S[i] == T[j]:
            dp[i+1][j+1] = SUM[i][j] + 1
        else:
            dp[i+1][j+1] = 0
        SUM[i+1][j+1] = SUM[i][j+1] + SUM[i+1][j] - SUM[i][j] + dp[i+1][j+1]
        dp[i+1][j+1] %= mod
        SUM[i+1][j+1] %= mod

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

dp = [[0 for i in range(M+1)] for j in range(N+1)]
SUM = [[0 for i in range(M+1)] for j in range(N+1)]
mod = 10 ** 9 + 7

for i in range(N):
    for j in range(M):
        if S[i] == T[j]:
            dp[i+1][j+1] = SUM[i][j] + 1
        else:
            dp[i+1][j+1] = 0
        SUM[i+1][j+1] = SUM[i][j+1] + SUM[i+1][j] - SUM[i][j] + dp[i+1][j+1]
        dp[i+1][j+1] %= mod
        SUM[i+1][j+1] %= mod

print((SUM[N][M] + 1) % mod)