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
class mint:
    def __init__(self, x):
        self.x = x % MOD if isinstance(x, int) else int(x) % MOD
    def __str__(self):
        return str(self.x)
    __repr__ = __str__
    def __iadd__(self, other):
        self.x += other.x if isinstance(other, mint) else other
        self.x -= MOD if self.x >= MOD else 0
        return self
    def __isub__(self, other):
        self.x += MOD-other.x if isinstance(other, mint) else MOD-other
        self.x -= MOD if self.x >= MOD else 0
        return self
    def __imul__(self, other):
        self.x *= other.x if isinstance(other, mint) else other
        self.x %= MOD
        return self
    def __imod__(self, other):
        self.x %= other.x if isinstance(other, mint) else other
        self.x %= MOD
        return self
    def __add__(self, other):
        return (
            mint(self.x + other.x) if isinstance(other, mint) else
            mint(self.x + other)
        )
    def __sub__(self, other):
        return (
            mint(self.x - other.x) if isinstance(other, mint) else
            mint(self.x - other)
        )
    def __mul__(self, other):
        return (
            mint(self.x * other.x) if isinstance(other, mint) else
            mint(self.x * other)
        )
    def __mod__(self, other):
        return (
            mint(self.x % other.x) if isinstance(other, mint) else
            mint(self.x % other)
        )
    def __truediv__(self, other):
        return (
            mint(
                self.x * pow(other.x, MOD - 2, MOD)
            ) if isinstance(other, mint) else
            mint(self.x * pow(other, MOD - 2, MOD))
        )
    def __pow__(self, other):
        return (
            mint(pow(self.x, other.x, MOD)) if isinstance(other, mint) else
            mint(pow(self.x, other, MOD))
        )
    __radd__ = __add__
    def __rsub__(self, other):
        return (
            mint(other.x - self.x) if isinstance(other, mint) else
            mint(other - self.x)
        )
    __rmul__ = __mul__
    def __rmod__(self, other):
        return (
            mint(other.x % self.x) if isinstance(other, mint) else
            mint(other % self.x)
        )
    def __rtruediv__(self, other):
        return (
            mint(
                other.x * pow(self.x, MOD - 2, MOD)
            ) if isinstance(other, mint) else
            mint(other * pow(self.x, MOD - 2, MOD))
        )
    def __rpow__(self, other):
        return (
            mint(pow(other.x, self.x, MOD)) if isinstance(other, mint) else
            mint(pow(other, self.x, MOD))
        )
class Comb():
    
    def __init__(self, n):
        self.n = n
        fact = [0]*(n+1) 
        ifact = [0]*(n+1) 
        fact[0] = mint(1)
        for i in range(1, n+1):
            fact[i] = fact[i-1]*i
        ifact[-1] = pow(fact[-1], MOD-2)
        for i in range(n, 0, -1):
            ifact[i-1] = ifact[i]*i
        self.fact = fact
        self.ifact = ifact
    def calc(self, n, k):
        if k<0 or k>n:
            return 0
        return self.fact[n]*self.ifact[k]*self.ifact[n-k]
cb= Comb(2000005)

k = int(input())
s = input()
n = len(s)

ans = mint(0)
for i in range(n-1,n+k):
    ans += cb.calc(i,n-1)*pow(25,i-n+1,MOD)*pow(26,n+k-i-1,MOD)

print(ans)

Solution (Python):
k=int(input())
s,m,c,a=input(),10**9+7,1,1
for i in range(k):c*=25*(k+len(s)-i)*pow(i+1,m-2,m)%m;c%=m;a+=c
print(a%m)

Solution (Python):
mod=10**9+7
k=int(input())
s=input()
n=len(s)
c=1
t=1
ans=0
m=10**20
for i in range(k+1):
  ans+=c*t
  if ans>m:ans%=mod
  c*=(n+k-i)*pow(i+1,mod-2,mod)
  if c>m:c%=mod
  t*=25
  if t>m:t%=mod
print(ans%mod)

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

