mod=1000000007
n,m=map(int,input().split())
S=tuple(map(int,input().split()))
T=tuple(map(int,input().split()))
DP=[[0]*(m+1) for _ in range(n+1)]
for i in range(n+1):
    DP[i][0]=1
for i in range(m+1):
    DP[0][i]=1
for i,s in enumerate(S):
    for j,t in enumerate(T):
        if s==t:
            DP[i+1][j+1]=DP[i][j+1]+DP[i+1][j]
        else:
            DP[i+1][j+1]=DP[i][j+1]+DP[i+1][j]-DP[i][j]
        DP[i+1][j+1]%=mod
print(DP[-1][-1]) mod=1000000007 mod 1000000007 n,m=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m S=tuple(map(int,input().split())) S tuple(map(int,input().split())) tuple map(int,input().split()) map int input().split() ().split () input split T=tuple(map(int,input().split())) T tuple(map(int,input().split())) tuple 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)] for i in range(n+1):
    DP[i][0]=1 i range(n+1) range n+1 n 1 DP[i][0]=1 DP[i][0] [i] DP i 0 1 for i in range(m+1):
    DP[0][i]=1 i range(m+1) range m+1 m 1 DP[0][i]=1 DP[0][i] [0] DP 0 i 1 for i,s in enumerate(S):
    for j,t in enumerate(T):
        if s==t:
            DP[i+1][j+1]=DP[i][j+1]+DP[i+1][j]
        else:
            DP[i+1][j+1]=DP[i][j+1]+DP[i+1][j]-DP[i][j]
        DP[i+1][j+1]%=mod i s enumerate(S) enumerate S for j,t in enumerate(T):
        if s==t:
            DP[i+1][j+1]=DP[i][j+1]+DP[i+1][j]
        else:
            DP[i+1][j+1]=DP[i][j+1]+DP[i+1][j]-DP[i][j]
        DP[i+1][j+1]%=mod j t enumerate(T) enumerate T if s==t:
            DP[i+1][j+1]=DP[i][j+1]+DP[i+1][j]
        else:
            DP[i+1][j+1]=DP[i][j+1]+DP[i+1][j]-DP[i][j]
         s==t s t DP[i+1][j+1]=DP[i][j+1]+DP[i+1][j] DP[i+1][j+1] [i+1] DP i+1 i 1 j+1 j 1 DP[i][j+1]+DP[i+1][j] DP[i][j+1] [i] DP i j+1 j 1 DP[i+1][j] [i+1] DP i+1 i 1 j DP[i+1][j+1]=DP[i][j+1]+DP[i+1][j]-DP[i][j] DP[i+1][j+1] [i+1] DP i+1 i 1 j+1 j 1 DP[i][j+1]+DP[i+1][j]-DP[i][j] DP[i][j+1]+DP[i+1][j] DP[i][j+1] [i] DP i j+1 j 1 DP[i+1][j] [i+1] DP i+1 i 1 j DP[i][j] [i] DP i j DP[i+1][j+1]%=mod DP[i+1][j+1] [i+1] DP i+1 i 1 j+1 j 1 mod print(DP[-1][-1]) print DP[-1][-1] [-1] DP -1 -1 DP=[[0]*(m+1) for _ in range(n+1)] [[0]*(m+1) for _ in range(n+1)] DP mod=1000000007 1000000007 mod S=tuple(map(int,input().split())) tuple(map(int,input().split())) S T=tuple(map(int,input().split())) tuple(map(int,input().split())) T n,m=map(int,input().split()) map(int,input().split()) n m=map(int,input().split()) map(int,input().split()) m
mod=1000000007
n,m=map(int,input().split())
S=tuple(map(int,input().split()))
T=tuple(map(int,input().split()))
DP=[[0]*(m+1) for _ in range(n+1)]
for i in range(n+1):
    DP[i][0]=1
for i in range(m+1):
    DP[0][i]=1
for i,s in enumerate(S):
    for j,t in enumerate(T):
        if s==t:
            DP[i+1][j+1]=DP[i][j+1]+DP[i+1][j]
        else:
            DP[i+1][j+1]=DP[i][j+1]+DP[i+1][j]-DP[i][j]
        DP[i+1][j+1]%=mod
print(DP[-1][-1])