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):
K = int(input())
S = input()

mod = 10**9+7

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

def comb(n,k):
    return (fac[n]*finv[k]%mod)*finv[n-k]%mod

N = len(S)
ans = 0

for i in range(K+1):
    j = K - i
    tmp = pow(25,j,mod)*pow(26,i,mod)%mod
    tmp *= comb(j+N-1,j)
    tmp %= mod
    ans += tmp
    ans %= mod

print(ans)

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


mod = 10**9 + 7  
N = 2000005
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)

K = int(input())
S = len(input())
ans = 0
for i in range(S, S + K + 1):
    ans += cmb(S + K, i, mod) * pow(25, K + S - i, mod)
    ans %= mod
print(ans)

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

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

comb_s = [1]
rest = pow(25, s, MOD)
for i in range(1, n):
    comb_s.append(comb_s[-1] * (s+1-i) * pow(i, MOD-2, MOD) % MOD)
    rest += pow(25, s-i, MOD) * comb_s[i]

print((pow(26, s, MOD) - rest) % MOD)

Solution (Python):
n = 2 * (10**6) + 10
mod = 10 ** 9 + 7
fact = [1]*(n+1)
rfact = [1]*(n+1)
r = 1
for i in range(1, n+1):
  fact[i] = r = r * i % mod
rfact[n] = r = pow(fact[n], mod-2, mod)
for i in range(n, 0, -1):
  rfact[i-1] = r = r * i % mod


def perm(n, k):
  return fact[n] * rfact[n-k] % mod


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

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

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

Solution (Python):
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter

from functools import lru_cache

sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])


