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