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