Problem:
 Score: 600 points    Problem Statement  How many strings can be obtained by applying the following operation on a string S exactly K times: "choose one lowercase English letter and insert it somewhere"?  The answer can be enormous, so print it modulo (10^9+7) .      Constraints   K is an integer between 1 and 10^6 (inclusive).  S is a string of length between 1 and 10^6 (inclusive) consisting of lowercase English letters.         Input  Input is given from Standard Input in the following format:  K  S       Output  Print the number of strings satisfying the condition, modulo (10^9+7) .        Sample Input 1 5
oof      Sample Output 1 575111451  For example, we can obtain proofend , moonwolf , and onionpuf , while we cannot obtain oofsix , oofelevennn , voxafolt , or fooooooo .       Sample Input 2 37564
whydidyoudesertme      Sample Output 2 318008117

Solution (Python):
MOD = 10**9 + 7
MOD_t_MAX = 2*10**6 + 10

fac  = [None] * MOD_t_MAX
finv = [None] * MOD_t_MAX
inv  = [None] * MOD_t_MAX
def MOD_COM_init():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MOD_t_MAX):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD
def MOD_COM(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD

def main():
    k = int(input())
    s = input()
    n = len(s)
    MOD_COM_init()
    ans = 0
    a = 1
    b = pow(26, k, MOD)
    for i in range(k+1):
        ans += a * MOD_COM(i + n-1, n-1) * b % MOD
        a *= 25
        b *= inv[26]
        a %= MOD
        b %= MOD
    print(ans % MOD)

if __name__ == "__main__":
    main()

Solution (Python):
k = int(input())
s = input()

l = len(s)

N = k + l + 100
MOD = 10 ** 9 + 7
fact = [0 for _ in range(N)]
invfact = [0 for _ in range(N)]
fact[0] = 1
for i in range(1, N):
    fact[i] = i * fact[i - 1] % MOD

invfact[N - 1] = pow(fact[N - 1], MOD - 2, MOD)

for i in range(N - 2, -1, -1):
    invfact[i] = invfact[i + 1] * (i + 1) % MOD
    
def nCk(n, k):
    if k < 0 or n < k:
        return 0
    else:
        return fact[n] * invfact[k] * invfact[n - k] % MOD

ex_25 = [0 for _ in range(N)]
ex_26 = [0 for _ in range(N)]
ex_25[0] = 1
ex_26[0] = 1
for i in range(1, N):
    ex_25[i] = ex_25[i - 1] * 25 % MOD
    ex_26[i] = ex_26[i - 1] * 26 % MOD

ans = 0
for i in range(k + 1):
    ans += ex_25[i] * ex_26[k - i] * nCk(i + l - 1, i)
    ans %= MOD
    
print(ans)

Solution (Python):
MOD = int(1e9) + 7
MAX = int(2e6) + 7


def div(a, b):
    return a * pow(b, MOD-2, MOD) % MOD


FACT = [1] * (MAX+1)
for i in range(1, MAX+1):
    FACT[i] = (i * FACT[i-1]) % MOD
INV = [1] * (MAX+1)
INV[MAX] = div(1, FACT[MAX])
for i in range(MAX, 0, -1):
    INV[i-1] = (INV[i] * i) % MOD


def combination(m, n):
    return (FACT[m] * INV[n] * INV[m-n]) % MOD


def main():
    K = int(input())
    S = input()
    N = len(S)
    pow25 = [1] * (K+1)
    pow26 = [1] * (K+1)
    for i in range(K):
        pow25[i+1] = (pow25[i] * 25) % MOD
        pow26[i+1] = (pow26[i] * 26) % MOD
    ans = 0
    for m in range(N, N+K+1):
        tmp = (combination(m-1, N-1) * pow25[m-N] * pow26[N+K-m]) % MOD
        ans = (ans + tmp) % MOD
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):


M = 1000000007
k = int(input())
s = len(input())
t = k+s
fact = [1]
p25 = [1]
for i in range(1,t+1):
    fact += [(fact[-1] * i)%M]
    if i<=k:
        p25  += [(p25[-1] * 25) % M]

inv = [1]*(t+1)
inv[t] = pow(fact[t], M-2, M)
for i in range(t-1, -1, -1):
    inv[i] = inv[i+1] * (i+1) % M

M = 1000000007
def nCr(n, r, M):
    return fact[n] * inv[n-r] % M * inv[r] % M

n = t

fact = [1] * (n + 1)
inv = [1] * (n + 1)

for i in range(1, n + 1):
    fact[i] = fact[i-1] * i % M

inv[n] = pow(fact[n], M - 2, M)
for i in range(n-1, -1, -1):
    inv[i] = inv[i + 1] * (i + 1) % M


res = 0
for i in range(k+1):
    
    res+=nCr(t,t-i,M)*p25[i]
    
    res%=M
    
print(res)