L26 = [ 1 for i in range(K+1)] 
for i in range(K):
  L26[i+1] = (L26[i] * 26) % base

T1 = 1
T2 = 1
ans = 0
for i in range( s, s+K+1):
  T3 = L26[K + s - i]
  
  
  p = (T1 * T2) % base
  p = (p * T3) % base
  ans += p
  ans %= base
  
  T1 *= 25
  T1 %= base

  T2 *= i
  T2 %= base
  T2 *= pow(i+1-s, base-2, base)
  T2 %= base
  
print(ans % base)

Solution (Python):
MOD = 10 ** 9 + 7
M = 2 * 10 ** 6
fac = [1] * (M + 1)
for i in range(len(fac) - 1):
    fac[i + 1] = fac[i] * (i + 1) % MOD


def comb(n, k):
    return fac[n] * pow(fac[n - k], MOD - 2, MOD) * pow(fac[k], MOD - 2, MOD) % MOD


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

Solution (Python):
mod=10**9+7
k=int(input())
s=input()
n=len(s)
c=1
t=1
ans=0
for i in range(k+1):
  ans+=c*t
  ans%=mod
  c*=(n+k-i)*pow(i+1,mod-2,mod)
  c%=mod
  t*=25
  t%=mod
print(ans)

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

k = int(input())
s = input()
MAX = k + len(s)

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


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

pow25 = [1] * (k + 1)
pow26 = [1] * (k + 1)
for i in range(k):
    pow25[i + 1] = pow25[i] * 25
    pow25[i + 1] %= MOD
    pow26[i + 1] = pow26[i] * 26
    pow26[i + 1] %= MOD


def combination(n, k):
    ret = factorial[n] * ifactorial[k] * ifactorial[n - k]
    return ret % MOD


ans = 0
for i in range(k + 1):
    tmp = combination(i + len(s) - 1, len(s) - 1)
    tmp *= pow25[i]
    tmp %= MOD
    
    tmp *= pow26[k - i]
    
    tmp %= MOD
    ans += tmp
    ans %= MOD
print(ans)

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


N = len(S)
M = K+N
s = [pow(26,K,MOD)]

r26 = pow(26,MOD-2,MOD)
for i in range(1,K+1):
    t = s[-1]
    t *= r26
    t *= 25
    t *= N+i-1
    t *= pow(i,MOD-2,MOD)
    t %= MOD
    s.append(t)


ans = sum(s) % MOD
print(ans)

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

class Facts():
   
   def __init__(self, max_num=10**5, p=10**9+7):
      self.p = p
      self.max_num = max_num
      self.fact = [1] * (self.max_num + 1)
      self.rev = [1] * (self.max_num + 1)
      for i in range(1, self.max_num + 1):
         self.fact[i] = (self.fact[i-1] * i) % self.p
      self.rev[self.max_num] = self.power_func(self.fact[self.max_num], self.p-2)
      for i in range(self.max_num-1, 0, -1):
         self.rev[i] = self.rev[i+1] * (i + 1) % self.p

   def comb(self, n, k):
      if n < 0 or k < 0 or n < k:
         return 0
      if n == 0 or k == 0:
         return 1
      res = ((self.fact[n] * self.rev[k] % self.p) * 
               self.rev[n - k]) % self.p
      return res

   def power_func(self, a, b):
      
      
      ans = 1
      while b > 0:
         if b & 1:
               ans = ans * a % self.p
         a = a * a % self.p
         b >>= 1
      return ans

r26 = [1 for _ in range(k + 1)]
r25 = [1 for _ in range(k + 1)]
for i in range(1, k+1):
   r26[i] = (r26[i-1] * 26) % MOD
   r25[i] = (r25[i-1] * 25) % MOD
facts = Facts(max_num=len(s)+k+1, p=MOD)

total = len(s) + k
ans = 0
for s_n in range(len(s), total+1):
   d = total - s_n
   ans += facts.comb(total - d - 1, len(s) - 1) * r25[k-d] * r26[d]
   ans %= MOD

print(ans)

Solution (Python):