class combination():
    def __init__(self, mod):
        '''
        modを指定して初期化
        '''
        self.mod = mod
        self.fac = [1, 1]  
        self.ifac = [1, 1]  
        self.inv = [0, 1]  

    def calc(self, n, k):
        '''
        nCk%modを計算する
        '''
        if k < 0 or n < k:
            return 0
        self.make_tables(n)  
        k = min(k, n - k)
        return self.fac[n] * (self.ifac[k] * self.ifac[n - k] %
                              self.mod) % self.mod

    def make_tables(self, n):
        '''
        階乗テーブル・階乗の逆元テーブルを作成
        '''
        for i in range(len(self.fac), n + 1):
            self.fac.append((self.fac[-1] * i) % self.mod)
            self.inv.append(
                (-self.inv[self.mod % i] * (self.mod // i)) % self.mod)
            self.ifac.append((self.ifac[-1] * self.inv[-1]) % self.mod)


k = inp()
s = str_inp()
comb = combination(mod)
ans = pow(26, len(s) + k, mod)
for i in range(0, len(s)):
    ans -= comb.calc(k + len(s), i) * pow(25, k + len(s) - i, mod)
    ans %= mod
print(ans)

Solution (Python):
def inv_mod(a, p):
    p = abs(p)
    a %= p
    stack = []
    p0 = p
    while a > 1:
        d, a, p = p//a, p%a, a
        stack.append(d)
    x, y = 1, 0
    while stack:
        d = stack.pop()
        x, y = y-d*x, x
    return x % p0

def comb_mod(n,k,p):
    ans = 1
    k = min(k,n-k)
    if k < 0:
        return 0
    for i in range(k):
        ans = ans * (n-i) * inv_mod(k-i,p) % p
    return ans

MOD = 10**9 + 7
K = int(input())
N = len(input())
f = 26 * inv_mod(25, MOD) % MOD
a = pow(25, K, MOD) * comb_mod(N+K-1, N-1, MOD)
ans = 0
for r in range(K+1):
    ans = (ans + a) % MOD
    a *= (f * (K-r) * inv_mod(N+K-r-1, MOD))
    a %= MOD
print(ans)

Solution (Python):
class Combination:
    """階乗とその逆元のテーブルをO(N)で事前作成し、組み合わせの計算をO(1)で行う"""
    def __init__(self, n, MOD):
        self.fact = [1]
        for i in range(1, n + 1):
            self.fact.append(self.fact[-1] * i % MOD)
        self.inv_fact = [0] * (n + 1)
        self.inv_fact[n] = pow(self.fact[n], MOD - 2, MOD)
        for i in reversed(range(n)):
            self.inv_fact[i] = self.inv_fact[i + 1] * (i + 1) % MOD
        self.MOD = MOD

    def inverse(self, k):
        """kの逆元を求める O(1)"""
        return (self.inv_fact[k] * self.fact[k - 1]) % self.MOD

    def factorial(self, k):
        """k!を求める O(1)"""
        return self.fact[k]

    def inverse_factorial(self, k):
        """k!の逆元を求める O(1)"""
        return self.inv_fact[k]

    def permutation(self, k, r):
        """kPrを求める O(1)"""
        if k < r:
            return 0
        return (self.fact[k] * self.inv_fact[k - r]) % self.MOD

    def combination(self, k, r):
        """kCrを求める O(1)"""
        if k < r:
            return 0
        return (self.fact[k] * self.inv_fact[k - r] * self.inv_fact[r]) % self.MOD

    def combination2(self, k, r):
        """kCrを求める O(r)
        kが大きいが、r <= nを満たしているときに使用
        """
        if k < r:
            return 0
        res = 1
        for l in range(r):
            res *= (k - l)
            res %= self.MOD
        return (res * self.inv_fact[r]) % self.MOD


k = int(input())
s = input()
MOD = 10 ** 9 + 7
comb = Combination(2 * 10 ** 6, MOD)

ans = 0

box = len(s)
for top in range(k + 1):
    ptn = pow(26, top, MOD)
    
    ball = k - top
    ptn *= comb.combination(ball + box - 1, ball) 
    ptn %= MOD
    ptn *= pow(25, ball, MOD)
    ptn %= MOD
    ans += ptn
    ans %= MOD
print(ans % MOD)

Solution (Python):
K=int(input())
S=input()
mod=10**9+7
def inv(x):
    return pow(x,mod-2,mod)
N=len(S)
ans=0
tmp1=1
tmp2=1
for i in range(0,K+1):
    ans=ans+(tmp1*tmp2)
    ans%=mod
    tmp1=tmp1*25
    tmp1%=mod
    tmp2=tmp2*(inv(i+1)*(N+K-i))
    tmp2%=mod
    
print(ans)

Solution (Python):
mod = 10**9+7
rng = 2000100
fctr = [1]
finv = [1]
for i in range(1,rng):
  fctr.append(fctr[-1]*i%mod)
for i in range(1,rng):
  finv.append(pow(fctr[i],mod-2,mod))
def cmb(n,k):
  if n<0 or k<0 or n<k:
    return 0
  else:
    return fctr[n]*finv[n-k]*finv[k]%mod
k = int(input())
s = input()
n = len(s)
ans = pow(26,n+k,mod)
for i in range(n):
  ans -= pow(25,n+k-i,mod)*cmb(n+k,i)
  ans %= mod
print(ans)

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

fact_range = 10**6 * 2
facts = [1] * (fact_range + 1)
for i in range(0, fact_range):
    facts[i+1] = facts[i] * (i + 1) % mod

ifacts = [1] * (fact_range + 1)
ifacts[fact_range] = pow(facts[fact_range], mod - 2, mod)
for i in range(fact_range, 0, -1):
    ifacts[i-1] = ifacts[i] * i % mod

def comb(n, k):
    if k < 0 or n < k:
        return 0
    else:
        return facts[n] * ifacts[n-k] % mod * ifacts[k] % mod

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

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

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 )


ans = cmb(N+K-1, K, mod)*pow(25, K, mod)%mod

for i in range(1, K+1):
    cnt = pow(26, i, mod)
    cnt *= cmb(N+K-i-1, K-i, mod)*pow(25, K-i, mod)
    cnt %= mod
    ans += cnt
    ans %= mod

print(ans)

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

f_list = [1] * list_size
f_r_list = [1] * list_size

for i in range(list_size-1):
	f_list[i+1] = (f_list[i] * (i+1)) % MOD

f_r_list[-1] = pow(f_list[-1], MOD - 2, MOD)

for i in range(list_size-2, -1, -1):
	f_r_list[i] = (f_r_list[i+1] * (i+1)) % MOD

def comb(n, r):
	if n < r or r < 0:
		return 0
	elif n == 0 or r == 0 or n == r:
		return 1
	else:
		return (f_list[n] * f_r_list[n-r] * f_r_list[r]) % MOD 

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

Solution (Python):
MOD = 10**9+7
MAXN = 2*10**6+5
f = [1]
for i in range(MAXN):
    f.append(f[-1] * (i+1) % MOD)
def nCr(n, r, mod=MOD):
    return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod

K = int(input())
S = input()
R = len(S)
N = K + R
ans = 0
for r in range(R,N+1):
    power = pow(25, N-r, MOD)
    ans += nCr(N, r) * power % MOD
    ans %= MOD
print(ans)

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

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

def comb(n,k):
    return fact[n]*factinv[k]*factinv[n-k]%mod
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)

Solution (Python):
from numba import njit
import numpy as np


@njit('i8(i8, i8, i8)', cache=True)
def mod_pow(x, a, MOD):
    ret = 1
    cur = x
    while a:
        if a & 1:
            ret = ret * cur % MOD
        cur = cur * cur % MOD
        a >>= 1
    return ret


@njit('UniTuple(i8[:], 2)(i8, i8)', cache=True)
def prepare(n, MOD):
    factorials = np.ones(n + 1, dtype=np.int64)
    for i in range(2, n + 1):
        factorials[i] = factorials[i - 1] * i % MOD
    finvs = np.ones(n + 1, dtype=np.int64)
    finvs[n] = mod_pow(factorials[n], MOD - 2, MOD)
    for i in range(n, 1, -1):
        finvs[i - 1] = finvs[i] * i % MOD
    return factorials, finvs


@njit('i8(i8, i8)', cache=True)
def solve(k, ls):
    MOD = 10 ** 9 + 7
    facts, finvs = prepare(k + ls, MOD)

    ans = 0
    for i in range(k + 1):
        r = k - i
        pat = facts[ls + r - 1] * finvs[ls - 1] % MOD * finvs[r] % MOD
        ans = (ans + pat * mod_pow(25, r, MOD) % MOD * mod_pow(26, i, MOD)) % MOD

    return ans


k = int(input())
s = input()
print(solve(k, len(s)))

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

fact = [1] * (n + 1)
revfact = [1] * (n + 1)
for i in range(n):
    fact[i + 1] = ((i + 1) * fact[i]) % mod
revfact[n] = pow(fact[n], mod - 2, mod)
for i in reversed(range(n)):
    revfact[i] = ((i + 1) * revfact[i + 1]) % mod
def combination(n, k, p):
    return (fact[n] * revfact[k] * revfact[n - k]) % p

ans = 0
comb = []
tf = [1]
for i in range(n + 1):
    comb.append(combination(n, i, mod))
    tf.append(tf[-1] * 25 % mod)
del tf[-1]
tf.reverse()
for i in range(len(s), n + 1):
    ans += comb[i] * tf[i]
    ans %= mod
print(ans)

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n):
    res = [None] * n
    for i in range(n):
        res[i] = II()
    return res
