Buggy python submission (verdict: Time Limit Exceeded):
def calc_pow(K, mod):
    pow25 = 1
    pow26 = 1
    li_pow25 = [1]
    li_pow26 = [1]
    for i in range(K + 1):
        pow25 *= 25
        pow25 %= mod
        li_pow25.append(pow25)
        pow26 *= 26
        pow26 %= mod
        li_pow26.append(pow26)
    return li_pow25, li_pow26
    
if __name__ == '__main__':
    K = int(input())
    n = len(input())
    mod = 10**9+7 #出力の制限
    #25 25 a 25 25 25 b 25 25  c  26 26
    cmb = 1
    ans = 0
    pow25, pow26 = calc_pow(K, mod)
    li = []
    for i in range(0, K + 1):
        ans1 = (pow25[i] * cmb) % mod
        ans2 = pow26[K - i]
        cmb = (cmb * (n + i) // (i + 1))
        ans = (ans + (ans1 * ans2) % mod) % mod
        #li.append(pow(25, i, mod))
    
    print(ans)

Fixed submission:
n = int(input())
s = input()
 
S = len(s)
mod = 10 ** 9 + 7
 
tmp_ans = pow(26, n, mod)
div = pow(26, -1, mod)
 
ans = tmp_ans
 
for i in range(1, n+1):
    tmp_ans = (tmp_ans * 25 * div) % mod
    tmp_ans = ((tmp_ans * (S-1+i)) * pow(i, -1, mod)) % mod
    ans = (ans + tmp_ans) % mod
 
ans %= mod
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 24 20:53:22 2020

@author: NEC-PCuser
"""
def calc_pow(K, mod):
    pow25 = 1
    pow26 = 1
    li_pow25 = [1]
    li_pow26 = [1]
    for i in range(K + 1):
        pow25 *= 25
        pow25 %= mod
        li_pow25.append(pow25)
        pow26 *= 26
        pow26 %= mod
        li_pow26.append(pow26)
    return li_pow25, li_pow26
    
if __name__ == '__main__':
    K = int(input())
    n = len(input())
    mod = 10**9+7 #出力の制限
    #25 25 a 25 25 25 b 25 25  c  26 26
    cmb = 1
    ans = 0
    pow25, pow26 = calc_pow(K, mod)
    li = []
    for i in range(0, K + 1):
        ans1 = (pow(25, i, mod) * cmb) % mod
        ans2 = pow(26, K - i, mod)
        cmb = (cmb * (n + i) // (i + 1))
        ans = (ans + (ans1 * ans2) % mod) % mod
        #li.append(pow(25, i, mod))
    
    print(ans)
        

Fixed submission:
n = int(input())
s = input()
 
S = len(s)
mod = 10 ** 9 + 7
 
tmp_ans = pow(26, n, mod)
div = pow(26, -1, mod)
 
ans = tmp_ans
 
for i in range(1, n+1):
    tmp_ans = (tmp_ans * 25 * div) % mod
    tmp_ans = ((tmp_ans * (S-1+i)) * pow(i, -1, mod)) % mod
    ans = (ans + tmp_ans) % mod
 
ans %= mod
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 24 20:53:22 2020

@author: NEC-PCuser
"""

if __name__ == '__main__':
    K = int(input())
    n = len(input())
    mod = 10**9+7 #出力の制限
    #25 25 a 25 25 25 b 25 25  c  26 26
    cmb = 1
    ans = 0
    for i in range(0, K + 1):
        ans1 = (pow(25, i, mod) * cmb) % mod
        ans2 = pow(26, K - i, mod)
        cmb = (cmb * (n + i) // (i + 1)) 
        ans = (ans + (ans1 * ans2) % mod) % mod
    
    
    print(ans)
        

Fixed submission:
n = int(input())
s = input()
 
S = len(s)
mod = 10 ** 9 + 7
 
tmp_ans = pow(26, n, mod)
div = pow(26, -1, mod)
 
ans = tmp_ans
 
for i in range(1, n+1):
    tmp_ans = (tmp_ans * 25 * div) % mod
    tmp_ans = ((tmp_ans * (S-1+i)) * pow(i, -1, mod)) % mod
    ans = (ans + tmp_ans) % mod
 
ans %= mod
 
print(ans)

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 24 20:53:22 2020

@author: NEC-PCuser
"""

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return fact[n] * factinv[r] * factinv[n-r] % mod

def createPowList(K, mod):
    li25 = [1]
    li26 = [1]
    p25 = 1
    p26 = 1
    for i in range(K + 1):
        p25 *= 25
        p25 %= mod
        li25.append(p25)
        p26 *= 26
        p26 %= mod
        li26.append(p26)
    return li25, li26

p = 10 ** 9 + 7
N = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用


p = 10 ** 9 + 7
N = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

if __name__ == '__main__':
    K = int(input())
    n = len(input())
    mod = 10**9+7 #出力の制限
    #25 25 a 25 25 25 b 25 25  c  26 26
    p25, p26 = createPowList(K, mod)

    ans = 0
    for i in range(0, K + 1):
        ans1 = (p25[i] * cmb(n + i - 1, n - 1, mod)) % mod
        ans2 = (p26[K - i])
        ans += (ans1 * ans2) % mod
    
    print(ans)
        

Fixed submission:
n = int(input())
s = input()
 
S = len(s)
mod = 10 ** 9 + 7
 
tmp_ans = pow(26, n, mod)
div = pow(26, -1, mod)
 
ans = tmp_ans
 
for i in range(1, n+1):
    tmp_ans = (tmp_ans * 25 * div) % mod
    tmp_ans = ((tmp_ans * (S-1+i)) * pow(i, -1, mod)) % mod
    ans = (ans + tmp_ans) % mod
 
ans %= mod
 
print(ans)

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 24 20:53:22 2020

@author: NEC-PCuser
"""

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return fact[n] * factinv[r] * factinv[n-r] % mod


p = 10 ** 9 + 7
N = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

if __name__ == '__main__':
    K = int(input())
    n = len(input())
    mod = 10**9+7 #出力の制限
    #25 25 a 25 25 25 b 25 25  c  26 26
    
    ans = 0
    for i in range(0, K + 1):
        ans1 = (((25 ** i) % (mod)) * cmb(n + i - 1, n - 1, mod)) % mod
        ans2 = (26 ** (K - i)) % mod
        ans += (ans1 * ans2) % mod
    
    print(ans)
        

Fixed submission:
n = int(input())
s = input()
 
S = len(s)
mod = 10 ** 9 + 7
 
tmp_ans = pow(26, n, mod)
div = pow(26, -1, mod)
 
ans = tmp_ans
 
for i in range(1, n+1):
    tmp_ans = (tmp_ans * 25 * div) % mod
    tmp_ans = ((tmp_ans * (S-1+i)) * pow(i, -1, mod)) % mod
    ans = (ans + tmp_ans) % mod
 
ans %= mod
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 24 20:53:22 2020

@author: NEC-PCuser
"""

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

if __name__ == '__main__':
    K = int(input())
    n = len(input())
    mod = 10**9+7 #出力の制限
    #25 25 a 25 25 25 b 25 25  c  26 26
    
    ans = 0
    for i in range(0, K + 1):
        ans1 = (((25 ** i) % (mod)) * cmb(n + i - 1, n - 1)) % mod
        ans2 = (26 ** (K - i)) % mod
        ans += (ans1 * ans2) % mod
    
    print(ans)
        

Fixed submission:
n = int(input())
s = input()
 
S = len(s)
mod = 10 ** 9 + 7
 
tmp_ans = pow(26, n, mod)
div = pow(26, -1, mod)
 
ans = tmp_ans
 
for i in range(1, n+1):
    tmp_ans = (tmp_ans * 25 * div) % mod
    tmp_ans = ((tmp_ans * (S-1+i)) * pow(i, -1, mod)) % mod
    ans = (ans + tmp_ans) % mod
 
ans %= mod
 
print(ans)