K=int(input())
S=input()
M=len(S)
N=K+M
mod=10**9+7
ans=pow(26,N,mod)
class Data():
    def __init__(self):
        self.power=1
        self.rev=1     
class Combi():
    def __init__(self,N,mod):
        self.lists=[Data() for _ in range(N+1)]
        self.mod=mod  
        for i in range(2,N+1):
            self.lists[i].power=((self.lists[i-1].power)*i)%self.mod
        self.lists[N].rev=pow(self.lists[N].power,self.mod-2,self.mod)
        for j in range(N,0,-1):
            self.lists[j-1].rev=((self.lists[j].rev)*j)%self.mod

    def combi(self,K,R):
        if K<R:
            return 0
        else:
            return ((self.lists[K].power)*(self.lists[K-R].rev)*(self.lists[R].rev))%self.mod
        
c=Combi(2*10**6,mod)
for i in range(M):
    ans-=c.combi(N,i)*pow(25,N-i,mod)
    ans%=mod
print(ans)

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

len_S=len(S)


mod = 10**9+7
def mul_mod(a,b):
  return (a*b) % mod

def fact_inv(a):
  ans = 1
  for i in range(1,a+1):
    ans = (pow(i,mod-2,mod) * ans) % mod
  return ans

fact_list = [1]
for i in range(1,len_S+K):
  fact_list.append(mul_mod(fact_list[-1],i))

fact_list_inv = [1]
for i in range(1,len_S+K):
  fact_list_inv .append((pow(i,mod-2,mod) * fact_list_inv[-1]) % mod)
def comb_inv_mod(a,b):
  tmp = (fact_list[a]*fact_list_inv[b]) % mod
  return (tmp*fact_list_inv[a-b]) % mod

ans = 0
for i in range(len_S-1,len_S+K): 
  
  
  A = comb_inv_mod(i,len_S-1)*pow(25,i-len_S+1,mod) % mod 
  A = A*pow(26,len_S+K-i-1,mod) % mod
  ans += A
  
  ans = ans % mod
print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

lim = 2*(10**6)  
fact = [1] * (lim+1)
fact_inv = [1] * (lim+1)
for n in range(1, lim+1):
    fact[n] = (fact[n-1] * n) % mod
fact_inv[lim] = pow(fact[lim], mod-2, mod)
for n in range(lim, 0, -1):
    fact_inv[n-1] = (n * fact_inv[n]) % mod
def C(n, r):
    return (((fact[n] * fact_inv[r]) % mod) * fact_inv[n-r]) % mod

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

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

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