def LIR(n):
    res = [None] * n
    for i in range(n):
        res[i] = LI()
    return res
def FR(n):
    res = [None] * n
    for i in range(n):
        res[i] = IF()
    return res
def LFR(n):
    res = [None] * n
    for i in range(n):
        res[i] = IF()
    return res
def LIR_(n):
    res = [None] * n
    for i in range(n):
        res[i] = LI_()
    return res
def SR(n):
    res = [None] * n
    for i in range(n):
        res[i] = S()
    return res
def LSR(n):
    res = [None] * n
    for i in range(n):
        res[i] = LS()
    return res
mod = 1000000007
inf = float('INF')
fact = [i for i in range(2 * 10 ** 6 + 1)]
fact[0] = 1
for i in range(2 * 10 ** 6):
    fact[i + 1] *= fact[i]
    fact[i + 1] %= mod
invfact = fact[:]
invfact[-1] = pow(invfact[-1], mod - 2, mod)
for i in range(2 * 10 ** 6, 0, -1):
    invfact[i - 1] = i * invfact[i]
    invfact[i - 1] %= mod

def combination_mod(n, k, mod):
    """ power_funcを用いて(nCk) mod p を求める """ 
    """ nCk = n!/((n-k)!k!)を使用 """
    from math import factorial
    if n < 0 or k < 0 or n < k: return 0
    if n == 0 or k == 0: return 1
    a = fact[n]
    b = invfact[k]
    c = invfact[n - k]
    return (a * b * c) % mod


