from numpy import array, ones

mod = 10 ** 9 + 7

N, M, *ST = map(int, open(0).read().split())
S, T = ST[:N], array(ST[N:])

dp = ones(M + 1, dtype="int64")
for s in S:
    dp[1:] = ((dp[:-1] * (s == T)).cumsum() + dp[1:]) % mod

print(dp[-1]) from numpy import array, ones mod = 10 ** 9 + 7 mod 10 ** 9 + 7 10 ** 9 10 9 7 N, M, *ST = map(int, open(0).read().split()) N map(int, open(0).read().split()) map int open(0).read().split() (0).read().split (0).read() (0).read (0) open 0 read split M *ST ST S, T = ST[:N], array(ST[N:]) S ST[:N] ST :N N T array(ST[N:]) array ST[N:] ST N: N dp = ones(M + 1, dtype="int64") dp ones(M + 1, dtype="int64") ones M + 1 M 1 dtype="int64" dtype "int64" for s in S:
    dp[1:] = ((dp[:-1] * (s == T)).cumsum() + dp[1:]) % mod s S dp[1:] = ((dp[:-1] * (s == T)).cumsum() + dp[1:]) % mod dp[1:] dp 1: 1 ((dp[:-1] * (s == T)).cumsum() + dp[1:]) % mod (dp[:-1] * (s == T)).cumsum() + dp[1:] (dp[:-1] * (s == T)).cumsum() dp[:-1] * (s == T)).cumsum dp[:-1] * (s == T) dp[:-1] dp :-1 -1 s == T s T cumsum dp[1:] dp 1: 1 mod print(dp[-1]) print dp[-1] dp -1 S, T = ST[:N], array(ST[N:]) ST[:N] S dp = ones(M + 1, dtype="int64") ones(M + 1, dtype="int64") dp mod = 10 ** 9 + 7 10 ** 9 + 7 mod N, M, *ST = map(int, open(0).read().split()) map(int, open(0).read().split()) N T = ST[:N], array(ST[N:]) array(ST[N:]) T M, *ST = map(int, open(0).read().split()) map(int, open(0).read().split()) M
from numpy import array, ones

mod = 10 ** 9 + 7

N, M, *ST = map(int, open(0).read().split())
S, T = ST[:N], array(ST[N:])

dp = ones(M + 1, dtype="int64")
for s in S:
    dp[1:] = ((dp[:-1] * (s == T)).cumsum() + dp[1:]) % mod

print(dp[-1])