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