N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
dp = [1] * (M+1)
acc = [0] * (M)
MOD = 10 ** 9 + 7
for s in S:
  ndp = [1]
  for i, t in enumerate(T):
    if s == t:
      ndp.append(ndp[-1] + dp[i+1])
      acc[i] = dp[i+1]
    else:
      ndp.append(ndp[-1] + acc[i])
  dp = ndp
print(dp[-1] % MOD) N, M = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split M S = list(map(int, input().split())) S list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split T = list(map(int, input().split())) T list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split dp = [1] * (M+1) dp [1] * (M+1) [1] 1 M+1 M 1 acc = [0] * (M) acc [0] * (M) [0] 0 M MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 for s in S:
  ndp = [1]
  for i, t in enumerate(T):
    if s == t:
      ndp.append(ndp[-1] + dp[i+1])
      acc[i] = dp[i+1]
    else:
      ndp.append(ndp[-1] + acc[i])
  dp = ndp s S ndp = [1] ndp [1] 1 for i, t in enumerate(T):
    if s == t:
      ndp.append(ndp[-1] + dp[i+1])
      acc[i] = dp[i+1]
    else:
      ndp.append(ndp[-1] + acc[i])
   i t enumerate(T) enumerate T if s == t:
      ndp.append(ndp[-1] + dp[i+1])
      acc[i] = dp[i+1]
    else:
      ndp.append(ndp[-1] + acc[i])
   s == t s t ndp.append(ndp[-1] + dp[i+1]) ndp.append ndp append ndp[-1] + dp[i+1] ndp[-1] ndp -1 dp[i+1] dp i+1 i 1 acc[i] = dp[i+1] acc[i] acc i dp[i+1] dp i+1 i 1 ndp.append(ndp[-1] + acc[i]) ndp.append ndp append ndp[-1] + acc[i] ndp[-1] ndp -1 acc[i] acc i dp = ndp dp ndp print(dp[-1] % MOD) print dp[-1] % MOD dp[-1] dp -1 MOD T = list(map(int, input().split())) list(map(int, input().split())) T acc = [0] * (M) [0] * (M) acc dp = ndp ndp dp MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD M = map(int, input().split()) map(int, input().split()) M dp = [1] * (M+1) [1] * (M+1) dp N, M = map(int, input().split()) map(int, input().split()) N S = list(map(int, input().split())) list(map(int, input().split())) S ndp = [1] [1] ndp
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
dp = [1] * (M+1)
acc = [0] * (M)
MOD = 10 ** 9 + 7
for s in S:
  ndp = [1]
  for i, t in enumerate(T):
    if s == t:
      ndp.append(ndp[-1] + dp[i+1])
      acc[i] = dp[i+1]
    else:
      ndp.append(ndp[-1] + acc[i])
  dp = ndp
print(dp[-1] % MOD)