n,m=map(int,input().split())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
mod=10**9+7
dp=[[0]*(m+1)for i in range(n+1)]
sum=[[0]*(m+1)for i in range(n+1)]
for i in range(1,n+1):
  for j in range(1,m+1):
    if s[i-1]==t[j-1]: dp[i][j]=sum[i-1][j-1]+1
    sum[i][j] = (sum[i][j-1]+sum[i-1][j]-sum[i-1][j-1]+dp[i][j]+mod)%mod
ans=1
for d in dp: 
  for x in d: ans+=x
print(ans%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 mod=10**9+7 mod 10**9+7 10**9 10 9 7 [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 dp=[[0]*(m+1)for i in range(n+1)] dp [[0]*(m+1)for i in range(n+1)] [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 sum=[[0]*(m+1)for i in range(n+1)] sum [[0]*(m+1)for i in range(n+1)] for i in range(1,n+1):
  for j in range(1,m+1):
    if s[i-1]==t[j-1]: dp[i][j]=sum[i-1][j-1]+1
    sum[i][j] = (sum[i][j-1]+sum[i-1][j]-sum[i-1][j-1]+dp[i][j]+mod)%mod i range(1,n+1) range 1 n+1 n 1 for j in range(1,m+1):
    if s[i-1]==t[j-1]: dp[i][j]=sum[i-1][j-1]+1
    sum[i][j] = (sum[i][j-1]+sum[i-1][j]-sum[i-1][j-1]+dp[i][j]+mod)%mod j range(1,m+1) range 1 m+1 m 1 if s[i-1]==t[j-1]: dp[i][j]=sum[i-1][j-1]+1
     s[i-1]==t[j-1] s[i-1] s i-1 i 1 t[j-1] t j-1 j 1 sum[i][j] = (sum[i][j-1]+sum[i-1][j]-sum[i-1][j-1]+dp[i][j]+mod)%mod sum[i][j] [i] sum i j (sum[i][j-1]+sum[i-1][j]-sum[i-1][j-1]+dp[i][j]+mod)%mod sum[i][j-1]+sum[i-1][j]-sum[i-1][j-1]+dp[i][j]+mod sum[i][j-1]+sum[i-1][j]-sum[i-1][j-1]+dp[i][j] sum[i][j-1]+sum[i-1][j]-sum[i-1][j-1] sum[i][j-1]+sum[i-1][j] sum[i][j-1] [i] sum i j-1 j 1 sum[i-1][j] [i-1] sum i-1 i 1 j sum[i-1][j-1] [i-1] sum i-1 i 1 j-1 j 1 dp[i][j] [i] dp i j mod mod ans=1 ans 1 for d in dp: 
  for x in d: ans+=x d dp for x in d: ans+ x d print(ans%mod) print ans%mod ans mod n,m=map(int,input().split()) map(int,input().split()) n t=list(map(int,input().split())) list(map(int,input().split())) t sum=[[0]*(m+1)for i in range(n+1)] [[0]*(m+1)for i in range(n+1)] sum m=map(int,input().split()) map(int,input().split()) m dp=[[0]*(m+1)for i in range(n+1)] [[0]*(m+1)for i in range(n+1)] dp ans=1 1 ans s=list(map(int,input().split())) list(map(int,input().split())) s 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()))
mod=10**9+7
dp=[[0]*(m+1)for i in range(n+1)]
sum=[[0]*(m+1)for i in range(n+1)]
for i in range(1,n+1):
  for j in range(1,m+1):
    if s[i-1]==t[j-1]: dp[i][j]=sum[i-1][j-1]+1
    sum[i][j] = (sum[i][j-1]+sum[i-1][j]-sum[i-1][j-1]+dp[i][j]+mod)%mod
ans=1
for d in dp: 
  for x in d: ans+=x
print(ans%mod)
