# dp[i][j] SとTの最後の文字を採用するような文字列の個数。これにより各DPテーブルの値が排反になる。元の文字列の最後を必ず採用するので
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
MOD = 10**9 + 7
dp = [[0] * (M + 2) for _ in range(N + 2)]
sdp = [[0] * (M + 2) for _ in range(N + 2)]
dp[0][0] = 1
sdp[1][1] = 1
for i in range(N + 1):
    for j in range(M + 1):
        if i - 1 >= 0 and j - 1 >= 0 and S[i - 1] == T[j - 1]:
            dp[i][j] = sdp[i][j]
        sdp[i + 1][j + 1] = sdp[i + 1][j] + sdp[i][j + 1] - sdp[i][j] + dp[i][j]
        sdp[i + 1][j + 1] %= MOD
        sdp[i + 1][j + 1] %= MOD
print(sdp[N + 1][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] * (M + 2) for _ in range(N + 2) for _ in range(N + 2) _ range(N + 2) range N + 2 N 2 for _ in range(N + 2) [0] * (M + 2) [0] 0 M + 2 M 2 dp = [[0] * (M + 2) for _ in range(N + 2)] dp [[0] * (M + 2) for _ in range(N + 2)] [0] * (M + 2) for _ in range(N + 2) for _ in range(N + 2) _ range(N + 2) range N + 2 N 2 for _ in range(N + 2) [0] * (M + 2) [0] 0 M + 2 M 2 sdp = [[0] * (M + 2) for _ in range(N + 2)] sdp [[0] * (M + 2) for _ in range(N + 2)] dp[0][0] = 1 dp[0][0] [0] dp 0 0 1 sdp[1][1] = 1 sdp[1][1] [1] sdp 1 1 1 for i in range(N + 1):
    for j in range(M + 1):
        if i - 1 >= 0 and j - 1 >= 0 and S[i - 1] == T[j - 1]:
            dp[i][j] = sdp[i][j]
        sdp[i + 1][j + 1] = sdp[i + 1][j] + sdp[i][j + 1] - sdp[i][j] + dp[i][j]
        sdp[i + 1][j + 1] %= MOD
        sdp[i + 1][j + 1] %= MOD i range(N + 1) range N + 1 N 1 for j in range(M + 1):
        if i - 1 >= 0 and j - 1 >= 0 and S[i - 1] == T[j - 1]:
            dp[i][j] = sdp[i][j]
        sdp[i + 1][j + 1] = sdp[i + 1][j] + sdp[i][j + 1] - sdp[i][j] + dp[i][j]
        sdp[i + 1][j + 1] %= MOD
        sdp[i + 1][j + 1] %= MOD j range(M + 1) range M + 1 M 1 if i - 1 >= 0 and j - 1 >= 0 and S[i - 1] == T[j - 1]:
            dp[i][j] = sdp[i][j]
         i - 1 >= 0 and j - 1 >= 0 and S[i - 1] == T[j - 1] i - 1 >= 0 and j - 1 >= 0 i - 1 >= 0 i - 1 i 1 0 j - 1 >= 0 j - 1 j 1 0 S[i - 1] == T[j - 1] S[i - 1] S i - 1 i 1 T[j - 1] T j - 1 j 1 dp[i][j] = sdp[i][j] dp[i][j] [i] dp i j sdp[i][j] [i] sdp i j sdp[i + 1][j + 1] = sdp[i + 1][j] + sdp[i][j + 1] - sdp[i][j] + dp[i][j] sdp[i + 1][j + 1] [i + 1] sdp i + 1 i 1 j + 1 j 1 sdp[i + 1][j] + sdp[i][j + 1] - sdp[i][j] + dp[i][j] sdp[i + 1][j] + sdp[i][j + 1] - sdp[i][j] sdp[i + 1][j] + sdp[i][j + 1] sdp[i + 1][j] [i + 1] sdp i + 1 i 1 j sdp[i][j + 1] [i] sdp i j + 1 j 1 sdp[i][j] [i] sdp i j dp[i][j] [i] dp i j sdp[i + 1][j + 1] %= MOD sdp[i + 1][j + 1] [i + 1] sdp i + 1 i 1 j + 1 j 1 MOD sdp[i + 1][j + 1] %= MOD sdp[i + 1][j + 1] [i + 1] sdp i + 1 i 1 j + 1 j 1 MOD print(sdp[N + 1][M + 1]) print sdp[N + 1][M + 1] [N + 1] sdp N + 1 N 1 M + 1 M 1 MOD = 10**9 + 7 10**9 + 7 MOD dp = [[0] * (M + 2) for _ in range(N + 2)] [[0] * (M + 2) for _ in range(N + 2)] dp sdp = [[0] * (M + 2) for _ in range(N + 2)] [[0] * (M + 2) for _ in range(N + 2)] sdp N, M = map(int, input().split()) map(int, input().split()) N M = map(int, input().split()) map(int, input().split()) M S = list(map(int, input().split())) list(map(int, input().split())) S T = list(map(int, input().split())) list(map(int, input().split())) T
# dp[i][j] SとTの最後の文字を採用するような文字列の個数。これにより各DPテーブルの値が排反になる。元の文字列の最後を必ず採用するので
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
MOD = 10**9 + 7
dp = [[0] * (M + 2) for _ in range(N + 2)]
sdp = [[0] * (M + 2) for _ in range(N + 2)]
dp[0][0] = 1
sdp[1][1] = 1
for i in range(N + 1):
    for j in range(M + 1):
        if i - 1 >= 0 and j - 1 >= 0 and S[i - 1] == T[j - 1]:
            dp[i][j] = sdp[i][j]
        sdp[i + 1][j + 1] = sdp[i + 1][j] + sdp[i][j + 1] - sdp[i][j] + dp[i][j]
        sdp[i + 1][j + 1] %= MOD
        sdp[i + 1][j + 1] %= MOD
print(sdp[N + 1][M + 1])
