N,M=map(int,input().split())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
mod=10**9+7
sm=[[ 0 for i in range(M)] for j in range(N)]
s1=0
s2=0
if N>M:
  for i in range(N):
    if t[0]==s[i]:
      a=1
    else:
      a=0
    s1=s1+a
    sm[i][0]=s1
    if i<M:
      if s[0]==t[i]:
        a=1
      else:
        a=0
      s2=s2+a
      sm[0][i]=s2
else:
  for i in range(M):
    if s[0]==t[i]:
      a=1
    else:
      a=0
    s2=s2+a
    sm[0][i]=s2
    if i<N:
      if t[0]==s[i]:
        a=1
      else:
        a=0
      s1=s1+a
      sm[i][0]=s1
for i in range(1,N):
  for j in range(1,M):
    if s[i] != t[j]:
      sm[i][j]=(sm[i-1][j]+sm[i][j-1]-sm[i-1][j-1])%mod
    else:
      sm[i][j]=(sm[i-1][j]+sm[i][j-1]-sm[i-1][j-1]+sm[i-1][j-1]+1)%mod
ans=(sm[N-1][M-1]+1)%mod
print(ans) 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 for i in range(M)] for j in range(N) for j in range(N) j range(N) range N for j in range(N) [ 0 for i in range(M)] sm=[[ 0 for i in range(M)] for j in range(N)] sm [[ 0 for i in range(M)] for j in range(N)] s1=0 s1 0 s2=0 s2 0 if N>M:
  for i in range(N):
    if t[0]==s[i]:
      a=1
    else:
      a=0
    s1=s1+a
    sm[i][0]=s1
    if i<M:
      if s[0]==t[i]:
        a=1
      else:
        a=0
      s2=s2+a
      sm[0][i]=s2
