output_description: Print the number of pairs of a subsequence of S and a subsequence of T such
  that the subsequences are the same in content, modulo 10^9+7.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N M
      S_1 S_2 ... S_{N-1} S_{N}
      T_1 T_2 ... T_{M-1} T_{M}
attempt: 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])
  
problem_description: Statement
  
  You are given two integer sequences S and T of length N and M, respectively,
  both consisting of integers between 1 and 10^5 (inclusive).
  
  In how many pairs of a subsequence of S and a subsequence of T do the two
  subsequences are the same in content?
  
  Here the subsequence of A is a sequence obtained by removing zero or more
  elements from A and concatenating the remaining elements without changing the
  order.
  
  For both S and T, we distinguish two subsequences if the sets of the indices
  of the removed elements are different, even if the subsequences are the same
  in content.
  
  Since the answer can be tremendous, print the number modulo 10^9+7.
samples: [{"input": "2 2\n    1 3\n    3 1", "output": "3\n    \n\nS has four subsequences: (), (1), (3), (1, 3).\n\nT has four subsequences: (), (3), (1), (3, 1).\n\nThere are 1 \\times 1 pair of subsequences in which the subsequences are both\n(), 1 \\times 1 pair of subsequences in which the subsequences are both (1),\nand 1 \\times 1 pair of subsequences in which the subsequences are both (3),\nfor a total of three pairs.\n\n* * *"}, {"input": "2 2\n    1 1\n    1 1", "output": "6\n    \n\nS has four subsequences: (), (1), (1), (1, 1).\n\nT has four subsequences: (), (1), (1), (1, 1).\n\nThere are 1 \\times 1 pair of subsequences in which the subsequences are both\n(), 2 \\times 2 pairs of subsequences in which the subsequences are both (1),\nand 1 \\times 1 pair of subsequences in which the subsequences are both (1,1),\nfor a total of six pairs. Note again that we distinguish two subsequences if\nthe sets of the indices of the removed elements are different, even if the\nsubsequences are the same in content.\n\n* * *"}, {"input": "4 4\n    3 4 5 6\n    3 4 5 6", "output": "16\n    \n\n* * *"}, {"input": "10 9\n    9 6 5 7 5 9 8 5 6 7\n    8 6 8 5 5 7 9 9 7", "output": "191\n    \n\n* * *"}, {"input": "20 20\n    1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n    1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "846527861\n    \n\nBe sure to print the number modulo 10^9+7."}]