Solution (Python):
K = int(input())
S = input()
N = len(S)
MOD = 10**9 + 7

fct = [1]
invfct = [1]
pow25 = [1]
pow26 = [1]
for i in range(1, K+N+1):
    fct.append(fct[i-1] * i % MOD)
    invfct.append(pow(fct[i], MOD-2, MOD))
    pow25.append(pow25[i-1] * 25 % MOD)
    pow26.append(pow26[i-1] * 26 % MOD)

def cmb(n, k):
    return fct[n] * invfct[k] * invfct[n-k]

ans = 0
for i in range(K+1):
    temp = pow25[i]
    temp *= cmb(i+N-1, N-1)
    temp *= pow26[K-i]
    ans += temp
    ans %= MOD
print(ans)

Solution (Python):
from sys import stdin
input = stdin.readline
def nCr(n,r):
    return fact[n]*(inv[n-r]%M)*(inv[r]%M)
M = 1000000007
k = int(input())
s = len(input().strip())
t = k+s
fact = [1]
p25 = [1]
for i in range(1,t+1):
    fact += [(fact[-1] * i)%M]
    if i<=k:
        p25  += [(p25[-1] * 25) % M]

inv = [1]*(t+1)
inv[t] = pow(fact[t], M-2, M)
for i in range(t-1, -1, -1):
    inv[i] = inv[i+1] * (i+1) % M


res = 0
for i in range(k+1):
    res+=nCr(t,t-i)*p25[i]
    res%=M
print(res)

Solution (Python):
def nCr(n,r):
    return fact[n]*(inv[n-r]%M)*(inv[r]%M)
M = 1000000007
k = int(input())
s = len(input())
t = k+s
fact = [1]
p25 = [1]
for i in range(1,t+1):
    fact += [(fact[-1] * i)%M]
    if i<=k:
        p25  += [(p25[-1] * 25) % M]

inv = [1]*(t+1)
inv[t] = pow(fact[t], M-2, M)
for i in range(t-1, -1, -1):
    inv[i] = inv[i+1] * (i+1) % M


res = 0
for i in range(k+1):
    
    res+=nCr(t,t-i)*p25[i]
    
    res%=M
    
print(res)

Solution (Python):
M = 10**9 + 7
k,n = int(input()),len(input())
a = t = pow(26,k,M)

for i in range(k):
    t = t*25*(i+n)*pow(26*(i+1),-1,M)%M
    a += t

print(a%M)

Solution (Python):
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 10**9 + 7

def main(K, N, MOD):
    def fact_table(N, MOD):
        inv = np.empty(N, np.int64)
        inv[0] = 0
        inv[1] = 1
        for n in range(2, N):
            q, r = divmod(MOD, n)
            inv[n] = inv[r] * (-q) % MOD
        fact = np.empty(N, np.int64)
        fact[0] = 1
        for n in range(1, N):
            fact[n] = n * fact[n - 1] % MOD
        fact_inv = np.empty(N, np.int64)
        fact_inv[0] = 1
        for n in range(1, N):
            fact_inv[n] = fact_inv[n - 1] * inv[n] % MOD
        return fact, fact_inv, inv

    fact, fact_inv, inv = fact_table(2_000_010, MOD)
    f = np.zeros(K + 1, np.int64)
    f = fact[N - 1:K + N] * fact_inv[N - 1] % MOD * fact_inv[0:K + 1] % MOD

    x = 1
    for i in range(1, K + 1):
        x = (x * 25) % MOD
        f[i] = f[i] * x % MOD
    for i in range(1, K + 1):
        f[i] += f[i - 1] * 26
        f[i] %= MOD
    return f[-1]

if sys.argv[-1] == 'ONLINE_JUDGE':  
    import numba
    from numba.pycc import CC
    i8 = numba.from_dtype(np.int64)
    signature = (i8, i8, i8)

    cc = CC('my_module')
    cc.export('main', signature)(main)
    cc.compile()


from my_module import main
K = int(readline())
N = len(read().rstrip())

print(main(K, N, MOD))

Solution (Python):
k = int(input())
s = input()
mod = 10**9+7
n = len(s)
fact =[1]*(k+n)
factinv = [1]*(k+n)
inv = [0,1]
 
 
for i in range(2,k+n):
    fact[i] = (fact[i-1] * i) % mod
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    factinv[i] = (factinv[i-1] * inv[i]) % mod

def nCr(n,r):
  r = min(r,n-r)
  return (fact[n] * factinv[r] * factinv[n-r])%mod
ans = 0
for i in range(k+1):
  a = pow(25, i, mod)
  a *= nCr(i+n-1, n-1)
  a *= pow(26,k-i, mod)
  ans += a
  ans %= mod
print (ans)

