N, M = map(int,input().split())
S = list(map(int,input().split()))
T = list(map(int,input().split()))
MOD = 10**9 + 7
dp = [[0 for k in range(M+1)] for l in range(N+1)]

for k in range(N):
    for l in range(M):
        if S[k] == T[l]:
            dp[k+1][l+1] = dp[k+1][l] + dp[k][l+1] + 1
        else:
            dp[k+1][l+1] = dp[k+1][l] + dp[k][l+1] - dp[k][l]
        dp[k+1][l+1] %= MOD

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

for k in range(N):
    for l in range(M):
        if S[k] == T[l]:
            dp[k+1][l+1] = dp[k+1][l] + dp[k][l+1] + 1
        else:
            dp[k+1][l+1] = dp[k+1][l] + dp[k][l+1] - dp[k][l]
        dp[k+1][l+1] %= MOD

print(dp[N][M]+1)