def solve():
    k = II()
    s = S()
    ans = pow(26, len(s) + k, mod)
    sk = len(s) + k
    for i in range(len(s)):
        ans -= combination_mod(sk, i, mod) * pow(25, sk - i, mod)
        ans %= mod
    print(ans)
    return



if __name__ == '__main__':
    solve()

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













N = val1
fact = [1]*2 + [0]*(N-1)
ifact = [1]*2 + [0]*(N-1)
inv = [0,1] + [0]*(N-1)
p=10**9+7

for i in range(2,N+1):
    fact[i] = (fact[i-1]*i)%p
    inv[i] = p - inv[p%i]*(p//i)%p
    ifact[i] = (ifact[i-1]*inv[i])%p
def op(n,k):
    if k<0 or k>n or n<0:
        return 0
    return (fact[n]*ifact[k]*ifact[n-k])%p

res = 0
for i in range(K+1):
    tmp = pow(26,K-i,MOD) * pow(25,i,MOD) * op(val2+i-1,i)
    res = (res + tmp)%MOD
print(res)

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')
AZ = "abcdefghijklmnopqrstuvwxyz"






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



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


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


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count




K = I()
S = S()
N = len(S)

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

Solution (Python):
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()
l = len(s)
MOD = 10 ** 9 + 7

facts, finvs = prepare(k + l, MOD)

ans = 0
for i in range(k + 1):
    r = k - i
    pat = facts[l + r - 1] * finvs[l - 1] * finvs[r] % MOD
    ans = (ans + pat * pow(25, r, MOD) * pow(26, i, MOD)) % MOD
print(ans)

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

m = [1]*(k+1)
M = [1]*(k+1)
h = [1]*(k+1)
for i in range(k):
    m[i+1] = (m[i] * 25)%mod
    M[i+1] = (M[i] * 26)%mod
    h[i+1] = (h[i]*(n+i)*pow(i+1,mod-2,mod))%mod

ans = 0
for i in range(k+1):
    ans += m[i]*M[k-i]%mod*h[i]%mod
    ans %= mod
print(ans)

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

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

FACT_INV=[pow(FACT[-1],mod-2,mod)]
for i in range(2*10**6+2,0,-1):
    FACT_INV.append(FACT_INV[-1]*i%mod)

FACT_INV.reverse()

def Combi(a,b):
    if 0<=b<=a:
        return FACT[a]*FACT_INV[b]*FACT_INV[a-b]%mod
    else:
        return 0


LEN=len(S)
ANS=0
for i in range(K+1):
    ANS+=Combi(i+LEN-1,LEN-1)*pow(25,i,mod)*pow(26,K-i,mod)
print(ANS%mod)

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



mod = 10**9+7
def cmb(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

NN = 2*10**6+5 
g1 = [1, 1] 
g2 = [1, 1] 
inverse = [0, 1] 

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

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

ans = 0
t25 = 1
t26 = pow(26, K, mod)
inv26 = pow(26, mod-2, mod)
for k in range(K+1):
    ans = (ans + t25 * t26 * cmb(k+L-1, k)) % mod
    t25 = t25 * 25 % mod
    t26 = t26 * inv26 % mod
print(ans)

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

fact = [1] * 2200000
invfact = [1] * 2200000

for i in range(1, 2200000):
    fact[i] = fact[i-1] * i % MOD

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

for i in range(2200000-1, 0, -1):
    invfact[i-1] = invfact[i] * i % MOD


def nCk(n, k):
    return fact[n] * invfact[k] * invfact[n-k] % MOD


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

ans = 0

for l in range(n, n+k+1):
    ans += pow(25, l - n, MOD) * nCk(l-1, n-1) * pow(26, n+k-l, MOD) % MOD
    ans %= MOD

print(ans)

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


def solve(k, s):
    res = 0
    factorial = [1] * (2 * 10 ** 6)
    factorial_inv = [1] * (2 * 10 ** 6)
    for i in range(1, 2 * 10 ** 6):
        factorial[i] = factorial[i - 1] * i % MOD
    factorial_inv[-1] = pow(factorial[-1], MOD - 2, MOD)
    for i in range(2 * 10 ** 6 - 1, 0, -1):
        factorial_inv[i - 1] = factorial_inv[i] * i % MOD
    
    
    for i in range(k + 1):
        left = k - i + len(s) - 1
        right = len(s) - 1
        ncr = (factorial[left] * factorial_inv[right] * factorial_inv[left - right]) % MOD
        add = (ncr * pow(25, k - i, MOD) * pow(26, i, MOD)) % MOD
        res += add
        res %= MOD
    
    return res


def main():
    k = int(input())
    s = input()
    res = solve(k, s)
    print(res)


def test():
    assert solve(1, "abc") == 25 + 25 + 25 + 26
    assert solve(5, "oof") == 575111451
    assert solve(37564, "whydidyoudesertme") == 318008117


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

Solution (Python):
mod = 10 ** 9 + 7
max_kai = 2*10**6
kai = [1]
for i in range(1, max_kai):
    kai.append(kai[-1] * i % mod)
kkai = [0] * max_kai
kkai[-1] = pow(kai[-1], mod - 2, mod)
for i in reversed(range(1, max_kai)):
    kkai[i - 1] = kkai[i] * i % mod


def comb(a, b):
    if a < 0 or b < 0:
        return 0
    elif a < b:
        return 0
    c = 1
    c *= kai[a]
    c *= kkai[b]
    c *= kkai[a - b]
    return c % mod


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

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

Solution (Python):


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

mod = 10**9+7
answer = 0
tmp = 0



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 = K+S
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 )

pow = -1
for i in range(K+1):
  if pow == -1:
    pow = 1
  else:
    pow = (pow*25)%mod
  answer = (answer+pow*cmb(N,i,mod))%mod

print(answer)

Solution (Python):
R=int(input())
s=input()
k=len(s)
n=R+k
MOD=10**9+7
factorials=[1]
current=1
for i in range(1,n+1):
  current=(current*i)%MOD
  factorials.append(current)
inverses=[]
for i in range(n+1):
  inverses.append(pow(factorials[i],MOD-2,MOD))
ans=0
for i in range(R+1):
  ans=(ans+factorials[n]*inverses[i+k]*inverses[n-i-k]*pow(25,n-k-i,MOD))%MOD
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**7) 
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right