class ModComb:
    def __init__(self, MAX, mod=10 ** 9 + 7):
        fac = [1, 1]
        finv = [1, 1]
        inv = [0, 1]
        for i in range(2, MAX):
            fac.append(fac[i - 1] * i % mod)
            inv.append(mod - inv[mod % i] * (mod // i) % mod)
            finv.append(finv[i - 1] * inv[i] % mod)
        self.fac, self.finv, self.mod = fac, finv, mod

    def nCk(self, n, k):
        if n < k or n < 0 or k < 0:
            return 0
        fac, finv, mod = self.fac, self.finv, self.mod
        return fac[n] * (finv[k] * finv[n - k] % mod) % mod

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

N = len(S)
mc = ModComb(N + K + 10)

ans = 0
for i in range(K + 1):
    ans += pow(25, i, mod) * pow(26, K - i, mod) * mc.nCk(i + N - 1, N - 1)
    ans %= mod

print(ans)

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

class Facts():
    
    def __init__(self, max_num=10**5, p=10**9 + 7):
        self.p = p
        self.max_num = max_num
        self.fact = [1] * (self.max_num + 1)
        for i in range(1, self.max_num + 1):
            self.fact[i] = self.fact[i-1] * i
            self.fact[i] %= self.p

    def comb(self, n, k):
        
        
        if n < 0 or k < 0 or n < k:
            return 0
        if n == 0 or k == 0:
            return 1
        a = self.fact[n]
        b = self.fact[k]
        c = self.fact[n-k]
        return (a*self.power_func(b, self.p-2) *
                self.power_func(c, self.p-2)) % self.p

    def power_func(self, a, b):
        
        
        ans = 1
        while b > 0:
            if b & 1:
                ans = ans * a % self.p
            a = a * a % self.p
            b >>= 1
        return ans

r26 = [1 for _ in range(k + 1)]
r25 = [1 for _ in range(k + 1)]
for i in range(1, k+1):
   r26[i] = (r26[i-1] * 26) % MOD
   r25[i] = (r25[i-1] * 25) % MOD
facts = Facts(max_num=len(s)+k+1, p=MOD)

total = len(s) + k
ans = 0
for s_n in range(len(s), total+1):
   d = total - s_n
   ans += facts.comb(total - d - 1, len(s) - 1) * r25[k-d] * r26[d]
   ans %= MOD

print(ans)

Solution (Python):

from sys import stdin
input = stdin.readline
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def modinv2(x,r):
  return pow(x,r-2,r)

def comb(n,a,R):
    return (fact[n]*modinv2(fact[n-a]*fact[a],R))

def factinit(n,R):
    global fact
    fact = [1]*(n+1)
    for i in range(2,n+1):
        fact[i] = (fact[i-1]*i)%R

k = inn()
s = ins()
n = len(s)
factinit(n+k,R)
sm = 0
for m in range(n,n+k+1):
    x = comb(m-1,n-1,R)
    y = pow(25,m-n,R)
    z = pow(26,n+k-m,R)
    sm = (sm+x*y*z)%R
    
print(sm)

Solution (Python):
K = int(input())
S = input()
M = K + len(S)
alpha = "abcdefghijklmnopqrstuvwxyz"
mod = int(1e9) + 7 
maxf = 2000010           

def doubling(n, m, modulo=mod):
    y = 1
    base = n
    tmp = m
    while tmp != 0:
        if tmp % 2 == 1:
            y *= base
            if modulo > 0:
                y %= modulo
        base *= base
        if modulo > 0:
            base %= modulo
        tmp //= 2
    return y

def inved(a, modulo=mod):
    x, y, u, v, k, l = 1, 0, 0, 1, a, modulo
    while l != 0:
        x, y, u, v = u, v, x - u * (k // l), y - v * (k // l)
        k, l = l, k % l
    return x % modulo

fact = [1 for _ in range(maxf+1)]
invf = [1 for _ in range(maxf+1)]

for i in range(maxf):
    fact[i+1] = (fact[i] * (i+1)) % mod
invf[-1] = inved(fact[-1])
for i in range(maxf, 0, -1):
    invf[i-1] = (invf[i] * i) % mod
  
SS = 0
bas = 1
for i in range(M, len(S)-1, -1):
  SS += (bas * invf[i] * invf[M-i]) % mod
  bas *= 25
  bas %= mod
  SS %= mod
print(SS*fact[M]%mod)

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


def solveBrute(K, S):
    

    N = len(S)
    dp = [0] * (N + 1)
    dp[0] = 1
    for i in range(N + K):
        nextDp = [0] * (N + 1)
        for j in range(N):
            nextDp[j] += dp[j] * 25
            nextDp[j + 1] += dp[j]
        nextDp[N] += dp[N] * 26

        dp = nextDp
        for j in range(N + 1):
            dp[j] %= MOD
        

    return dp[N]


def solveBrute2(K, S):
    import numpy as np

    def matrixPower(mat, k):
        assert k >= 0
        if k == 0:
            return np.eye(mat.shape[0], dtype=np.int64)
        if k == 1:
            return mat
        temp = matrixPower(mat, k // 2)
        ret = (temp @ temp) % MOD
        if k % 2:
            return (ret @ mat) % MOD
        return ret

    
    
    

    N = len(S)

    mat = 25 * np.eye(N + 1, dtype=np.int64,)
    mat[N][N] += 1
    for i in range(N):
        mat[i + 1][i] = 1

    vec = np.zeros((N + 1, 1), dtype=np.int64)
    vec[0] = 1

    res = matrixPower(mat, N + K) @ vec
    return int(res[N]) % MOD


def solve(K, S):
    def modInverse(a, p):
        
        return pow(a, p - 2, p)

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

    def nCr(n, r, p=MOD):
        
        return (fact[n] * modInverse(fact[r], p) * modInverse(fact[n - r], p)) % p

    total = 0
    N = len(S)
    for i in range(N, N + K + 1):
        total += nCr(N + K, i) * pow(25, N + K - i, MOD)
        total %= MOD
    return total


(K,) = [int(x) for x in input().split()]
S = input()
ans = solve(K, S)

print(ans)

Solution (Python):
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LS2(): return list(sys.stdin.readline().rstrip())  

K = I()
n = len(LS2())
mod = 10**9+7








C = [1]
for i in range(1,K+1):
    C.append((C[-1]*(i+n-1)*pow(i,mod-2,mod)) % mod)


ans = 0
for i in range(K+1):
    ans += C[i]*pow(25,i,mod)*pow(26,K-i,mod)
    ans %= mod

print(ans)

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

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

g1=[1,1]
g2=[1,1]
inv=[0,1]
for i in range(2,3000003):
  g1.append((g1[-1]*i)%mod)
  inv.append((-inv[mod%i]*(mod//i))%mod)
  g2.append((g2[-1]*inv[-1])%mod)
P=0
for i in range(N,N+K+1):
  P=(P+cmb(N+K,i)*pow(25,N+K-i,mod))%mod
print(P)

Solution (Python):
class comb():
  F = [1, 1]
  Fi = [1, 1]
  I = [0, 1]
  def __init__(self, num, mod):
    self.MOD = mod
    for i in range(2, num + 1):
      self.F.append((self.F[-1] * i) % mod)
      self.I.append(mod - self.I[mod % i] * (mod // i) % mod)
      self.Fi.append(self.Fi[-1] * self.I[i] % mod)
  def com(self, n, k):
    if n < k: return 0
    if n < 0 or k < 0: return 0
    return self.F[n] * (self.Fi[k] * self.Fi[n - k] % self.MOD) % self.MOD


K = int(input())
S = input()
MOD = 10 ** 9 + 7

N = K + len(S)
M = len(S)
com = comb(N + 1, MOD)

p25 = [1]
for i in range(N + 1):
  p25.append(p25[-1] * 25 % MOD)

ans = 0

for i in range(K + 1):
  t = M + i
  ans = (ans + p25[N - t] * com.com(N, t)) % MOD

print(ans)

Solution (Python):
import sys
import numpy as np
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

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

    fac, finv, _ = fact_table(2_000_010, MOD)
    f = np.zeros(K + 1, np.int64)
    f = fac[N - 1:K + N] * finv[N - 1] % MOD * finv[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):
import sys


class Bigint:

    mod = 10**9 + 7

    def __init__(self, n):
        self.n = n % self.mod

    def __str__(self):
        return str(self.n)

    def __add__(self, other):
        ot = type(other)
        if ot == Bigint:
            return Bigint(self.n+other.n)
        elif ot == int:
            return Bigint(self.n+other)
        else:
            raise ValueError("Invalid type")

    def __iadd__(self, other):
        return self.__add__(other)

    def __sub__(self, other):
        ot = type(other)
        if ot == Bigint:
            o = other.n
        elif ot == int:
            o = other
        else:
            raise ValueError("Invalid type")
        
        return Bigint(self.n - o)

    def __isub__(self, other):
        return self.__sub__(other)

    def __mul__(self, other):
        ot = type(other)
        if ot == Bigint:
            return Bigint(self.n*other.n)
        elif ot == int:
            return Bigint(self.n*other)
        else:
            raise ValueError("Invalid type")

    def __imul__(self, other):
        return self.__mul__(other)

    def __pow__(self, other):
        assert type(other) == int, "power should be integer"
        
        if other < 0:
            return self ** (other % (self.mod-1))
        ret = Bigint(1)
        now = Bigint(self.n)
        while other > 0:
            if other % 2 == 0:
                pass
            else:
                ret *= now
            other //= 2
            now *= now
        return ret

    def __truediv__(self, other):
        ot = type(other)
        if ot == Bigint:
            o = other
        elif ot == int:
            o = Bigint(other)
        else:
            raise ValueError("Invalid type")

        self *= (o ** (o.mod-2))
        return self

    def __itruediv__(self, other):
        return self.__truediv__(other)


def _s(): return sys.stdin.readline().strip()


def _i(): return int(sys.stdin.readline().strip())


def main():
    k = _i()
    s = _s()
    n = len(s)

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

    ifact = [None] * (n+k)
    ifact[n+k-1] = fact[n+k-1] ** (-1)
    for i in range(n+k-2, -1, -1):
        ifact[i] = ifact[i+1] * (i+1)

    p = [Bigint(1)] * (k+1)
    q = [Bigint(1)] * (k+1)
    for i in range(1, k+1):
        p[i] = p[i-1] * 25
        q[i] = q[i-1] * 26

    nf = ifact[n-1]
    ret = Bigint(0)
    for i in range(k+1):
        k_ = k - i
        n_ = n - 1 + k_
        nck = fact[n_] * ifact[k_] * nf
        ret += (nck * p[k_] * q[i])

    return ret


if __name__ == "__main__":
    print(main())

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


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]
 
gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]
 
def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

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

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

n = 2*10**6 + 1
factorial = [1]
inverse = [1]
pow25 = [1]
pow26 = [1]
for i in range(1, n+1):
    factorial.append(factorial[-1] * i % mod)
    inverse.append(pow(factorial[-1], mod - 2, mod))
    pow25.append((pow25[-1]*25)%mod)
    pow26.append((pow26[-1]*26)%mod)

def comb(n, r, mod):
    if n < r or r < 0: return 0
    elif r == 0: return 1
    return factorial[n] * inverse[r] * inverse[n - r] % mod

n = len(s)
length = k + n
ans = 0
for i in range(n, length+1):
    temp = 1
    temp *= comb(i-1, n-1, mod)
    temp %= mod
    temp *= pow25[i-n]
    temp %= mod
    temp *= pow26[length-i]
    temp %= mod
    ans += temp
    ans %= mod
print(ans)

Solution (Python):
class ModCombination():
    def __init__(self, n, mod=998244353):
        self.mod = mod
        self.N = n
        fact = [1, 1] 
        ifact = [1, 1] 
        inverse = [0, 1] 

        for i in range( 2, n + 1 ):
            fact.append( ( fact[-1] * i ) % mod )
            inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
            ifact.append( (ifact[-1] * inverse[-1]) % mod )
        
        self.fact = fact
        self.ifact = ifact
        self.inverse = inverse

    def nCr(self, n, r):
        if r < 0 or r > n:
            return 0
        return self.fact[n] * self.ifact[r] * self.ifact[n-r] % self.mod

    def nPr(self, n, r):
        if r < 0 or r > n:
            return 0
        return self.fact[n] * self.ifact[n-r] % self.mod

def main():
    K = int(input())
    S = input()
    MOD = 10 ** 9 + 7
    N = len(S)
    mc = ModCombination(N+K-1, MOD)

    
    
    
    
    
    
    
    
    
    
    
    
    
    

    

    
    
    
    

    ans = 0
    
    for L in range(K+1):
        index_pattern = mc.nCr(N-1+K-L, N-1)
        char_pattern = pow(26, L, MOD) * pow(25, K-L, MOD) % MOD
        ans = (ans + index_pattern * char_pattern) % MOD

    print(ans)

if __name__ == '__main__':
    main()

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

import sys
sys.setrecursionlimit(10**9)

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p
p = mod 
N = 2*(10 ** 6)  
fact = [1, 1]  
factinv = [1, 1]  
inv = [0, 1]  
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)

ans=0

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

    

print(ans%mod)

Solution (Python):
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
MOD = 10**9+7
for i in range(2, 2*10**6+1):
    g1.append((g1[-1] * i) % MOD)
    inverse.append((-inverse[MOD % i] * (MOD // i)) % MOD)
    g2.append((g2[-1] * inverse[-1]) % MOD)

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

K = int(input())
S = input()
N = len(S)
NN = N + K
ans = 0
pow25 = [1]
pow26 = [1]
for i in range(K+1):
  pow25.append(pow25[-1]*25 % MOD)
  pow26.append(pow26[-1]*26 % MOD)

for i in range(K+1):
  n = NN - i
  ans = (ans + pow26[i]*pow25[n-N]*comb(n-1, N-1)) % MOD

print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(300000)

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')

class BinomialCoefficient(object):

    def __init__(self, N=510000, MOD=10**9+7):
        self.fac = [1, 1]
        self.finv = [1, 1]
        self.inv = [0, 1]
        self.MOD = MOD
        for i in range(2, N + 1):
            self.fac.append((self.fac[-1] * i) % MOD)
            self.inv.append((-self.inv[MOD % i] * (MOD // i)) % MOD)
            self.finv.append((self.finv[-1] * self.inv[-1]) % MOD)

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

K = I()
S = input()

bi = BinomialCoefficient(N=10 ** 6 * 2 + 1)
ans = 0

for i in range(len(S) - 1, len(S) + K):
    tail = len(S) + K - i - 1
    lans = bi.comb(i, len(S) - 1)
    lans = lans * pow(25, K - tail, MOD) % MOD
    lans = lans * pow(26, tail, MOD) % MOD
    ans = (ans + lans) % MOD
print(ans)

Solution (Python):
def main():
    import collections
    K = int(input())
    N = len(input())
    mod = 10**9 + 7

    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

    n = N + K
    g1 = [1, 1]  
    g2 = [1, 1]  
    inverse = [0, 1]  

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

    d = [0]*(K+1)
    d[0] = 1
    d2 = [0]*(K+1)
    d2[0] = 1

    for i in range(K):
        d[i+1] = d[i]*26
        d[i+1] %= mod

        d2[i+1] = d2[i]*25
        d2[i+1] %= mod

    ans = 0
    for i in range(K+1):
        ans += d2[K-i] * d[i] * cmb(N+K-i-1, N-1, mod)
        ans %= mod
    print(ans)


main()

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

pow25 = [1] * (N + 1)
fac = [1] * (N + 1)
inv = [1] * (N + 1)
for x in range(1, N + 1):
    fac[x] = fac[x - 1] * x % MOD
    pow25[x] = pow25[x - 1] * 25 % MOD
inv[N] = pow(fac[N], MOD-2, MOD)
for x in range(N - 1, -1, -1):
    inv[x] = inv[x + 1] * (x + 1) % MOD

def binom(n, k):
    return fac[n] * inv[n - k] % MOD * inv[k] % MOD

ans = 0
for k in range(M, N + 1):
    ans += binom(N, k) * pow25[N - k] % MOD
    ans %= MOD
print(ans)

Solution (Python):
mod = 10**9+7
M = 2*10**6

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

def comb(n,k):
    return fact[n]*factinv[k]*factinv[n-k]%mod

def main(K,S):
    n = len(S)
    ans = 0

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

if __name__ == '__main__':
    K = int(input())
    S = input()
    main(K,S)

Solution (Python):
k = int(input())
n = len(input())
p = 10**9 + 7
a = 1
fct = [a]
for i in range(1, n + k + 1):
    a = (a * i) % p
    fct.append(a)
b = pow(fct[-1], p - 2, p)
inv = [b]
for i in range(1, n + k + 1)[::-1]:
    b = (b * i) % p
    inv.append(b)
inv.reverse()
ans = 0
pow25, pow26 = [1], [1]
for i in range(1, k + 1):
    pow25.append((pow25[-1] * 25) % p)
    pow26.append((pow26[-1] * 26) % p)
for i in range(k + 1):
    c = fct[i + n - 1] * inv[i] * inv[n - 1]
    ans += pow25[i] * pow26[k - i] * c
    ans %= p
print(ans)