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

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

for i in range(1, N+1):
    for j in range(1, M+1):
        dp[i][j] = 0 if S[i-1]!=T[j-1] else (1 + accum[i-1][j-1])%MOD
        accum[i][j] = (accum[i-1][j]+accum[i][j-1]-accum[i-1][j-1]+dp[i][j])%MOD     

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

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

for i in range(1, N+1):
    for j in range(1, M+1):
        dp[i][j] = 0 if S[i-1]!=T[j-1] else (1 + accum[i-1][j-1])%MOD
        accum[i][j] = (accum[i-1][j]+accum[i][j-1]-accum[i-1][j-1]+dp[i][j])%MOD     

ans = (sum(map(sum, dp))+1)%MOD
print(ans)
