import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

MOD = 10 ** 9 + 7
N, M = list(map(int, sys.stdin.readline().split()))
S = list(map(int, sys.stdin.readline().split()))
T = list(map(int, sys.stdin.readline().split()))
S = np.array([-1] + S)
T = np.array([-1] + T)

# # dp[i][j]: S[i] と T[j] で終わる組み合わせの数
# # S[i] != T[j] のとき 0
# # S[i] == T[j] のとき、sum(dp[:i][:j])
# dp = np.zeros((len(S), len(T)), dtype=int)
# dp[0][0] = 1
# # dp の二次元累積和
# cumsum = np.ones(len(T), dtype=int)
# for i in range(1, len(S)):
#     for j in range(1, len(T)):
#         if S[i] != T[j]:
#             continue
#         # dp[i][j] = dp[:i, :j].sum() % MOD
#         dp[i][j] = cumsum[j - 1] % MOD
#     cumsum += dp[i].cumsum()
#     cumsum %= MOD
# print(cumsum[-1])


cumsum = np.ones(len(T), dtype=int)
for i in range(1, len(S)):
    cumsum[1:] += ((T == S[i])[1:] * cumsum[:-1] % MOD).cumsum()
    cumsum %= MOD
print(cumsum[-1]) import os os import sys sys import numpy as np numpy if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r") os.getenv("LOCAL") os.getenv os getenv "LOCAL" sys.stdin = open("_in.txt", "r") sys.stdin sys stdin open("_in.txt", "r") open "_in.txt" "r" sys.setrecursionlimit(2147483647) sys.setrecursionlimit sys setrecursionlimit 2147483647 INF = float("inf") INF float("inf") float "inf" MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 N, M = list(map(int, sys.stdin.readline().split())) N list(map(int, sys.stdin.readline().split())) list map(int, sys.stdin.readline().split()) map int sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split M S = list(map(int, sys.stdin.readline().split())) S list(map(int, sys.stdin.readline().split())) list map(int, sys.stdin.readline().split()) map int sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split T = list(map(int, sys.stdin.readline().split())) T list(map(int, sys.stdin.readline().split())) list map(int, sys.stdin.readline().split()) map int sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split S = np.array([-1] + S) S np.array([-1] + S) np.array np array [-1] + S [-1] -1 S T = np.array([-1] + T) T np.array([-1] + T) np.array np array [-1] + T [-1] -1 T cumsum = np.ones(len(T), dtype=int) cumsum np.ones(len(T), dtype=int) np.ones np ones len(T) len T dtype=int dtype int for i in range(1, len(S)):
    cumsum[1:] += ((T == S[i])[1:] * cumsum[:-1] % MOD).cumsum()
    cumsum %= MOD i range(1, len(S)) range 1 len(S) len S cumsum[1:] += ((T == S[i])[1:] * cumsum[:-1] % MOD).cumsum() cumsum[1:] cumsum 1: 1 ((T == S[i])[1:] * cumsum[:-1] % MOD).cumsum() (T == S[i])[1:] * cumsum[:-1] % MOD).cumsum (T == S[i])[1:] * cumsum[:-1] % MOD (T == S[i])[1:] * cumsum[:-1] (T == S[i])[1:] T == S[i] T S[i] S i 1: 1 cumsum[:-1] cumsum :-1 -1 MOD cumsum cumsum %= MOD cumsum MOD print(cumsum[-1]) print cumsum[-1] cumsum -1 S = list(map(int, sys.stdin.readline().split())) list(map(int, sys.stdin.readline().split())) S T = np.array([-1] + T) np.array([-1] + T) T cumsum = np.ones(len(T), dtype=int) np.ones(len(T), dtype=int) cumsum M = list(map(int, sys.stdin.readline().split())) list(map(int, sys.stdin.readline().split())) M T = list(map(int, sys.stdin.readline().split())) list(map(int, sys.stdin.readline().split())) T S = np.array([-1] + S) np.array([-1] + S) S cumsum %= MOD MOD cumsum INF = float("inf") float("inf") INF MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD N, M = list(map(int, sys.stdin.readline().split())) list(map(int, sys.stdin.readline().split())) N
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

MOD = 10 ** 9 + 7
N, M = list(map(int, sys.stdin.readline().split()))
S = list(map(int, sys.stdin.readline().split()))
T = list(map(int, sys.stdin.readline().split()))
S = np.array([-1] + S)
T = np.array([-1] + T)

# # dp[i][j]: S[i] と T[j] で終わる組み合わせの数
# # S[i] != T[j] のとき 0
# # S[i] == T[j] のとき、sum(dp[:i][:j])
# dp = np.zeros((len(S), len(T)), dtype=int)
# dp[0][0] = 1
# # dp の二次元累積和
# cumsum = np.ones(len(T), dtype=int)
# for i in range(1, len(S)):
#     for j in range(1, len(T)):
#         if S[i] != T[j]:
#             continue
#         # dp[i][j] = dp[:i, :j].sum() % MOD
#         dp[i][j] = cumsum[j - 1] % MOD
#     cumsum += dp[i].cumsum()
#     cumsum %= MOD
# print(cumsum[-1])


cumsum = np.ones(len(T), dtype=int)
for i in range(1, len(S)):
    cumsum[1:] += ((T == S[i])[1:] * cumsum[:-1] % MOD).cumsum()
    cumsum %= MOD
print(cumsum[-1])
