n, m = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))
dp = [[0] * (m + 1) for _ in range(n + 1)]
sum = [[0] * (m + 1) for _ in range(n + 1)]
MOD = 10 ** 9 + 7

ans = 0
for i in range(n):
  for j in range(m):
    if s[i] == t[j]:
      dp[i + 1][j + 1] = (sum[i][j] + 1) % MOD
    else:
      dp[i + 1][j + 1] = 0
    sum[i + 1][j + 1] = (sum[i][j + 1] + sum[i + 1][j] 
                       - sum[i][j] + dp[i + 1][j + 1]) % MOD
    ans += dp[i + 1][j + 1]
    ans %= MOD
print((ans + 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 [0] * (m + 1) for _ in range(n + 1) for _ in range(n + 1) _ range(n + 1) range n + 1 n 1 for _ in range(n + 1) [0] * (m + 1) [0] 0 m + 1 m 1 dp = [[0] * (m + 1) for _ in range(n + 1)] dp [[0] * (m + 1) for _ in range(n + 1)] [0] * (m + 1) for _ in range(n + 1) for _ in range(n + 1) _ range(n + 1) range n + 1 n 1 for _ in range(n + 1) [0] * (m + 1) [0] 0 m + 1 m 1 sum = [[0] * (m + 1) for _ in range(n + 1)] sum [[0] * (m + 1) for _ in range(n + 1)] MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 ans = 0 ans 0 for i in range(n):
  for j in range(m):
    if s[i] == t[j]:
      dp[i + 1][j + 1] = (sum[i][j] + 1) % MOD
    else:
      dp[i + 1][j + 1] = 0
    sum[i + 1][j + 1] = (sum[i][j + 1] + sum[i + 1][j] 
                       - sum[i][j] + dp[i + 1][j + 1]) % MOD
    ans += dp[i + 1][j + 1]
    ans %= MOD i range(n) range n for j in range(m):
    if s[i] == t[j]:
      dp[i + 1][j + 1] = (sum[i][j] + 1) % MOD
    else:
      dp[i + 1][j + 1] = 0
    sum[i + 1][j + 1] = (sum[i][j + 1] + sum[i + 1][j] 
                       - sum[i][j] + dp[i + 1][j + 1]) % MOD
    ans += dp[i + 1][j + 1]
    ans %= MOD j range(m) range m if s[i] == t[j]:
      dp[i + 1][j + 1] = (sum[i][j] + 1) % MOD
    else:
      dp[i + 1][j + 1] = 0
     s[i] == t[j] s[i] s i t[j] t j dp[i + 1][j + 1] = (sum[i][j] + 1) % MOD dp[i + 1][j + 1] [i + 1] dp i + 1 i 1 j + 1 j 1 (sum[i][j] + 1) % MOD sum[i][j] + 1 sum[i][j] [i] sum i j 1 MOD dp[i + 1][j + 1] = 0 dp[i + 1][j + 1] [i + 1] dp i + 1 i 1 j + 1 j 1 0 sum[i + 1][j + 1] = (sum[i][j + 1] + sum[i + 1][j] 
                       - sum[i][j] + dp[i + 1][j + 1]) % MOD sum[i + 1][j + 1] [i + 1] sum i + 1 i 1 j + 1 j 1 (sum[i][j + 1] + sum[i + 1][j] 
                       - sum[i][j] + dp[i + 1][j + 1]) % MOD sum[i][j + 1] + sum[i + 1][j] 
                       - sum[i][j] + dp[i + 1][j + 1] sum[i][j + 1] + sum[i + 1][j] 
                       - sum[i][j] sum[i][j + 1] + sum[i + 1][j] sum[i][j + 1] [i] sum i j + 1 j 1 sum[i + 1][j] [i + 1] sum i + 1 i 1 j sum[i][j] [i] sum i j dp[i + 1][j + 1] [i + 1] dp i + 1 i 1 j + 1 j 1 MOD ans += dp[i + 1][j + 1] ans dp[i + 1][j + 1] [i + 1] dp i + 1 i 1 j + 1 j 1 ans %= MOD ans MOD print((ans + 1) % MOD) print (ans + 1) % MOD ans + 1 ans 1 MOD MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD ans += dp[i + 1][j + 1] dp[i + 1][j + 1] ans ans %= MOD MOD ans m = map(int, input().split()) map(int, input().split()) m s = list(map(int, input().split())) list(map(int, input().split())) s t = list(map(int, input().split())) list(map(int, input().split())) t ans = 0 0 ans sum = [[0] * (m + 1) for _ in range(n + 1)] [[0] * (m + 1) for _ in range(n + 1)] sum dp = [[0] * (m + 1) for _ in range(n + 1)] [[0] * (m + 1) for _ in range(n + 1)] dp n, m = map(int, input().split()) map(int, input().split()) n
n, m = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))
dp = [[0] * (m + 1) for _ in range(n + 1)]
sum = [[0] * (m + 1) for _ in range(n + 1)]
MOD = 10 ** 9 + 7

ans = 0
for i in range(n):
  for j in range(m):
    if s[i] == t[j]:
      dp[i + 1][j + 1] = (sum[i][j] + 1) % MOD
    else:
      dp[i + 1][j + 1] = 0
    sum[i + 1][j + 1] = (sum[i][j + 1] + sum[i + 1][j] 
                       - sum[i][j] + dp[i + 1][j + 1]) % MOD
    ans += dp[i + 1][j + 1]
    ans %= MOD
print((ans + 1) % MOD)