from collections import deque


from collections import Counter

from itertools import accumulate,combinations,permutations

from heapq import heapify,heappop,heappush


from functools import lru_cache

from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    

    K = int(input())
    
    
    
    
    s=input()
    ls=len(s)
    tot=pow(26,ls+K,mod)

    N=ls+K
    fact=[0]*(N+1)
    ifact=[0]*(N+1)
    fact[0],fact[1],ifact[0],ifact[1]=1,1,1,1
    for i in range(2,N+1):
        x=(fact[i-1]*i)%mod
        fact[i]=x
        ifact[i]=pow(x,mod-2,mod)
    pows=[1]*(N+1)
    for i in range(1,N+1):
        pows[i]=pows[i-1]*25%mod

    def comb(n,r): return (fact[n]*ifact[r]%mod)*ifact[n-r]%mod
    
    for i in range(0,ls):
        tot-=comb(ls+K,i)*pows[ls+K-i]
        tot%=mod
    print(tot)
    






if __name__ == "__main__":
    main()

Solution (Python):
class Combination:
    def __init__(self, n_max, mod=10**9+7):
        
        self.mod = mod
        f = 1
        self.fac = fac = [f]
        for i in range(1, n_max+1):
            f = f * i % mod
            fac.append(f)
        f = pow(f, mod-2, mod)
        self.facinv = facinv = [f]
        for i in range(n_max, 0, -1):
            f = f * i % mod
            facinv.append(f)
        facinv.reverse()

    
    

    def __call__(self, n, r):  
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def C(self, n, r):
        if not 0 <= r <= n: return 0
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def P(self, n, r):
        if not 0 <= r <= n: return 0
        return self.fac[n] * self.facinv[n-r] % self.mod

    def H(self, n, r):
        if (n == 0 and r > 0) or r < 0: return 0
        return self.fac[n+r-1] * self.facinv[r] % self.mod * self.facinv[n-1] % self.mod

    def rising_factorial(self, n, r):  
        return self.fac[n+r-1] * self.facinv[n-1] % self.mod

    def stirling_first(self, n, k):  
        if n == k: return 1
        if k == 0: return 0
        return (self.stirling_first(n-1, k-1) + (n-1)*self.stirling_first(n-1, k)) % self.mod

    def stirling_second(self, n, k):  
        if n == k: return 1  
        return self.facinv[k] * sum((-1)**(k-m) * self.C(k, m) * pow(m, n, self.mod) for m in range(1, k+1)) % self.mod

    def balls_and_boxes_3(self, n, k):  
        return sum((-1)**(k-m) * self.C(k, m) * pow(m, n, self.mod) for m in range(1, k+1)) % self.mod

    def bernoulli(self, n):  
        if n == 0: return 1
        if n % 2 and n >= 3: return 0  
        return (- pow(n+1, self.mod-2, self.mod) * sum(self.C(n+1, k) * self.bernoulli(k) % self.mod for k in range(n))) % self.mod

    def faulhaber(self, k, n):  
        
        return pow(k+1, self.mod-2, self.mod) * sum(self.C(k+1, j) * self.bernoulli(j) % self.mod * pow(n, k-j+1, self.mod) % self.mod for j in range(k+1)) % self.mod

    def lah(self, n, k):  
        return self.C(n-1, k-1) * self.fac[n] % self.mod * self.facinv[k] % self.mod

    def bell(self, n, k):  
        return sum(self.stirling_second(n, j) for j in range(1, k+1)) % self.mod

