Buggy python submission (verdict: Time Limit Exceeded):
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, M = nl()
S = nl()
T = nl()

import numpy as np
dp = np.zeros(M+1, dtype=np.int64)
for i, s in enumerate(S):
    dp2 = np.zeros(M+1, dtype=np.int64)
    dp2[1:] = dp[1:] - dp[:M]
    for j, t in enumerate(T):
        dp2[j+1] += dp2[j]
        if s == t:
            dp2[j+1] += dp[j] + 1
    dp = dp2

print(int(dp[M]+1) % 1000000007)


Fixed submission:
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, M = nl()
S = nl()
T = nl()

dp = [0] * (M+1)
for i, s in enumerate(S):
    dp2 = dp[:]
    for j, t in enumerate(T):
        dp2[j+1] += dp2[j] - dp[j]
        if s == t:
            dp2[j+1] += dp[j] + 1
    dp = dp2

print((dp[M]+1) % 1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, M = nl()
S = nl()
T = nl()

dp = [0] * (M+1)
for i, s in enumerate(S):
    dp2 = dp[:]
    cum = 0
    for j, t in enumerate(T):
        k = dp2[j] - dp[j]
        if s == t:
            k += dp[j] + 1
        dp2[j+1] += k
    dp = dp2

print((dp[M]+1) % 1000000007)


Fixed submission:
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, M = nl()
S = nl()
T = nl()

dp = [0] * (M+1)
for i, s in enumerate(S):
    dp2 = dp[:]
    for j, t in enumerate(T):
        dp2[j+1] += dp2[j] - dp[j]
        if s == t:
            dp2[j+1] += dp[j] + 1
    dp = dp2

print((dp[M]+1) % 1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, M = nl()
S = nl()
T = nl()

dp = [0] * (M+1)
for i, s in enumerate(S):
    dp2 = dp[:]
    for j, t in enumerate(T):
        dp2[j+1] += dp2[j] - dp[j]
        if s == t:
            dp2[j+1] += dp[j] + 1
    dp = dp2

print((dp[M]+1) % 1000000007)


Fixed submission:
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, M = nl()
S = nl()
T = nl()

dp = [0] * (M+1)
for i, s in enumerate(S):
    dp2 = dp[:]
    for j, t in enumerate(T):
        dp2[j+1] += dp2[j] - dp[j]
        if s == t:
            dp2[j+1] += dp[j] + 1
    dp = dp2

print((dp[M]+1) % 1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, M = nl()
S = nl()
T = nl()

import numpy as np
dp = np.zeros((N+1, M+1), dtype=np.int64)

for i, s in enumerate(S):
    dp[i+1, 1:] = dp[i, 1:] - dp[i, :M]
    for j, t in enumerate(T):
        dp[i+1, j+1] += dp[i+1, j]
        if s == t:
            dp[i+1, j+1] += dp[i, j] + 1

print(int(dp[N, M]+1) % 1000000007)


Fixed submission:
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, M = nl()
S = nl()
T = nl()

dp = [0] * (M+1)
for i, s in enumerate(S):
    dp2 = dp[:]
    for j, t in enumerate(T):
        dp2[j+1] += dp2[j] - dp[j]
        if s == t:
            dp2[j+1] += dp[j] + 1
    dp = dp2

print((dp[M]+1) % 1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, M = nl()
S = nl()
T = nl()

import numpy as np
dp = np.zeros((N+1, M+1), dtype=np.uint32)

for i, s in enumerate(S):
    for j, t in enumerate(T):
        dp[i+1, j+1] += dp[i, j+1] + dp[i+1, j] - dp[i, j]
        if s == t:
            dp[i+1, j+1] += dp[i, j] + 1
        dp[i+1, j+1] %= 1000000007

print(int(dp[N, M]+1))


Fixed submission:
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, M = nl()
S = nl()
T = nl()

dp = [0] * (M+1)
for i, s in enumerate(S):
    dp2 = dp[:]
    for j, t in enumerate(T):
        dp2[j+1] += dp2[j] - dp[j]
        if s == t:
            dp2[j+1] += dp[j] + 1
    dp = dp2

print((dp[M]+1) % 1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, M = nl()
S = nl()
T = nl()

import numpy as np
dp = np.zeros((N+1, M+1), dtype=np.uint32)
for i, s in enumerate(S):
    for j, t in enumerate(T):
        dp[i+1, j+1] += dp[i, j+1] + dp[i+1, j]
        if s == t:
            dp[i+1, j+1] += 1
        else:
            dp[i+1, j+1] -= dp[i, j]
        dp[i+1, j+1] %= 1000000007

print(int(dp[N, M]+1))


Fixed submission:
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, M = nl()
S = nl()
T = nl()

dp = [0] * (M+1)
for i, s in enumerate(S):
    dp2 = dp[:]
    for j, t in enumerate(T):
        dp2[j+1] += dp2[j] - dp[j]
        if s == t:
            dp2[j+1] += dp[j] + 1
    dp = dp2

print((dp[M]+1) % 1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, M = nl()
S = nl()
T = nl()

import numpy as np
dp = np.zeros((N+1, M+1), dtype=np.uint32)
for i in range(1, N+1):
    for j in range(1, M+1):
        dp[i, j] += dp[i-1, j] + dp[i, j-1]
        if S[i-1] == T[j-1]:
            dp[i, j] += 1
        else:
            dp[i, j] -= dp[i-1, j-1]
        dp[i, j] %= 1000000007

print(int(dp[N, M]+1))


Fixed submission:
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, M = nl()
S = nl()
T = nl()

dp = [0] * (M+1)
for i, s in enumerate(S):
    dp2 = dp[:]
    for j, t in enumerate(T):
        dp2[j+1] += dp2[j] - dp[j]
        if s == t:
            dp2[j+1] += dp[j] + 1
    dp = dp2

print((dp[M]+1) % 1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, M = nl()
S = nl()
T = nl()

import numpy as np
dp = np.zeros((N+1, M+1), dtype=np.uint64)
for i in range(1, N+1):
    for j in range(1, M+1):
        dp[i, j] = dp[i-1, j] + dp[i, j-1]
        if S[i-1] == T[j-1]:
            dp[i, j] += 1
        else:
            dp[i, j] -= dp[i-1, j-1]
        dp[i, j] %= 1000000007

print(int(dp[N, M]+1))


Fixed submission:
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, M = nl()
S = nl()
T = nl()

dp = [0] * (M+1)
for i, s in enumerate(S):
    dp2 = dp[:]
    for j, t in enumerate(T):
        dp2[j+1] += dp2[j] - dp[j]
        if s == t:
            dp2[j+1] += dp[j] + 1
    dp = dp2

print((dp[M]+1) % 1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, M = nl()
S = nl()
T = nl()

import numpy as np
dp = np.zeros((N+1, M+1), dtype=np.uint64)
for i in range(1, N+1):
    for j in range(1, M+1):
        dp[i, j] = dp[i-1, j] + dp[i, j-1]
        if S[i-1] == T[j-1]:
            dp[i, j] += 1
        else:
            dp[i, j] -= dp[i-1, j-1]

print(int(dp[N, M]+1) % 1000000007)


Fixed submission:
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, M = nl()
S = nl()
T = nl()

dp = [0] * (M+1)
for i, s in enumerate(S):
    dp2 = dp[:]
    for j, t in enumerate(T):
        dp2[j+1] += dp2[j] - dp[j]
        if s == t:
            dp2[j+1] += dp[j] + 1
    dp = dp2

print((dp[M]+1) % 1000000007)