N, M = map(int, input().split())
s = [int(c) for c in input().split()]
t = [int(c) for c in input().split()]
MOD = 10**9+7

dp = [[0]*(M+1) for i in range(N+1)]
dp_cum = [[0]*(M+1) for i in range(N+1)]

dp[0][0] = 1
for i in range(N+1):
  dp_cum[i][0] = 1
for j in range(M+1):
  dp_cum[0][j] = 1
  
for i in range(N):
  for j in range(M):
    if s[i]!=t[j]:
      dp[i+1][j+1] = 0
    else:
      dp[i+1][j+1] = dp_cum[i][j]
    dp_cum[i+1][j+1] = dp_cum[i][j+1] + dp_cum[i+1][j] - dp_cum[i][j] + dp[i+1][j+1]
    dp_cum[i+1][j+1] %= MOD

print(dp_cum[-1][-1]) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M int(c) for c in input().split() for c in input().split() c input().split() ().split () input split for c in input().split() int(c) int c s = [int(c) for c in input().split()] s [int(c) for c in input().split()] int(c) for c in input().split() for c in input().split() c input().split() ().split () input split for c in input().split() int(c) int c t = [int(c) for c in input().split()] t [int(c) for c in 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 dp_cum = [[0]*(M+1) for i in range(N+1)] dp_cum [[0]*(M+1) for i in range(N+1)] dp[0][0] = 1 dp[0][0] [0] dp 0 0 1 for i in range(N+1):
  dp_cum[i][0] = 1 i range(N+1) range N+1 N 1 dp_cum[i][0] = 1 dp_cum[i][0] [i] dp_cum i 0 1 for j in range(M+1):
  dp_cum[0][j] = 1
   j range(M+1) range M+1 M 1 dp_cum[0][j] = 1 dp_cum[0][j] [0] dp_cum 0 j 1 for i in range(N):
  for j in range(M):
    if s[i]!=t[j]:
      dp[i+1][j+1] = 0
    else:
      dp[i+1][j+1] = dp_cum[i][j]
    dp_cum[i+1][j+1] = dp_cum[i][j+1] + dp_cum[i+1][j] - dp_cum[i][j] + dp[i+1][j+1]
    dp_cum[i+1][j+1] %= MOD i range(N) range N for j in range(M):
    if s[i]!=t[j]:
      dp[i+1][j+1] = 0
    else:
      dp[i+1][j+1] = dp_cum[i][j]
    dp_cum[i+1][j+1] = dp_cum[i][j+1] + dp_cum[i+1][j] - dp_cum[i][j] + dp[i+1][j+1]
    dp_cum[i+1][j+1] %= MOD j range(M) range M if s[i]!=t[j]:
      dp[i+1][j+1] = 0
    else:
      dp[i+1][j+1] = dp_cum[i][j]
     s[i]!=t[j] s[i] s i t[j] t j dp[i+1][j+1] = 0 dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 0 dp[i+1][j+1] = dp_cum[i][j] dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 dp_cum[i][j] [i] dp_cum i j dp_cum[i+1][j+1] = dp_cum[i][j+1] + dp_cum[i+1][j] - dp_cum[i][j] + dp[i+1][j+1] dp_cum[i+1][j+1] [i+1] dp_cum i+1 i 1 j+1 j 1 dp_cum[i][j+1] + dp_cum[i+1][j] - dp_cum[i][j] + dp[i+1][j+1] dp_cum[i][j+1] + dp_cum[i+1][j] - dp_cum[i][j] dp_cum[i][j+1] + dp_cum[i+1][j] dp_cum[i][j+1] [i] dp_cum i j+1 j 1 dp_cum[i+1][j] [i+1] dp_cum i+1 i 1 j dp_cum[i][j] [i] dp_cum i j dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 dp_cum[i+1][j+1] %= MOD dp_cum[i+1][j+1] [i+1] dp_cum i+1 i 1 j+1 j 1 MOD print(dp_cum[-1][-1]) print dp_cum[-1][-1] [-1] dp_cum -1 -1 dp = [[0]*(M+1) for i in range(N+1)] [[0]*(M+1) for i in range(N+1)] dp M = map(int, input().split()) map(int, input().split()) M dp_cum = [[0]*(M+1) for i in range(N+1)] [[0]*(M+1) for i in range(N+1)] dp_cum t = [int(c) for c in input().split()] [int(c) for c in input().split()] t MOD = 10**9+7 10**9+7 MOD N, M = map(int, input().split()) map(int, input().split()) N s = [int(c) for c in input().split()] [int(c) for c in input().split()] s
N, M = map(int, input().split())
s = [int(c) for c in input().split()]
t = [int(c) for c in input().split()]
MOD = 10**9+7

dp = [[0]*(M+1) for i in range(N+1)]
dp_cum = [[0]*(M+1) for i in range(N+1)]

dp[0][0] = 1
for i in range(N+1):
  dp_cum[i][0] = 1
for j in range(M+1):
  dp_cum[0][j] = 1
  
for i in range(N):
  for j in range(M):
    if s[i]!=t[j]:
      dp[i+1][j+1] = 0
    else:
      dp[i+1][j+1] = dp_cum[i][j]
    dp_cum[i+1][j+1] = dp_cum[i][j+1] + dp_cum[i+1][j] - dp_cum[i][j] + dp[i+1][j+1]
    dp_cum[i+1][j+1] %= MOD

print(dp_cum[-1][-1])