else:
  for i in range(M):
    if s[0]==t[i]:
      a=1
    else:
      a=0
    s2=s2+a
    sm[0][i]=s2
    if i<N:
      if t[0]==s[i]:
        a=1
      else:
        a=0
      s1=s1+a
      sm[i][0]=s1 N>M N M for i in range(N):
    if t[0]==s[i]:
      a=1
    else:
      a=0
    s1=s1+a
    sm[i][0]=s1
    if i<M:
      if s[0]==t[i]:
        a=1
      else:
        a=0
      s2=s2+a
      sm[0][i]=s2 i range(N) range N if t[0]==s[i]:
      a=1
    else:
      a=0
     t[0]==s[i] t[0] t 0 s[i] s i a=1 a 1 a=0 a 0 s1=s1+a s1 s1+a s1 a sm[i][0]=s1 sm[i][0] [i] sm i 0 s1 if i<M:
      if s[0]==t[i]:
        a=1
      else:
        a=0
      s2=s2+a
      sm[0][i]=s2 i<M i M if s[0]==t[i]:
        a=1
      else:
        a=0
       s[0]==t[i] s[0] s 0 t[i] t i a=1 a 1 a=0 a 0 s2=s2+a s2 s2+a s2 a sm[0][i]=s2 sm[0][i] [0] sm 0 i s2 for i in range(M):
    if s[0]==t[i]:
      a=1
    else:
      a=0
    s2=s2+a
    sm[0][i]=s2
    if i<N:
      if t[0]==s[i]:
        a=1
      else:
        a=0
      s1=s1+a
      sm[i][0]=s1 i range(M) range M if s[0]==t[i]:
      a=1
    else:
      a=0
     s[0]==t[i] s[0] s 0 t[i] t i a=1 a 1 a=0 a 0 s2=s2+a s2 s2+a s2 a sm[0][i]=s2 sm[0][i] [0] sm 0 i s2 if i<N:
      if t[0]==s[i]:
        a=1
      else:
        a=0
      s1=s1+a
      sm[i][0]=s1 i<N i N if t[0]==s[i]:
        a=1
      else:
        a=0
       t[0]==s[i] t[0] t 0 s[i] s i a=1 a 1 a=0 a 0 s1=s1+a s1 s1+a s1 a sm[i][0]=s1 sm[i][0] [i] sm i 0 s1 for i in range(1,N):
  for j in range(1,M):
    if s[i] != t[j]:
      sm[i][j]=(sm[i-1][j]+sm[i][j-1]-sm[i-1][j-1])%mod
    else:
      sm[i][j]=(sm[i-1][j]+sm[i][j-1]-sm[i-1][j-1]+sm[i-1][j-1]+1)%mod i range(1,N) range 1 N for j in range(1,M):
    if s[i] != t[j]:
      sm[i][j]=(sm[i-1][j]+sm[i][j-1]-sm[i-1][j-1])%mod
    else:
      sm[i][j]=(sm[i-1][j]+sm[i][j-1]-sm[i-1][j-1]+sm[i-1][j-1]+1)%mod j range(1,M) range 1 M if s[i] != t[j]:
      sm[i][j]=(sm[i-1][j]+sm[i][j-1]-sm[i-1][j-1])%mod
    else:
      sm[i][j]=(sm[i-1][j]+sm[i][j-1]-sm[i-1][j-1]+sm[i-1][j-1]+1)%mod s[i] != t[j] s[i] s i t[j] t j sm[i][j]=(sm[i-1][j]+sm[i][j-1]-sm[i-1][j-1])%mod sm[i][j] [i] sm i j (sm[i-1][j]+sm[i][j-1]-sm[i-1][j-1])%mod sm[i-1][j]+sm[i][j-1]-sm[i-1][j-1] sm[i-1][j]+sm[i][j-1] sm[i-1][j] [i-1] sm i-1 i 1 j sm[i][j-1] [i] sm i j-1 j 1 sm[i-1][j-1] [i-1] sm i-1 i 1 j-1 j 1 mod sm[i][j]=(sm[i-1][j]+sm[i][j-1]-sm[i-1][j-1]+sm[i-1][j-1]+1)%mod sm[i][j] [i] sm i j (sm[i-1][j]+sm[i][j-1]-sm[i-1][j-1]+sm[i-1][j-1]+1)%mod sm[i-1][j]+sm[i][j-1]-sm[i-1][j-1]+sm[i-1][j-1]+1 sm[i-1][j]+sm[i][j-1]-sm[i-1][j-1]+sm[i-1][j-1] sm[i-1][j]+sm[i][j-1]-sm[i-1][j-1] sm[i-1][j]+sm[i][j-1] sm[i-1][j] [i-1] sm i-1 i 1 j sm[i][j-1] [i] sm i j-1 j 1 sm[i-1][j-1] [i-1] sm i-1 i 1 j-1 j 1 sm[i-1][j-1] [i-1] sm i-1 i 1 j-1 j 1 1 mod ans=(sm[N-1][M-1]+1)%mod ans (sm[N-1][M-1]+1)%mod sm[N-1][M-1]+1 sm[N-1][M-1] [N-1] sm N-1 N 1 M-1 M 1 1 mod print(ans) print ans s1=0 0 s1 s2=s2+a s2+a s2 s1=s1+a s1+a s1 a=0 0 a a=1 1 a a=1 1 a M=map(int,input().split()) map(int,input().split()) M sm=[[ 0 for i in range(M)] for j in range(N)] [[ 0 for i in range(M)] for j in range(N)] sm t=list(map(int,input().split())) list(map(int,input().split())) t mod=10**9+7 10**9+7 mod a=0 0 a ans=(sm[N-1][M-1]+1)%mod (sm[N-1][M-1]+1)%mod ans a=0 0 a s1=s1+a s1+a s1 s=list(map(int,input().split())) list(map(int,input().split())) s s2=0 0 s2 a=0 0 a a=1 1 a s2=s2+a s2+a s2 a=1 1 a N,M=map(int,input().split()) map(int,input().split()) N
N,M=map(int,input().split())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
mod=10**9+7
sm=[[ 0 for i in range(M)] for j in range(N)]
s1=0
s2=0
if N>M:
  for i in range(N):
    if t[0]==s[i]:
      a=1
    else:
      a=0
    s1=s1+a
    sm[i][0]=s1
    if i<M:
      if s[0]==t[i]:
        a=1
      else:
        a=0
      s2=s2+a
      sm[0][i]=s2
else:
  for i in range(M):
    if s[0]==t[i]:
      a=1
    else:
      a=0
    s2=s2+a
    sm[0][i]=s2
    if i<N:
      if t[0]==s[i]:
        a=1
      else:
        a=0
      s1=s1+a
      sm[i][0]=s1
for i in range(1,N):
  for j in range(1,M):
    if s[i] != t[j]:
      sm[i][j]=(sm[i-1][j]+sm[i][j-1]-sm[i-1][j-1])%mod
    else:
      sm[i][j]=(sm[i-1][j]+sm[i][j-1]-sm[i-1][j-1]+sm[i-1][j-1]+1)%mod
ans=(sm[N-1][M-1]+1)%mod
print(ans)