N, M = map(int, input().split())
S = [int(x) for x in input().split()]
T = [int(x) for x in input().split()]
p = 10 ** 9 + 7
DP = [[0 for _ in range(M + 1)] for _ in range(N + 1)]
for i in range(N + 1):
  DP[i][0] = 1
for j in range(M + 1):
  DP[0][j] = 1
for i in range(N):
  for j in range(M):
    DP[i + 1][j + 1] = DP[i + 1][j] + DP[i][j + 1] - DP[i][j]
    if S[i] == T[j]:
      DP[i + 1][j + 1] += DP[i][j]
    DP[i + 1][j + 1] %= p
  print(DP[i])
print(DP[N])
print(DP[N][M])