Solution (Python):
class Cmb:
  g1=[1,1]
  g2=[1,1]
  inv=[0,1]
  def __init__(self,mod,upper_limit):
    self.mod=mod
    for i in range(2,upper_limit+1):
      Cmb.g1.append(Cmb.g1[-1]*i%mod)
      Cmb.inv.append(-Cmb.inv[mod%i]*(mod//i)%mod)
      Cmb.g2.append(Cmb.g2[-1]*Cmb.inv[-1]%mod)
  def cmb(self,n,r):
    if r<0 or n<r:
      return 0
    r=min(r,n-r)
    return Cmb.g1[n]*Cmb.g2[r]*Cmb.g2[n-r]%self.mod

k=int(input())
s=len(input())
mod=10**9+7
Cmb=Cmb(mod,k+s)
ans=1
for i in range(1,k+1):
  ans=(ans*26+Cmb.cmb(i+s-1,s-1)*pow(25,i,mod))%mod
print(ans)

Solution (Python):

import sys


class Combi():
    def __init__(self, N, mod):
        self.power = [1 for _ in range(N+1)]
        self.rev = [1 for _ in range(N+1)]
        self.mod = mod
        for i in range(2, N+1):
            self.power[i] = (self.power[i-1]*i) % self.mod
        self.rev[N] = pow(self.power[N], self.mod-2, self.mod)
        for j in range(N, 0, -1):
            self.rev[j-1] = (self.rev[j]*j) % self.mod

    def com(self, K, R):
        if K < R:
            return 0
        else:
            return ((self.power[K])*(self.rev[K-R])*(self.rev[R])) % self.mod

    def pom(self, K, R):
        if K < R:
            return 0
        else:
            return (self.power[K])*(self.rev[K-R]) % self.mod



def input(): return sys.stdin.readline().rstrip()


K = int(input())
S = input()
M = len(S)
N = K+M
mod = 10**9+7
ans = pow(26, N, mod)

c = Combi(2*10**6, mod)
for i in range(M):
    ans -= c.com(N, i)*pow(25, N-i, mod)
    ans %= mod
print(ans)

Solution (Python):
M=10**9+7
k,n=int(input()),len(input())
a=t=pow(26,k,M)
for i in range(k):
  t=t*25*(i+n)*pow(26*-~i,M-2,M)%M
  a+=t
print(a%M)

Solution (Python):
M=10**9+7
k,n=int(input()),len(input())
a=t=pow(26,k,M)
for i in range(k):
  t=t*25*(i+n)*pow(26*-~i,-1,M)%M
  a+=t
print(a%M)

Solution (Python):
M=10**9+7
k,n=int(input()),len(input())
a=t=pow(26,k,M)
for i in range(1,k+1):
  t=t*25*(i+n-1)*pow(26*i,-1,M)%M
  a+=t
print(a%M)

Solution (Python):


def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    K=I()
    S=input()
    N=len(S)
    
    def cmb(n, r, mod):
        if (r < 0) or (n < r):
            return 0
        r = min(r, n - r)
        return (fact[n] * factinv[r] * factinv[n-r])%mod

    fact=[1,1]
    factinv=[1,1]
    inv=[0,1]
    
    for i in range(2, N+K+2 + 1):
        fact.append((fact[-1] * i) % mod)
        inv.append((-inv[mod % i] * (mod // i)) % mod)
        factinv.append((factinv[-1] * inv[-1]) % mod)
    
    
    
    
    def calc(i,j):
        temp=pow(26,K-j,mod)
        temp=(temp*pow(25,j,mod)*cmb(i-1,j,mod))%mod
        return temp
    
    ans=0
    for j in range(K+1):
        i=j+N
        ans=(ans+calc(i,j))%mod
        
    print(ans)


main()

Solution (Python):
import sys
input = sys.stdin.readline
from collections import Counter

MAX = 2*10**6+100
MOD = 10**9+7
fact = [0]*MAX 
inv = [0]*MAX 
finv = [0]*MAX 
fact[0] = 1
fact[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
    
for i in range(2, MAX):
    fact[i] = fact[i-1]*i%MOD
    inv[i] = MOD-inv[MOD%i]*(MOD//i)%MOD
    finv[i] = finv[i-1]*inv[i]%MOD

def C(n, r):
    if n<r:
        return 0
    if n<0 or r<0:
        return 0
    return fact[n]*(finv[r]*finv[n-r]%MOD)%MOD

K = int(input())
S = input()[:-1]
N = len(S)
ans = 0

for i in range(K+1):
    ans += C(N+K-i-1, N-1)*pow(26, i, MOD)*pow(25, K-i, MOD)
    ans %= MOD
    
print(ans)

Solution (Python):
import math
k = int(input())
s = len(input())

mod = 10**9 + 7

m25 = [] 
m26 = [] 
m_n = [1] 
a = 1
b = 1

for i in range(k+1):
    m25.append(a)
    a *= 25
    a %= mod

for i in range(k+1):
    m26.append(b)
    b *= 26
    b %= mod

for i in range(2,k+s):
    x = mod % i
    y = mod // i
    c = - m_n[x-1] * y
    c %= mod
    m_n.append(c)

samu = 0
fc = 1
for i in range(k):
    sm = fc
    sm *= m25[i]
    sm *= m26[k-i]
    sm %= mod
    samu += sm

    fc *= (s + i)
    fc %= mod
    fc *= m_n[i]
    fc %= mod

sm = fc
sm *= m25[k]
sm %= mod
samu += sm

samu %= mod
print(samu)

Solution (Python):
import sys
INF = 1 << 60
MOD = 10**9 + 7 
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()

class modfact(object):
    def __init__(self, n):
        fact, invfact = [1] * (n + 1), [1] * (n + 1)
        for i in range(1, n + 1): fact[i] = i * fact[i - 1] % MOD
        invfact[n] = pow(fact[n], MOD - 2, MOD)
        for i in range(n - 1, -1, -1): invfact[i] = invfact[i + 1] * (i + 1) % MOD
        self._fact, self._invfact = fact, invfact

    def fact(self, n):
        return self._fact[n]

    def invfact(self, n):
        return self._invfact[n]

    def comb(self, n, k):
        return self._fact[n] * self._invfact[k] % MOD * self._invfact[n - k] % MOD if 0 <= k <= n else 0

    def perm(self, n, k):
        return self._fact[n] * self._invfact[n - k] % MOD if 0 <= k <= n else 0

def resolve():
    k = int(input())
    n = len(input())
    mf = modfact(n + k)
    ans = 0
    for i in range(n, n + k + 1):
        ans += mf.comb(n + k, i) * pow(25, n + k - i, MOD)
        ans %= MOD
    print(ans)
resolve()

Solution (Python):
import sys
INF = 1 << 60
MOD = 10**9 + 7 
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()

class modfact(object):
    def __init__(self, n):
        fact, invfact = [1] * (n + 1), [1] * (n + 1)
        for i in range(1, n + 1): fact[i] = i * fact[i - 1] % MOD
        invfact[n] = pow(fact[n], MOD - 2, MOD)
        for i in range(n - 1, -1, -1): invfact[i] = invfact[i + 1] * (i + 1) % MOD
        self._fact, self._invfact = fact, invfact

    def fact(self, n):
        return self._fact[n]

    def invfact(self, n):
        return self._invfact[n]

    def comb(self, n, k):
        return self._fact[n] * self._invfact[k] % MOD * self._invfact[n - k] % MOD if 0 <= k <= n else 0

    def perm(self, n, k):
        return self._fact[n] * self._invfact[n - k] % MOD if 0 <= k <= n else 0

def resolve():
    k = int(input())
    n = len(input())
    mf = modfact(n + k)
    ans = 0
    for i in range(n, n + k + 1):
        ans += mf.comb(n + k, i) * pow(25, n + k - i, MOD)
        ans %= MOD
    print(ans)
resolve()

Solution (Python):
k = int(input())
s = input()
len_s = len(s)
MOD = 1000000007

x_i = pow(26, k, MOD)
r = (25 * pow(26, -1, MOD)) % MOD
comb_i = 1

a = 0
for i in range(k + 1):  
  a += (comb_i  * x_i  ) % MOD
  a %= MOD
  
  x_i  = (x_i  * r) % MOD
  comb_i = (comb_i * (len_s + i) * pow(i + 1, -1, MOD)) % MOD


print(a)

Solution (Python):
K = int(input())
S = input()
N = len(S)

mod = 10**9+7

power25 = [1]*(K+1)
power26 = [1]*(K+1)

def mod_factorial(n, m):
    mod_factorials = [1] * (n + 1)
    for i in range(1, n+1):
        mod_factorials[i] = mod_factorials[i-1]*i
        mod_factorials[i] %= m
    return mod_factorials


def mod_inv_factorials2(n, m):
    mod_invs = [1] * (n + 1)
    invs = [1] * (n + 1)
    for i in range(2, n + 1):
        invs[i] = m - invs[m % i] * (m//i) % m

    for i in range(1, n+1):
        mod_invs[i] = invs[i]*mod_invs[i-1]
        mod_invs[i] %= m
    return mod_invs

factrials = mod_factorial(K+N,mod)
inv_factrials = mod_inv_factorials2(max(N,K+1),mod)

for i in range(1,K+1):
    power25[i] = (power25[i-1]*25)%mod
for i in range(1,K+1):
    power26[i] = (power26[i-1]*26)%mod

ans = 0
for i in range(K+1):
    rk = K-i
    ans += power25[rk]*factrials[rk+N-1]*inv_factrials[N-1]*inv_factrials[rk]*power26[i]
    ans %= mod

print(ans)

Solution (Python):
K = int(input())
S = len(input())
P = 10**9+7
nn = 2*10**6+1
fa = [1] * (nn+1)
fainv = [1] * (nn+1)
for i in range(nn):
    fa[i+1] = fa[i] * (i+1) % P
fainv[-1] = pow(fa[-1], P-2, P)
for i in range(nn)[::-1]:
    fainv[i] = fainv[i+1] * (i+1) % P
 
C = lambda a, b: fa[a] * fainv[b] % P * fainv[a-b] % P if 0 <= b <= a else 0

inv = [1]*27
for i in range(2,27):
  inv[i]=(-(P//i)*inv[P%i])%P
ans = 0
a = 1
b = pow(26,K,P)
for i in range(K+1):
  ans = (ans + (C(i+S-1,S-1)*a%P*b%P))%P
  a = a*25%P
  b = b*inv[26]%P
print(ans)

Solution (Python):
P = 10**9 + 7

K = int(input())
S = input()
L = len(S)

d = [0]*(L+K+1)
d[0] = 1
for i in range(1, L+K+1):
    d[i] = (d[i-1]*i)%P

ans = 0
for i in range(K+1):
    temp = pow(26, i, P) * pow(25, K-i, P)
    temp %= P
    temp *= d[L-1+K-i]
    temp %= P
    temp *= pow(d[L-1], P-2, P)
    temp %= P
    temp *= pow(d[K-i], P-2, P)
    temp %= P
    ans += temp
    ans %= P

print(ans)

Solution (Python):
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    
    
    nmax = 2 * 10 ** 6 + 10  
    fac = [0] * nmax
    finv = [0] * nmax
    inv = [0] * nmax
    fac[0] = 1
    fac[1] = 1
    finv[0] = 1
    finv[1] = 1
    inv[1] = 1
    for i in range(2, nmax):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod

    def comb(n, r):
        if n < r:
            return 0
        else:
            return (fac[n] * ((finv[r] * finv[n - r]) % mod)) % mod

    K = int(input())
    S = input().rstrip('\n')
    N = len(S)

    ans = 0
    for k in range(K+1):
        ans = (ans + (pow(25, K-k, mod) * comb(N+K, N+k))%mod)%mod
    print(ans)



if __name__ == '__main__':
    main()

Solution (Python):
K = int(input())
S = input()

MAX = 2 * 10 ** 6 + 1
MOD = 10 ** 9 + 7


fac = [0] * (MAX + 1)
fac[0] = 1
fac[1] = 1
for i in range(2, MAX + 1):
    fac[i] = fac[i - 1] * i % MOD
    

finv = [0] * (MAX + 1)
finv[MAX] = pow(fac[MAX], MOD - 2, MOD)
for i in reversed(range(1, MAX + 1)):
    finv[i - 1] = finv[i] * i % MOD

def comb(n, k):
    if n < k or k < 0:
        return 0
    return (fac[n] * finv[k] * finv[n - k]) % MOD

N = len(S)
ans = 0
for i in range(K + 1):
    tmp = (pow(25, K - i, MOD) * pow(26, i, MOD)) % MOD
    ans += comb(N + K - i - 1, N - 1) * tmp
    ans %= MOD
print(ans)

Solution (Python):
MOD = 10**9 + 7

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()
n = len(s)
ans = 0

l = k+n + 3
 
a25 = [1]
for i in range(l):
    a25.append((a25[-1] * 25) % MOD)
a26 = [1]
for i in range(l):
    a26.append((a26[-1] * 26) % MOD)

fact, inv = prepare(n+k, MOD)
for i in range(k+1):
    c25 = a25[i]
    f = fact[i+n-1] * inv[i] % MOD * inv[n-1] % MOD
    c25 *= f
    c25 %= MOD

    c26 = a26[k-i]
    ans += (c25 * c26 % MOD)
    ans %= MOD
print(ans)

Solution (Python):
k = int(input())
s = input()
n = len(s)
mod = 10**9+7
def cmb(n,r,mod):
    r = min(r, n-r)
    return (fact[n] * factinv[r] * factinv[n-r]) % mod
def makefact(n,mod):
    fact = [1,1]
    factinv = [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)
        factinv.append((factinv[-1]*inv[-1])%mod)
    return fact,factinv
fact,factinv = makefact(2*10**6+5,mod)
ans = 0
for i in range(k+1):
    temp = pow(26,i,mod)
    c = cmb(n+k-i-1,n-1,mod)
    temp *= c*pow(25,k-i,mod)
    ans = (ans+temp)%mod
print(ans)

Solution (Python):
import sys
INF = 1 << 60
MOD = 10**9 + 7 
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()

class modfact(object):
    def __init__(self, n):
        fact, invfact = [1] * (n + 1), [1] * (n + 1)
        for i in range(1, n + 1): fact[i] = i * fact[i - 1] % MOD
        invfact[n] = pow(fact[n], MOD - 2, MOD)
        for i in range(n - 1, -1, -1): invfact[i] = invfact[i + 1] * (i + 1) % MOD
        self._fact, self._invfact = fact, invfact

    def fact(self, n):
        return self._fact[n]

    def invfact(self, n):
        return self._invfact[n]

    def comb(self, n, k):
        return self._fact[n] * self._invfact[k] % MOD * self._invfact[n - k] % MOD if 0 <= k <= n else 0

    def perm(self, n, k):
        return self._fact[n] * self._invfact[n - k] % MOD if 0 <= k <= n else 0

def resolve():
    k = int(input())
    n = len(input())
    mf = modfact(n + k)
    ans = 0
    for i in range(n, n + k + 1):
        ans += mf.comb(n + k, i) * pow(25, n + k - i, MOD)
        ans %= MOD
    print(ans)
resolve()

Solution (Python):
k = int(input())
s = input()

mod = 10**9+7
n = len(s) + k

frac = [1]*(n+1)
finv = [1]*(n+1)
for i in range(n):
    frac[i+1] = (i+1)*frac[i]%mod
finv[-1] = pow(frac[-1],mod-2,mod)
for i in range(1,n+1):
    finv[n-i] = finv[n-i+1]*(n-i+1)%mod
def nCr(n,r,m):
    if n<0 or r<0 or n<r: return 0
    r = min(r,n-r)
    return frac[n]*finv[n-r]*finv[r]%mod
a,b = [1],[1]
for _ in range(k+1):
    a.append(a[-1]*25%mod)
    b.append(b[-1]*26%mod)
n = len(s)
ans = 0
for i in range(k+1):
    ans += a[i]*b[k-i]*nCr(i+n-1,n-1,mod)
    ans %= mod
print(ans)

Solution (Python):
def calc_inv(n, mod_n):
    inv_li = [0] * (n + 2)
    inv_li[0] = 0
    inv_li[1] = 1
    for i in range(2, n + 2):
        q, r = divmod(mod_n, i)
        inv_li[i] = -inv_li[r] * q % mod_n
    return inv_li


K = int(input())
S = input()
s_len = len(S)

MOD = 10**9 + 7
inv = calc_inv(max(K, 26) + 10, MOD)

ans = 0
p = pow(26, K, MOD)

for i in range(1, K + 2):
    ans = (ans + p % MOD) % MOD
    p = p * (s_len + i - 1) * inv[i] * 25 * inv[26] % MOD

print(ans)

Solution (Python):
mod = 10**9+7
k = int(input())
s = input()

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

g1 = [1, 1] 
g2 = [1, 1] 
inverse = [0, 1] 

for i in range( 2, len(s)+k+5):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

ans = 0
for i in range(len(s), len(s)+k+1):
  ans += pow(25, i-len(s), mod)*pow(26, k+len(s)-i, mod)*cmb(i-1, len(s)-1, mod)
  ans %= mod
  
print(ans)

Solution (Python):
mod = 10**9+7
k = int(input())
s = input()

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

g1 = [1, 1] 
g2 = [1, 1] 
inverse = [0, 1] 

for i in range( 2, len(s)+k+5):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

ans = 0
pow1 = 1
for i in range(len(s), len(s)+k+1):
  ans += pow1 * pow(26, k+len(s)-i, mod)*cmb(i-1, len(s)-1, mod)
  pow1 *= 25
  pow1 %= mod
  ans %= mod
  
print(ans)

Solution (Python):
k = int(input())
s = str(input())

mod = 1000000007
decided_keta = len(s)
all_keta = len(s) + k

kai_list = [1 for i in range(2000010)]
for i in range(2,len(kai_list)):
    kai_list[i] = (kai_list[i-1]*i)%mod

answer = 0
for last_given_character_posi in range(decided_keta-1,all_keta):
    given_posi_pattern = kai_list[last_given_character_posi]*pow(kai_list[decided_keta-1],mod-2,mod)%mod*pow(kai_list[last_given_character_posi-decided_keta+1],mod-2,mod)%mod
    char_pattern = pow(25,last_given_character_posi-(decided_keta-1),mod)
    rest_char_pattern = pow(26,all_keta-(last_given_character_posi+1),mod)
    answer = (answer + given_posi_pattern*char_pattern%mod*rest_char_pattern%mod)%mod
print(answer)

Solution (Python):
k = int(input())
s = input()
n = len(s)

MAX = 10**6
MOD = 10**9+7

inv = [0] * (MAX+1)
inv[1] = 1
for i in range(2, MAX+1):
    q, r = divmod(MOD, i)
    inv[i] = -inv[r] * q % MOD

ans = val = pow(26, k, MOD)
for i in range(1, k+1):
    val *= (i+n-1) * 25 * inv[i] * inv[26] % MOD
    val %= MOD
    ans += val
    ans %= MOD
print(ans)

Solution (Python):
k = int(input())
s = input()
n = len(s)

MOD = 10**9+7
d = pow(26, -1, MOD)
ans = val = pow(26, k, MOD)
for i in range(1, k+1):
    val *= (i+n-1) * 25 * pow(i, -1, MOD) * d % MOD
    val %= MOD
    ans += val
    ans %= MOD
print(ans)

Solution (Python):
MAX = 2*10**6
MOD = 10**9+7

fac = [0] * (MAX)
finv = [0] * (MAX)
inv = [0] * (MAX)

def comb_init():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i-1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
        finv[i] = finv[i-1] * inv[i] % MOD

def comb(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD


if __name__ == '__main__':
    k = int(input())
    s = input()
    n = len(s)
    comb_init()
    ans = 0
    for i in range(k+1):
        val = comb(i+n-1, n-1)
        val *= pow(25, i, MOD)
        val %= MOD
        val *= pow(26, k-i, MOD)
        val %= MOD
        ans += val
        ans %= MOD
    print(ans)

Solution (Python):
MAX = 2*10**6
MOD = 10**9+7

fac = [0] * (MAX+1)
finv = [0] * (MAX+1)
inv = [0] * (MAX+1)

def comb_init():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX+1):
        fac[i] = fac[i-1] * i % MOD
        inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
        finv[i] = finv[i-1] * inv[i] % MOD

def comb(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD


if __name__ == '__main__':
    k = int(input())
    s = input()
    n = len(s)
    comb_init()
    ans = 0
    for i in range(k+1):
        val = comb(i+n-1, n-1)
        val *= pow(25, i, MOD)
        val %= MOD
        val *= pow(26, k-i, MOD)
        val %= MOD
        ans += val
        ans %= MOD
    print(ans)

Solution (Python):
k = int(input())
s = len(input())
MOD = 10 ** 9 + 7


def mod_inv(n):
    return pow(n, MOD - 2, MOD)

total = pow(26, k + s, MOD)
tmp = pow(25, k + s, MOD)
total = (total - tmp) % MOD

for i in range(0, s-1):
    tmp = ((tmp * ((k+s) - i)) % MOD * mod_inv((i + 1) * 25)) % MOD
    total = (total - tmp) % MOD
print(total)

Solution (Python):


'''
Author: andyli
Time: 2020-06-24 21:10:25
'''

mod = 10**9 + 7

m = int(input())
n = len(input())
t = n+m

fac = [0]*(t+1)
ifac = [0]*(t+1)
pw = [0] * (t+1)
fac[0] = 1
for i in range(1, t+1):
    fac[i] = fac[i-1] * i % mod
ifac[t] = pow(fac[t], mod-2, mod)

for i in range(t-1, -1, -1):
    ifac[i] = ifac[i+1] * (i+1) % mod

pw[0] = 1
for i in range(1, t+1):
    pw[i] = pw[i-1] * 25 % mod

def C(n, m):
    return fac[n]*ifac[m]*ifac[n-m]%mod

ans=0
for i in range(n, t+1):
    ans = (ans + pw[t-i] * C(t, i)) % mod

print(ans)

Solution (Python):
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)

Solution (Python):
import sys

K = int(sys.stdin.readline())
S = sys.stdin.readline().rstrip('\n')


N_MAX = 10**6  
MOD = 10**9 + 7

inv = [0] * (N_MAX + 2)
inv[0] = 0  
inv[1] = 1

for i in range(2, N_MAX + 2):
    q, r = divmod(MOD, i)
    inv[i] = -inv[r] * q % MOD



ans = 0

ln = len(S)

p = pow(26, K, MOD)

for i in range(1, K + 2):

    ans += p % MOD
    ans %= MOD

    
    p = p * (ln + i - 1) * inv[i] * 25 * inv[26] % MOD

    
    

print(ans)

Solution (Python):
import sys

K = int(sys.stdin.readline())
S = sys.stdin.readline().rstrip('\n')


N_MAX = 10**6  
MOD = 10**9 + 7

inv = [0] * (N_MAX + 2)
inv[0] = 0  
inv[1] = 1

for i in range(2, N_MAX + 2):
    inv[i] = -inv[MOD % i] * (MOD // i) % MOD


ans = 0

ln = len(S)

p1 = 1
p2 = 1
s2 = pow(26, K, MOD)

for i in range(1, K + 2):

    ans += (p1 * p2 * s2) % MOD
    ans %= MOD

    

    
    p1 = (p1 * (ln + i - 1) * inv[i]) % MOD
    p2 = (p2 * 25) % MOD

    
    s2 = (s2 * inv[26]) % MOD

print(ans)

Solution (Python):
import sys

K = int(sys.stdin.readline())
S = sys.stdin.readline().rstrip('\n')


N_MAX = 10**6  
MOD = 10**9 + 7

inv = [0, 1]  

for i in range(2, N_MAX + 2):
    inv.append((-inv[MOD % i] * (MOD // i)) % MOD)


ans = 0

ln = len(S)

p1 = 1
p2 = 1
s2 = pow(26, K, MOD)

for i in range(1, K + 2):

    ans += (p1 * p2 * s2) % MOD
    ans %= MOD

    

    
    p1 = (p1 * (ln + i - 1) * inv[i]) % MOD
    p2 = (p2 * 25) % MOD

    
    s2 = (s2 * inv[26]) % MOD

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
K = int(input())
N = len(input().rstrip())
mod = 10**9 + 7
pow25 = [1]
pow26 = [1]
x = 1
y = 1
for i in range(K):
    x *= 25
    y *= 26
    x %= mod
    y %= mod
    pow25.append(x)
    pow26.append(y)

def comb(n, r, mod):
    if r<0 or r>n:
        return 0
    r = min(r, n-r)
    return fac[n] * (finv[r] * finv[n-r] % mod) % mod

fac = [1, 1]
finv = [1, 1]
inv = [0, 1]
for i in range(2, N + K + 1):
    fac.append((fac[-1] * i) % mod)
    inv.append((-inv[mod%i] * (mod//i)) % mod)
    finv.append((finv[-1] * inv[-1]) % mod)

ans = 0
for i in range(K+1):
    ans += (((comb(i+N-1, N-1, mod) * pow25[i]) % mod) * pow26[K-i]) % mod
print(ans%mod)

Solution (Python):
K = int(input())
N = len(input())

mod = 10 ** 9 + 7
div = pow(26, -1, mod)
comb_i = pow(26, K, mod)
ans = comb_i
for i in range(1, K + 1):
  comb_i = (comb_i * (N - 1 + i) * pow(i, -1, mod)) % mod
  comb_i = (comb_i * 25 * div) % mod
  ans = (ans + comb_i) % mod
  
print(ans)

Solution (Python):
import sys
input = sys.stdin.buffer.readline

mod = 10**9+7
MAX_N = 10**7 + 10

fact = [1]
fact_inv = [0]*(MAX_N+4)
for i in range(MAX_N+3):
    fact.append(fact[-1]*(i+1)%mod)

fact_inv[-1] = pow(fact[-1],mod-2,mod)
for i in range(MAX_N+2,-1,-1):
    fact_inv[i] = fact_inv[i+1]*(i+1)%mod


def mod_comb_k(n,k,mod):
    return fact[n] * fact_inv[k] % mod * fact_inv[n-k] %mod

k = int(input())
s = list(input())

n = len(s)-1

res = 0

for i in range(n,n+k+1):
    res = (res + (mod_comb_k(i-1,n-1,mod)*pow(25,i-n,mod)%mod)*pow(26,n+k-i,mod))%mod

print(res)

Solution (Python):
import collections
import heapq

from collections import defaultdict
from heapq import heappush, heappop
import sys


def main(K, N):
    P = 10 ** 9 + 7

    P25 = [1] * (K + 1)
    P26 = [1] * (K + 1)
    F = [1] * (N + K)
    INV = [1] * (N + K)
    INVF = [1] * (N + K)

    p25 = 1
    p26 = 1
    for i in range(1, K + 1):
        p25 *= 25
        p25 %= P
        P25[i] = p25

        p26 *= 26
        p26 %= P
        P26[i] = p26

    f = 1
    invf = 1
    for i in range(2, N + K):
        f *= i
        f %= P
        F[i] = f
        q, r = divmod(P, i)
        INV[i] = -INV[r] * q % P
        invf *= INV[i]
        invf %= P
        INVF[i] = invf

    def comb_rep(n, r):
        return (F[n + r - 1] * INVF[r] % P) * INVF[n - 1] % P

    ret = 0
    for i in range(K + 1):
        ret += (
            P25[i] *
            P26[K - i] % P *
            comb_rep(N, i) % P
        )
    return (ret % P)


if sys.argv[-1] == 'ONLINE_JUDGE':
    print("compiling")
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('main', 'i8(i8,i8)')(main)
    cc.compile()
    exit()
else:
    from my_module import main
    K = int(input())
    S = input()
    print(main(K, len(S)))

Solution (Python):
from sys import stdin, setrecursionlimit

setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi, radians, sin, cos

MOD = 10 ** 9 + 7
INF = 10 ** 18

K = int(input())
S = input()

len_S = len(S)


SIZE = 2 * 10 ** 6 + 100
g1, g2, inv = [1, 1], [1, 1], [0, 1]
for i in range(2, SIZE + 1):
    g1.append((g1[-1] * i) % MOD)
    inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
    g2.append((g2[-1] * inv[-1]) % MOD)
def nCr(n, r):
    if r < 0 or r > n:
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n - r] % MOD

answer = 0
for i in range(K + 1):
    answer += pow(25, i, MOD) * nCr(len_S - 1 + i, i) * pow(26, K - i, MOD)
    answer %= MOD

print(answer)