M = int(1e+9 + 7)


def main():
  input()
  s = list(map(int, input().split()))
  t = list(map(int, input().split()))
  z = [0] * len(t)

  for v in s:
    c = 0

    for i, w in enumerate(t):
      y = z[i]

      if v == w:
        z[i] = (z[i] + c + 1) % M

      c = (c + y) % M

  y = 0

  for v in z:
    y = (y + v) % M

  y = (y + 1) % M

  print(y)


if __name__ == '__main__':
  main() M = int(1e+9 + 7) M int(1e+9 + 7) int 1e+9 + 7 1e+9 7 def main():
  input()
  s = list(map(int, input().split()))
  t = list(map(int, input().split()))
  z = [0] * len(t)

  for v in s:
    c = 0

    for i, w in enumerate(t):
      y = z[i]

      if v == w:
        z[i] = (z[i] + c + 1) % M

      c = (c + y) % M

  y = 0

  for v in z:
    y = (y + v) % M

  y = (y + 1) % M

  print(y) main input() input 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 z = [0] * len(t) z [0] * len(t) [0] 0 len(t) len t for v in s:
    c = 0

    for i, w in enumerate(t):
      y = z[i]

      if v == w:
        z[i] = (z[i] + c + 1) % M

      c = (c + y) % M

   v s c = 0 c 0 for i, w in enumerate(t):
      y = z[i]

      if v == w:
        z[i] = (z[i] + c + 1) % M

      c = (c + y) % M

   i w enumerate(t) enumerate t y = z[i] y z[i] z i if v == w:
        z[i] = (z[i] + c + 1) % M

       v == w v w z[i] = (z[i] + c + 1) % M z[i] z i (z[i] + c + 1) % M z[i] + c + 1 z[i] + c z[i] z i c 1 M c = (c + y) % M c (c + y) % M c + y c y M y = 0 y 0 for v in z:
    y = (y + v) % M

   v z y = (y + v) % M y (y + v) % M y + v y v M y = (y + 1) % M y (y + 1) % M y + 1 y 1 M print(y) print y if __name__ == '__main__':
  main() __name__ == '__main__' __name__ '__main__' main() main def main():
  input()
  s = list(map(int, input().split()))
  t = list(map(int, input().split()))
  z = [0] * len(t)

  for v in s:
    c = 0

    for i, w in enumerate(t):
      y = z[i]

      if v == w:
        z[i] = (z[i] + c + 1) % M

      c = (c + y) % M

  y = 0

  for v in z:
    y = (y + v) % M

  y = (y + 1) % M

  print(y) def main():
  input()
  s = list(map(int, input().split()))
  t = list(map(int, input().split()))
  z = [0] * len(t)

  for v in s:
    c = 0

    for i, w in enumerate(t):
      y = z[i]

      if v == w:
        z[i] = (z[i] + c + 1) % M

      c = (c + y) % M

  y = 0

  for v in z:
    y = (y + v) % M

  y = (y + 1) % M

  print(y) main M = int(1e+9 + 7) int(1e+9 + 7) M
M = int(1e+9 + 7)


def main():
  input()
  s = list(map(int, input().split()))
  t = list(map(int, input().split()))
  z = [0] * len(t)

  for v in s:
    c = 0

    for i, w in enumerate(t):
      y = z[i]

      if v == w:
        z[i] = (z[i] + c + 1) % M

      c = (c + y) % M

  y = 0

  for v in z:
    y = (y + v) % M

  y = (y + 1) % M

  print(y)


if __name__ == '__main__':
  main()
