Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
s = input()
L = len(s)
mod = 10**9+7

com = [1]*(k+1)
p25 = [1]*(k+1)
p26 = [1]*(k+1)

for i in range(k):
  com[i+1] = com[i]*(L+i)//(i+1)
  p25[i+1] = p25[i]*25%mod
  p26[i+1] = p26[i]*26%mod

ans = 0
for p in range(k+1):
  chk = com[p]%mod
  chk *= p25[p]%mod
  chk *= p26[k-p]%mod
  ans += chk
  ans %= mod
  
print(ans)

Fixed submission:
k = int(input())
s = input()
L = len(s)
mod = 10**9+7

MAX = 2*10**6
fact = [1]*(MAX+1)
for i in range(1, MAX+1):
    fact[i] = (fact[i-1]*i) % mod

inv = [1]*(MAX+1)
for i in range(2, MAX+1):
    inv[i] = inv[mod % i]*(mod-mod//i) % mod

fact_inv = [1]*(MAX+1)
for i in range(1, MAX+1):
    fact_inv[i] = fact_inv[i-1] * inv[i] % mod

def comb(n, k):
    if n < k:
        return 0
    return fact[n] * fact_inv[n-k] * fact_inv[k] % mod
  
p25 = [1]*(k+1)
p26 = [1]*(k+1)

for i in range(k):
  p25[i+1] = p25[i]*25%mod
  p26[i+1] = p26[i]*26%mod

ans = 0
for p in range(k+1):
  chk = p25[p]*comb(L-1+p,L-1)%mod
  chk *= p26[k-p]%mod
  ans += chk
  ans %= mod
  
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
s = input()
L = len(s)
mod = 10**9+7

com = [1]*(k+1)
p25 = [1]*(k+1)
p26 = [1]*(k+1)

for i in range(k):
  com[i+1] = com[i]*(L+i)//(i+1)
  p25[i+1] = p25[i]*25%mod
  p26[i+1] = p26[i]*26%mod

ans = 0
for p in range(k+1):
  chk = p25[p]*com[p]%mod
  chk *= p26[k-p]%mod
  ans += chk
  ans %= mod
  
print(ans)

Fixed submission:
k = int(input())
s = input()
L = len(s)
mod = 10**9+7

MAX = 2*10**6
fact = [1]*(MAX+1)
for i in range(1, MAX+1):
    fact[i] = (fact[i-1]*i) % mod

inv = [1]*(MAX+1)
for i in range(2, MAX+1):
    inv[i] = inv[mod % i]*(mod-mod//i) % mod

fact_inv = [1]*(MAX+1)
for i in range(1, MAX+1):
    fact_inv[i] = fact_inv[i-1] * inv[i] % mod

def comb(n, k):
    if n < k:
        return 0
    return fact[n] * fact_inv[n-k] * fact_inv[k] % mod
  
p25 = [1]*(k+1)
p26 = [1]*(k+1)

for i in range(k):
  p25[i+1] = p25[i]*25%mod
  p26[i+1] = p26[i]*26%mod

ans = 0
for p in range(k+1):
  chk = p25[p]*comb(L-1+p,L-1)%mod
  chk *= p26[k-p]%mod
  ans += chk
  ans %= mod
  
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
s = input()
L = len(s)
def make_array_for_comb(N, mod=10**9+7):
    fact = [1,1]
    fact_inv = [1,1]
    inv = [0,1]
    for i in range(2, N+1):
        fact.append((fact[-1]*i) % mod)
        # モジュラ逆数の性質
        inv.append((-inv[mod%i] * (mod//i)) % mod)
        fact_inv.append((fact_inv[-1]*inv[i]) % mod)
    return fact, fact_inv

def comb(n, r, mod=10**9+7):
  if (r < 0) or (n < r):
      return 0
  r = min(r, n - r)
  return fact[n] * fact_inv[r] * fact_inv[n-r] % mod

mod = 10**9+7
ans = 0
for p in range(L-1,L+k):
  chk = 1
  fact, fact_inv = make_array_for_comb(p,mod)
  chk *= pow(25,p-L+1,mod)
  chk *= comb(p,L-1,mod)
  chk %= mod
  chk *= pow(26,L+k-1-p,mod)
  ans += chk
  ans %= mod
  
print(ans)

Fixed submission:
k = int(input())
s = input()
L = len(s)
mod = 10**9+7

MAX = 2*10**6
fact = [1]*(MAX+1)
for i in range(1, MAX+1):
    fact[i] = (fact[i-1]*i) % mod

inv = [1]*(MAX+1)
for i in range(2, MAX+1):
    inv[i] = inv[mod % i]*(mod-mod//i) % mod

fact_inv = [1]*(MAX+1)
for i in range(1, MAX+1):
    fact_inv[i] = fact_inv[i-1] * inv[i] % mod

def comb(n, k):
    if n < k:
        return 0
    return fact[n] * fact_inv[n-k] * fact_inv[k] % mod
  
p25 = [1]*(k+1)
p26 = [1]*(k+1)

for i in range(k):
  p25[i+1] = p25[i]*25%mod
  p26[i+1] = p26[i]*26%mod

ans = 0
for p in range(k+1):
  chk = p25[p]*comb(L-1+p,L-1)%mod
  chk *= p26[k-p]%mod
  ans += chk
  ans %= mod
  
print(ans)