ans = 0
mod = 10**9+7
K = int(input())
S = input()
comb = Combination(2020202)
N = len(S)
for i in range(K+1):
    a = comb(N+K-1-i, N-1)
    a = a * pow(25, K-i, mod) % mod * pow(26, i, mod) % mod
    ans += a
print(ans % mod)

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())
N = len(input()) + K
P = 10**9+7

nn = 2002002
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

s = 0
po = 1
for i in range(K + 1):
    s = (s + C(N, i) * po) % P
    po = po * 25 % P
print(s)

Solution (Python):
mod = 10**9+7
def inv(n):
    x = pow(n,mod-2,mod)
    return x
k = int(input())
s = input()
l = len(s)
cmb = 1
ans = 1
for i in range(k):
    cmb =cmb*25*(k+l-i)*inv(i+1)
    cmb %= mod
    ans += cmb
    ans %= mod
print(ans)

Solution (Python):


k = int(input())
s = input()
n = len(s)
mod = 10**9 + 7
l = 2*10**6 + 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)


mod = 10**9 + 7


M = [1]  
m = 1
for i in range(1, l):
    m = (m * i) % mod
    M.append(m)

def pow(x, y, mod):  
    ans = 1
    while y > 0:
        if y % 2 == 1:
            ans = (ans * x) % mod
        x = (x**2) % mod
        y //= 2
    return ans

def inv(x, mod):  
    return pow(x, mod-2, mod)



MI = [0] * (l-1) +[inv(M[l-1], mod)]  
for i in range(l-2, -1, -1):
    MI[i] = MI[i+1] * (i+1) % mod

def C(x, y):  
    if y < 0 or y > x:
        return 0
    elif x > l:  
        y = min(y, x-y)
        ans = 1
        for i in range(x, x-y, -1):
            ans = (ans * i) % mod
        return (ans * MI[y]) % mod
    else:  
        ans = M[x]
        ans = (ans * MI[y]) % mod
        return (ans * MI[x-y]) % mod

ans = 0
for i in range(n-1, n+k):
    ans = (ans + C(i, n-1) * a25[i-(n-1)] * a26[n+k-i-1]) % mod
print(ans)

Solution (Python):

import bisect
import collections
import sys

sys.setrecursionlimit(1000000)
ACMOD = 1000000007
INF = 1 << 62

MOD = 1000000007  


def solve(K: int, S: str):
    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 = K + len(S)  
    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 k in range(K + 1):
        remain = K - k
        ans += pow(26, k, MOD) * pow(25, remain, MOD) * cmb(remain + len(S) - 1, remain, MOD)
    print(ans % MOD)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    K = int(next(tokens))  
    S = next(tokens)  
    solve(K, S)


if __name__ == '__main__':
    (main())