N,M = map(int, input().split())
S = [int(s) for s in input().split()]
T = [int(t) for t in input().split()]

mod = 10**9+7
dp = [[0]*(M+1) for _ in range(N+1)]
sum2D = [[0]*(M+1) for _ in range(N+1)]


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

mod = 10**9+7
dp = [[0]*(M+1) for _ in range(N+1)]
sum2D = [[0]*(M+1) for _ in range(N+1)]


for i in range(1, N+1):
    for j in range(1, M+1):
        if S[i-1] == T[j-1]:
            dp[i][j] = sum2D[i-1][j-1] + 1
            dp[i][j] %= mod
        sum2D[i][j] = dp[i][j] + sum2D[i-1][j] + sum2D[i][j-1] - sum2D[i-1][j-1]
        sum2D[i][j] %= mod
        
ans = 1
for i in range(1, N+1):
    for j in range(1, M+1):
        ans += dp[i][j]
        ans %= mod
        
print(ans)