# coding: utf-8
# Your code here!

N, M = list(map(int, input().rstrip().split(' ')))
S = list(map(int, input().rstrip().split(' ')))
T = list(map(int, input().rstrip().split(' ')))
dp = [[0] * (N + 1) for _ in range(M + 1)]

for i in range(1, M+1):
    for j in range(1, N+1):
        if S[j-1] == T[i-1]:
            dp[i][j] = dp[i-1][j] + dp[i][j-1] + 1
        else:
            dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1]
        dp[i][j] = dp[i][j] % 1000000007
            
print((dp[-1][-1]+1) % 1000000007) N, M = list(map(int, input().rstrip().split(' '))) N list(map(int, input().rstrip().split(' '))) list map(int, input().rstrip().split(' ')) map int input().rstrip().split(' ') ().rstrip().split ().rstrip() ().rstrip () input rstrip split ' ' M S = list(map(int, input().rstrip().split(' '))) S list(map(int, input().rstrip().split(' '))) list map(int, input().rstrip().split(' ')) map int input().rstrip().split(' ') ().rstrip().split ().rstrip() ().rstrip () input rstrip split ' ' T = list(map(int, input().rstrip().split(' '))) T list(map(int, input().rstrip().split(' '))) list map(int, input().rstrip().split(' ')) map int input().rstrip().split(' ') ().rstrip().split ().rstrip() ().rstrip () input rstrip split ' ' [0] * (N + 1) for _ in range(M + 1) for _ in range(M + 1) _ range(M + 1) range M + 1 M 1 for _ in range(M + 1) [0] * (N + 1) [0] 0 N + 1 N 1 dp = [[0] * (N + 1) for _ in range(M + 1)] dp [[0] * (N + 1) for _ in range(M + 1)] for i in range(1, M+1):
    for j in range(1, N+1):
        if S[j-1] == T[i-1]:
            dp[i][j] = dp[i-1][j] + dp[i][j-1] + 1
        else:
            dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1]
        dp[i][j] = dp[i][j] % 1000000007
             i range(1, M+1) range 1 M+1 M 1 for j in range(1, N+1):
        if S[j-1] == T[i-1]:
            dp[i][j] = dp[i-1][j] + dp[i][j-1] + 1
        else:
            dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1]
        dp[i][j] = dp[i][j] % 1000000007
             j range(1, N+1) range 1 N+1 N 1 if S[j-1] == T[i-1]:
            dp[i][j] = dp[i-1][j] + dp[i][j-1] + 1
        else:
            dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1]
         S[j-1] == T[i-1] S[j-1] S j-1 j 1 T[i-1] T i-1 i 1 dp[i][j] = dp[i-1][j] + dp[i][j-1] + 1 dp[i][j] [i] dp i j dp[i-1][j] + dp[i][j-1] + 1 dp[i-1][j] + dp[i][j-1] dp[i-1][j] [i-1] dp i-1 i 1 j dp[i][j-1] [i] dp i j-1 j 1 1 dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1] dp[i][j] [i] dp i j dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1] dp[i-1][j] + dp[i][j-1] dp[i-1][j] [i-1] dp i-1 i 1 j dp[i][j-1] [i] dp i j-1 j 1 dp[i-1][j-1] [i-1] dp i-1 i 1 j-1 j 1 dp[i][j] = dp[i][j] % 1000000007 dp[i][j] [i] dp i j dp[i][j] % 1000000007 dp[i][j] [i] dp i j 1000000007 print((dp[-1][-1]+1) % 1000000007) print (dp[-1][-1]+1) % 1000000007 dp[-1][-1]+1 dp[-1][-1] [-1] dp -1 -1 1 1000000007 M = list(map(int, input().rstrip().split(' '))) list(map(int, input().rstrip().split(' '))) M N, M = list(map(int, input().rstrip().split(' '))) list(map(int, input().rstrip().split(' '))) N T = list(map(int, input().rstrip().split(' '))) list(map(int, input().rstrip().split(' '))) T S = list(map(int, input().rstrip().split(' '))) list(map(int, input().rstrip().split(' '))) S dp = [[0] * (N + 1) for _ in range(M + 1)] [[0] * (N + 1) for _ in range(M + 1)] dp
# coding: utf-8
# Your code here!

N, M = list(map(int, input().rstrip().split(' ')))
S = list(map(int, input().rstrip().split(' ')))
T = list(map(int, input().rstrip().split(' ')))
dp = [[0] * (N + 1) for _ in range(M + 1)]

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