Buggy python submission (verdict: Time Limit Exceeded):
def prepare(n, MOD):

    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv

    return factorials, invs


k = int(input())
s = input()
length = len(s)
MOD = 10**9 + 7

fact, inv = prepare(k + length, MOD)

ans = 0

for i in range(length, length + k + 1):
    coef = fact[i - 1] * inv[i - length] * inv[length - 1] % MOD
    ans += coef * pow(25, i - length, MOD) * pow(26, length + k - i, MOD) % MOD

print(ans % MOD)

Fixed submission:
def solve(k, length, MOD, div, dp):
    for i in range(1, k + 1):
        dp[0] = dp[0] * 25 * div * (length + i - 1) * pow(i, -1, MOD) % MOD
        dp[1] = (dp[1] + dp[0]) % MOD

    return(dp[1])


k = int(input())
s = input()
length = len(s)
MOD = 10**9 + 7
div = pow(26, -1, MOD)

dp = [pow(26, k, MOD)] * 2

print(solve(k, length, MOD, div, dp))

Buggy python submission (verdict: Time Limit Exceeded):
def prepare(n, MOD):

    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv

    return factorials, invs


k = int(input())
s = input()
length = len(s)
MOD = 10**9 + 7

fact, inv = prepare(k + length, MOD)

ans = 0

for i in range(length, length + k + 1):
    coef = fact[i - 1] * inv[i - length] * inv[length - 1]
    ans += coef * pow(25, i - length, MOD) * pow(26, length + k - i, MOD) % MOD

print(ans % MOD)

Fixed submission:
def solve(k, length, MOD, div, dp):
    for i in range(1, k + 1):
        dp[0] = dp[0] * 25 * div * (length + i - 1) * pow(i, -1, MOD) % MOD
        dp[1] = (dp[1] + dp[0]) % MOD

    return(dp[1])


k = int(input())
s = input()
length = len(s)
MOD = 10**9 + 7
div = pow(26, -1, MOD)

dp = [pow(26, k, MOD)] * 2

print(solve(k, length, MOD, div, dp))

Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce


def ccnt(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


k = int(input())
s = input()
length = len(s)
MOD = 10**9 + 7

ans = 0

for i in range(length, length + k + 1):
    ans += ccnt(i - 1, length - 1) * pow(25, i - length, MOD) * pow(26, length + k - i, MOD) % MOD

print(ans % MOD)

Fixed submission:
def solve(k, length, MOD, div, dp):
    for i in range(1, k + 1):
        dp[0] = dp[0] * 25 * div * (length + i - 1) * pow(i, -1, MOD) % MOD
        dp[1] = (dp[1] + dp[0]) % MOD

    return(dp[1])


k = int(input())
s = input()
length = len(s)
MOD = 10**9 + 7
div = pow(26, -1, MOD)

dp = [pow(26, k, MOD)] * 2

print(solve(k, length, MOD, div, dp))

Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce


def ccnt(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


k = int(input())
s = input()
length = len(s)
MOD = 10**9 + 7

ans = 0

for i in range(length, length + k + 1):
    ans += ccnt(i - 1, length - 1) * pow(25, i - length, MOD) * pow(26, length + k - i, MOD) % MOD

print(ans % MOD)

Fixed submission:
def solve(k, length, MOD, div, dp):
    for i in range(1, k + 1):
        dp[0] = dp[0] * 25 * div * (length + i - 1) * pow(i, -1, MOD) % MOD
        dp[1] = (dp[1] + dp[0]) % MOD

    return(dp[1])


k = int(input())
s = input()
length = len(s)
MOD = 10**9 + 7
div = pow(26, -1, MOD)

dp = [pow(26, k, MOD)] * 2

print(solve(k, length, MOD, div, dp))

Buggy python submission (verdict: Runtime Error):
k = int(input())
s = input()

length = len(s)
MOD = 10**9 + 7

dp = [[0] * (k + 1) for _ in range(2)]
dp[0][0] = pow(26, k, MOD)
dp[1][0] = pow(26, k, MOD)

div = pow(26, -1, MOD)

for i in range(1, k + 1):
    dp[0][i] = dp[0][i - 1] * 25 * div * (length + i - 1) * pow(i, -1, MOD) % MOD
    dp[1][i] = (dp[1][i - 1] + dp[0][i]) % MOD

print(dp[-1][-1])

Fixed submission:
def solve(k, length, MOD, div, dp):
    for i in range(1, k + 1):
        dp[0] = dp[0] * 25 * div * (length + i - 1) * pow(i, -1, MOD) % MOD
        dp[1] = (dp[1] + dp[0]) % MOD

    return(dp[1])


k = int(input())
s = input()
length = len(s)
MOD = 10**9 + 7
div = pow(26, -1, MOD)

dp = [pow(26, k, MOD)] * 2

print(solve(k, length, MOD, div, dp))

Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
s = input()

length = len(s)
MOD = 10**9 + 7

dp = [[0] * (k + 1) for _ in range(2)]
dp[0][0] = pow(26, k, MOD)
dp[1][0] = pow(26, k, MOD)

div = pow(26, -1, MOD)

for i in range(1, k + 1):
    dp[0][i] = dp[0][i - 1] * 25 * div * (length + i - 1) * pow(i, -1, MOD) % MOD
    dp[1][i] = (dp[1][i - 1] + dp[0][i]) % MOD

print(dp[-1][-1])

Fixed submission:
def solve(k, length, MOD, div, dp):
    for i in range(1, k + 1):
        dp[0] = dp[0] * 25 * div * (length + i - 1) * pow(i, -1, MOD) % MOD
        dp[1] = (dp[1] + dp[0]) % MOD

    return(dp[1])


k = int(input())
s = input()
length = len(s)
MOD = 10**9 + 7
div = pow(26, -1, MOD)

dp = [pow(26, k, MOD)] * 2

print(solve(k, length, MOD, div, dp))