import numpy as np
MOD = 10**9 + 7
N,M = map(int,input().split())
S = np.array(input().split(), dtype=np.int32)
T = np.array(input().split(), dtype=np.int32)

# (n,m) 以前で作れている列
dp = np.ones(M+1, dtype = np.int64)

for n in range(N):
  dp[1:] = ((dp[:-1] * (T == S[n])).cumsum() + dp[1:]) % MOD # cumsumに直す

answer = dp[M]
print(answer) import numpy as np numpy MOD = 10**9 + 7 MOD 10**9 + 7 10**9 10 9 7 N,M = map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M S = np.array(input().split(), dtype=np.int32) S np.array(input().split(), dtype=np.int32) np.array np array input().split() ().split () input split dtype=np.int32 dtype np.int32 np int32 T = np.array(input().split(), dtype=np.int32) T np.array(input().split(), dtype=np.int32) np.array np array input().split() ().split () input split dtype=np.int32 dtype np.int32 np int32 dp = np.ones(M+1, dtype = np.int64) dp np.ones(M+1, dtype = np.int64) np.ones np ones M+1 M 1 dtype = np.int64 dtype np.int64 np int64 for n in range(N):
  dp[1:] = ((dp[:-1] * (T == S[n])).cumsum() + dp[1:]) % MOD # cumsumに直す n range(N) range N dp[1:] = ((dp[:-1] * (T == S[n])).cumsum() + dp[1:]) % MOD dp[1:] dp 1: 1 ((dp[:-1] * (T == S[n])).cumsum() + dp[1:]) % MOD (dp[:-1] * (T == S[n])).cumsum() + dp[1:] (dp[:-1] * (T == S[n])).cumsum() dp[:-1] * (T == S[n])).cumsum dp[:-1] * (T == S[n]) dp[:-1] dp :-1 -1 T == S[n] T S[n] S n cumsum dp[1:] dp 1: 1 MOD answer = dp[M] answer dp[M] dp M print(answer) print answer T = np.array(input().split(), dtype=np.int32) np.array(input().split(), dtype=np.int32) T N,M = map(int,input().split()) map(int,input().split()) N dp = np.ones(M+1, dtype = np.int64) np.ones(M+1, dtype = np.int64) dp S = np.array(input().split(), dtype=np.int32) np.array(input().split(), dtype=np.int32) S M = map(int,input().split()) map(int,input().split()) M answer = dp[M] dp[M] answer MOD = 10**9 + 7 10**9 + 7 MOD
import numpy as np
MOD = 10**9 + 7
N,M = map(int,input().split())
S = np.array(input().split(), dtype=np.int32)
T = np.array(input().split(), dtype=np.int32)

# (n,m) 以前で作れている列
dp = np.ones(M+1, dtype = np.int64)

for n in range(N):
  dp[1:] = ((dp[:-1] * (T == S[n])).cumsum() + dp[1:]) % MOD # cumsumに直す

answer = dp[M]
print(answer)