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 + 1) for i in range(N + 1)]
dp_sum = [[0] * (M + 1) for i in range(N + 1)]

dp[0][0] = 1
for i, s in enumerate(S, start=1):
    for j, t in enumerate(T, start=1):
        if s == t:
            dp[i][j] = dp_sum[i - 1][j - 1] + 1
            dp[i][j] %= MOD
        dp_sum[i][j] = dp_sum[i - 1][j] + dp_sum[i][j - 1] - dp_sum[i - 1][j - 1] + dp[i][j]
        dp_sum[i][j] %= MOD

ans = 0
for i in range(N + 1):
    for j in range(M + 1):
        ans += dp[i][j]
        ans %= MOD

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

dp[0][0] = 1
for i, s in enumerate(S, start=1):
    for j, t in enumerate(T, start=1):
        if s == t:
            dp[i][j] = dp_sum[i - 1][j - 1] + 1
            dp[i][j] %= MOD
        dp_sum[i][j] = dp_sum[i - 1][j] + dp_sum[i][j - 1] - dp_sum[i - 1][j - 1] + dp[i][j]
        dp_sum[i][j] %= MOD

ans = 0
for i in range(N + 1):
    for j in range(M + 1):
        ans += dp[i][j]
        ans %= MOD

print(ans % MOD)
