import numpy as np
N, M = map(int, input().split())
MOD = 10**9+7
s = np.array([int(c) for c in input().split()], dtype=np.int32)
t = np.array([int(c) for c in input().split()], dtype=np.int32)
dp = np.zeros((N+1,M+1), np.int64)
dp[0] = 1
for i in range(N):
  mask = s[i]==t
  dp[i+1,1:][mask] = dp[i,:-1][mask]
  dp[i+1] = (np.cumsum(dp[i+1])+dp[i])%MOD
print(dp[-1,-1]) import numpy as np numpy N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M MOD = 10**9+7 MOD 10**9+7 10**9 10 9 7 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 = np.array([int(c) for c in input().split()], dtype=np.int32) s np.array([int(c) for c in input().split()], dtype=np.int32) np.array np array [int(c) for c in input().split()] dtype=np.int32 dtype np.int32 np int32 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 = np.array([int(c) for c in input().split()], dtype=np.int32) t np.array([int(c) for c in input().split()], dtype=np.int32) np.array np array [int(c) for c in input().split()] dtype=np.int32 dtype np.int32 np int32 dp = np.zeros((N+1,M+1), np.int64) dp np.zeros((N+1,M+1), np.int64) np.zeros np zeros (N+1,M+1) N+1 N 1 M+1 M 1 np.int64 np int64 dp[0] = 1 dp[0] dp 0 1 for i in range(N):
  mask = s[i]==t
  dp[i+1,1:][mask] = dp[i,:-1][mask]
  dp[i+1] = (np.cumsum(dp[i+1])+dp[i])%MOD i range(N) range N mask = s[i]==t mask s[i]==t s[i] s i t dp[i+1,1:][mask] = dp[i,:-1][mask] dp[i+1,1:][mask] [i+1,1:] dp i+1 i 1 mask dp[i,:-1][mask] [i,:-1] dp i mask dp[i+1] = (np.cumsum(dp[i+1])+dp[i])%MOD dp[i+1] dp i+1 i 1 (np.cumsum(dp[i+1])+dp[i])%MOD np.cumsum(dp[i+1])+dp[i] np.cumsum(dp[i+1]) np.cumsum np cumsum dp[i+1] dp i+1 i 1 dp[i] dp i MOD print(dp[-1,-1]) print dp[-1,-1] dp -1 mask = s[i]==t s[i]==t mask N, M = map(int, input().split()) map(int, input().split()) N M = map(int, input().split()) map(int, input().split()) M s = np.array([int(c) for c in input().split()], dtype=np.int32) np.array([int(c) for c in input().split()], dtype=np.int32) s t = np.array([int(c) for c in input().split()], dtype=np.int32) np.array([int(c) for c in input().split()], dtype=np.int32) t dp = np.zeros((N+1,M+1), np.int64) np.zeros((N+1,M+1), np.int64) dp MOD = 10**9+7 10**9+7 MOD
import numpy as np
N, M = map(int, input().split())
MOD = 10**9+7
s = np.array([int(c) for c in input().split()], dtype=np.int32)
t = np.array([int(c) for c in input().split()], dtype=np.int32)
dp = np.zeros((N+1,M+1), np.int64)
dp[0] = 1
for i in range(N):
  mask = s[i]==t
  dp[i+1,1:][mask] = dp[i,:-1][mask]
  dp[i+1] = (np.cumsum(dp[i+1])+dp[i])%MOD
print(dp[-1,-1])