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



Sample input:
5
oof


Sample output:
575111451

Submission status: Runtime Error

Solution code:
from functools import lru_cache


@lru_cache
def factorial(n):
    if n == 0:
        return 1
    return (n * factorial(n-1)) % MOD


@lru_cache
def ifactorial(n):
    return pow(factorial(n), MOD-2, MOD)


@lru_cache
def combination(n, k):
    return (factorial(n) * ifactorial(k) * ifactorial(n - k)) % MOD


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

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

Submission status: Runtime Error

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


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

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

# Sn の位置をx = l-1,l,..,l+k-1まで全て動かす
# pow(25,x-l-1,MOD)* x-1Cl-1 * pow(26,l+k-1-x,MOD) をかければOK
ans = 0
for x in range(l - 1, l + k):
    ans += pow(25, x - l + 1, MOD) * comb(x, l - 1, MOD) * pow(26, l + k - 1 - x, MOD)
    ans %= MOD
print(ans)
"""
# dp[i][j]:k+l の長さの文字列の中で、長さi で、sのj番目の文字列まじで含む文字列の個数とする
# dp[i][j] = dp[i-1][j-1] + dp[i-1][j] * 25 となる
# これだと10**12でTLEなので、まとめる
# 答えたいのは、dp[k+l][l]で初期化はdp[1][1] = 1 dp[1][0] = 25
# l までいったら遷移の仕方が変わって*26を続けるだけで良いようになる
dp = [[0] * (l + 1) for _ in range(k + l + 1)]
dp[0][0] = 1
for i in range(1, k + l + 1):
    for j in range(l + 1):
        if j == l:
            dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j] * 26
        else:
            dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j] * 25
        dp[i][j] %= MOD
print(dp[k + l][l])
"""

Submission status: Runtime Error

Solution code:
from functools import lru_cache


@lru_cache
def factorial(n):
    if n == 0:
        return 1
    return n * factorial(n-1)


@lru_cache
def combination(n, k):
    return factorial(n) // factorial(k) // factorial(n - k)


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

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

Submission status: Runtime Error

Solution code:
from functools import lru_cache


@lru_cache
def factorial(n):
    if n == 0:
        return 1
    return (n * factorial(n-1)) % MOD


def combination(n, k):
    return factorial(n) // factorial(k) // factorial(n - k)


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

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

Submission status: Runtime Error

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

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

def make_tables(n, mod = 10 ** 9 + 7):
    fac = [1, 1] # 階乗テーブル
    finv = [1, 1] #逆元の階乗テーブル
    inv = [0, 1] #逆元テーブル

    for i in range(2, n + 1):
        fac.append((fac[-1] * i) % mod)
        inv.append((mod -inv[mod % i] * (mod // i)) % mod)
        finv.append((finv[-1] * inv[-1]) % mod)
    return fac, finv

def nCk(n, k, mod = 10 ** 9 + 7):
    k = min(k, n-k)
    return fac[n] * finv[k] * finv[n-k] % mod

##########################
fac, finv = make_tables(10**6 + 1)
ans = 0
for i in range(k + 1):
    temp = 1
    temp *= pow(26, i, mod)
    temp %= mod
    j = k - i
    if j == 0:
        ans += temp
        continue
    temp *= pow(25, j, mod)
    temp %= mod
    temp *= nCk(n + j - 1, n - 1)
    ans += temp
    ans %= mod
print(ans % mod)

Submission status: Runtime Error

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    K = int(readline())
    S = readline().strip()

    COM_MAX = 10 ** 6

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

    for i in range(2, COM_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 mod_com(n, r):
        if n < r:
            return 0
        if n < 0 or r < 0:
            return 0
        return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD

    M = len(S)
    L = K + M

    ans = 0
    p = pow(25, K + 1, MOD)
    for i in range(M - 1, -1, -1):
        ans += mod_com(L, i) * p
        p = p * 25 % MOD

    ans = (pow(26, L, MOD) - ans) % MOD
    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
mod = 10 ** 9 + 7

SIZE = 10 ** 6 + 1
fact = [0] * SIZE
inv = [0] * SIZE
finv = [0] * SIZE
fact[0], fact[1] = 1, 1
inv[1] = 1
finv[0], finv[1] = 1, 1
for i in range(2, SIZE):
    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 nCr(n, r):
    if n < 0 or r < 0 or n < r:
        return 0
    return fact[n] * (finv[r] * finv[n - r] % mod) % mod


k = int(input())
S = input()
s_length = len(S)
full_length = len(S) + k
ans = 0
for i in range(k+1):
    add = pow(26, i, mod) * pow(25, k-i, mod) * nCr(full_length-i-1, s_length-1) % mod
    ans = (ans + add) % mod

print(ans)

Submission status: Runtime Error

Solution code:
from math import factorial

def combinations_count(n, r):
    ''' 組み合わせ '''
    return factorial(n) // (factorial(n - r) * factorial(r))

#print(combinations_count(5, 2))
def modpow(a, n, MOD):
  res = 1
  while (n > 0):
    if (n & 1):
      res = res * a % MOD
    a = a * a % MOD
    n >>= 1
  return res

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

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

ans = 0
p = N + K - 1
#now = combinations_count(p, N - 1) % mod

for i in range(K + 1):
  p = N + K - i - 1
  now = cmb(p, N - 1, mod)
  a = pow(25, K - i, mod)
  b = pow(26, i, mod)
  c = a * b % mod
  ans += now * c % mod
  ans = ans % mod
print(ans)

Submission status: Runtime Error

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

mod = 10**9+7
ls = len(S)

dp = [[0]*(ls) for _ in range(K+ls)]
dp[0][0] = 1
dp[0][1] = 1

for i in range(1, K+ls):
    dp[i][0] = 1
    for j in range(1, ls):
        dp[i][j] = dp[i-1][j-1]+dp[i-1][j]

res = 1
for i in range(K+ls):
    res *= 26
    res %= mod

b = 1
for i in range(K):
    b *= 25
    b %= mod

for i, d in enumerate(dp[-1][::-1]):
    b *= 25
    b %= mod
    res -= d*b%mod

print(res%mod)

Submission status: Runtime Error

Solution code:
K = int(input())
S = len(input())

mod = int(1e9 + 7)

def memorize(f):
    dic = {}
    def main(*args):
        if args not in dic:
            dic[args] = f(*args)
        return dic[args]
    return main
    
# @memorize
def fpow(x, n):
    ret = 1
    tmp = x
    while n:
        if n & 1:
            ret = ret * tmp % mod
        tmp = tmp * tmp % mod
        n >>= 1
    return ret
    
# @memorize
def inv(x):
    return fpow(x, mod - 2)
    
@memorize
def fact(x):
    if x == 0:
        return 1
    return fact(x - 1) * x % mod
    
# @memorize
def C(n, m):
    return fact(n) * inv(fact(m)) * inv(fact(n - m)) % mod
    
ret = 0
for i in range(S, S + K + 1):
    ret = (ret + C(i - 1, i - S) * fpow(25, i - S) * fpow(26, S + K - i)) % mod
print(ret)

Submission status: Runtime Error

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

k=int(input())
s=input()
lens=len(s)
mod=10**9+7
ans=0

now=1

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

print(ans)

Submission status: Runtime Error

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

k = ni()
s = ns()
n = len(s)
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 = 10**6
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 = 0
for i in range(k+1):
    ans += cmb(n-1+i,i,mod)*pow(25,i,mod)%mod*pow(26,k-i,mod)%mod
    ans %= mod

print(ans)

Submission status: Runtime Error

Solution code:
K = int(input())
S = len(input())

mod = int(1e9 + 7)

def memorize(f):
    dic = {}
    def main(*args):
        if args not in dic:
            dic[args] = f(*args)
        return dic[args]
    return main
    
@memorize
def fpow(x, n):
    ret = 1
    tmp = x
    while n:
        if n & 1:
            ret = ret * tmp % mod
        tmp = tmp * tmp % mod
        n >>= 1
    return ret
    
@memorize
def inv(x):
    return fpow(x, mod - 2)
    
@memorize
def fact(x):
    if x == 0:
        return 1
    return fact(x - 1) * x % mod
    
@memorize
def C(n, m):
    return fact(n) * inv(fact(m)) * inv(fact(n - m)) % mod
    
ret = 0
for i in range(S, S + K + 1):
    ret = (ret + C(i - 1, i - S) * fpow(25, i - S) * fpow(26, S + K - i)) % mod
print(ret)

Submission status: Runtime Error

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

k=int(input())
s=input()
lens=len(s)
mod=10**9+7
ans=0


now=1

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

print(ans)

Submission status: Runtime Error

Solution code:
k = int(input())
s = input()
len_total = len(s)+k
i = len_total
tmp = 1
fac = 1
total = 0
for i in range(1,len_total):
    fac = fac * i % mod
    if i == len_total-1:
        tmp = tmp * fac %mod
    if i == len(s) - 1:
        tmp = tmp * pow(fac, mod-2, mod)
    if i == len_total - len(s):
        tmp = tmp * pow(fac, mod-2, mod)
for i in range(k):
    tmp*= 25
i = len_total
while i >= len(s):
    total = total + tmp
    tmp = (tmp * 26 * (i - len(s)) * pow(25*(i-1), mod-2, mod))%mod
    i -= 1
print(total%mod)

Submission status: Runtime Error

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

k = ni()
s = ns()
n = len(s)
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 = 10**3*3
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 = 0
for i in range(k+1):
    ans += cmb(n-1+i,i,mod)*pow(25,i,mod)%mod*pow(26,k-i,mod)%mod
    ans %= mod

print(ans)

Submission status: Runtime Error

Solution code:
k = int(input())
s = input()
len_total = len(s)+k
i = len_total
tmp = 1
fac = 1
for i in range(1,len_total):
    fac = fac * i % mod
    if i == len_total-1:
        tmp = tmp * fac %mod
    if i == len(s) - 1:
        print(i)
        tmp = tmp * pow(fac, mod-2, mod)
    if i == len_total - len(s):
        print(i)
        tmp = tmp * pow(fac, mod-2, mod)
for i in range(k):
    tmp*= 25
while i >= len(s):
    tmp = (tmp + 26 * (i - len(s)) * pow(25*(i-1), mod-2, mod))%mod
    i -= 1
print(tmp)

Submission status: Runtime Error

Solution code:
import numpy as np
k=int(input())
s=input()
ls=len(s)
r=(k+ls)**26
m=(k-ls)
a=np.array([range(m,26)])
m2== np.prod(a)
print(r-m2)

Submission status: Runtime Error

Solution code:
# import sys
# readline = sys.stdin.readline
# generator = (readline().strip() for _ in range(N))

# N, M = map(int, input().split())
# As = list(map(int, input().split()))
# queries = (input() for _ in range(N))


def solve():
    K = int(input())
    S = input()
    l = len(S)

    ans = 0

    for i in range(K):
        v = (25 ** l + i) / 24 % (10 ** 9 + 7)
        ans += v
        ans %= (10 ** 9 + 7)

    ans += K
    return ans


def main():
    print(solve())


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
K = int(input())
S = input()
SF = len(S)+1
A = 1
for x in range(K):
    A = A*(SF)*26
    SF = SF+1
print(A%((10**9)

Submission status: Runtime Error

Solution code:
from math import factorial

def combinations_count(n, r):
    ''' 組み合わせ '''
    return factorial(n) // (factorial(n - r) * factorial(r))

#print(combinations_count(5, 2))
def modpow(a, n, MOD):
  res = 1
  while (n > 0):
    if (n & 1):
      res = res * a % MOD
    a = a * a % MOD
    n >>= 1
  return res
 

K = int(input())
S = str(input())
mod = 10 ** 9 + 7
N = len(S)
L = N + K

ans = 0
p = N + K - 1
now = combinations_count(p, N - 1) % mod

for i in range(K + 1):
  a = pow(25, K - i, mod)
  b = pow(26, i, mod)
  c = a * b % mod
  ans += now * c % mod
  ans = ans % mod
  p -= 1
  now = int(now * (p - N + 1) / (p + 1)) % mod
print(ans)

Submission status: Runtime Error

Solution code:


# def main():
#     n = int(input())
#     al = list(map(int, input().split()))
#     all_xor = 0
#     for a in al:
#         all_xor = all_xor ^ a

#     ans = []
#     for a in al:
#         curr_ans = all_xor ^ a
#         ans.append(curr_ans)

#     print(*ans)


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


N_MAX = 2*(10**6)
MOD = 10**9 + 7
fac, finv, inv = [0]*N_MAX ,[0]*N_MAX, [0]*N_MAX
def com_init():
    fac[0], fac[1] = 1, 1
    finv[0], finv[1] = 1, 1
    inv[1] = 1
    for i in range(2, N_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 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 com(n, k):
    ans = 1
    for i in range(n-k+1,n+1):
        ans *= i
        ans %= MOD
    return (ans * finv[k]) % MOD


def main():
    k = int(input())
    s = input()
    n = len(s)

    com_init()

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

    print(ans%MOD)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import bisect, collections, copy, heapq, itertools, math, numpy, string
import sys
from bisect import bisect_left, bisect_right, insort
from collections import deque
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def MS(): return map(str, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
# N = I()
# A = [LI() for _ in range(N)]


k = I()
s = S()
p = 10**9 + 7
ans = pow(26,len(s) + k,p)
a = 0
aa = list(itertools.combinations_with_replacement(range(k),len(s)))
for i in range(len(aa)):
    ans -= pow(26,aa[i][0],p)
    for j in range(1,len(s)):
        ans -= pow(26,aa[i][i]-aa[i][i-1],p)
    ans -= pow(26,len(s) + k - aa[i][-1],p)
print(ans%p)

Submission status: Runtime Error

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

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

def make_tables(n, mod = 10 ** 9 + 7):
    fac = [1, 1] # 階乗テーブル
    finv = [1, 1] #逆元の階乗テーブル
    inv = [0, 1] #逆元テーブル

    for i in range(2, n + 1):
        fac.append((fac[-1] * i) % mod)
        inv.append((mod -inv[mod % i] * (mod // i)) % mod)
        finv.append((finv[-1] * inv[-1]) % mod)
    return fac, finv

def nCk(n, k, mod = 10 ** 9 + 7):
    k = min(k, n-k)
    return fac[n] * finv[k] * finv[n-k] % mod

##########################
fac, finv = make_tables(10**6)
ans = 1
for i in range(k + 1):
    temp = 1
    temp *= 26**i
    temp %= mod
    j = k - i
    if j == 0:
        ans += temp
        continue
    temp *= 25**j
    temp %= mod
    temp *= nCk(j - 1 + len(s), j - 1)
    ans += temp
    ans %= mod
print(ans)

Submission status: Runtime Error

Solution code:
# import sys
# readline = sys.stdin.readline
# generator = (readline().strip() for _ in range(N))

# N, M = map(int, input().split())
# As = list(map(int, input().split()))
# queries = (input() for _ in range(N))


def solve():
    K = int(input())
    S = input()
    l = len(S)

    ans = 0
    
    for i in range(K):
        v = (25 ** l + i) / 24 % (10 ** 9 + 7)
        ans += v
        ans %= (10 ** 9 + 7)

    ans += K
    return


def main():
    print(solve())


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

K = I()
S = LI2()
s = len(S)
mod = 10**9+7

dp1 = [0]*(K+s)
dp2 = [0]*(K+s)

for i in range(K+s):
    if i == s-1:
        dp1[i] = pow(26,i,mod)-1
    elif i == s:
        dp2[i] = pow(26,i,mod)-1
    else:
        dp1[i] = dp1[i-1]*26+dp2[i-1]*25
        dp1[i] %= mod
        dp2[i] = dp2[i-1]*26 + dp1[i-1]*25
        dp2[i] %= mod



print((dp1[K+s-1]*26 + (dp2[K+s-1]-dp1[K+s-1])*25) % mod)

Submission status: Runtime Error

Solution code:
def fact(n):
  if n==0 or n==1:
    return 1
  else:
    return n*fact(n-1)
n=int(input())
s=input()

print(fact(len(s))*fact(n)*fact(len(s)+n))

Submission status: Runtime Error

Solution code:
from math import factorial

def combinations_count(n, r):
    ''' 組み合わせ '''
    return factorial(n) // (factorial(n - r) * factorial(r))

#print(combinations_count(5, 2))
def modpow(a, n, MOD):
  res = 1
  while (n > 0):
    if (n & 1):
      res = res * a % MOD
    a = a * a % MOD
    n >>= 1
  return res
 

K = int(input())
S = str(input())
mod = 10 ** 9 + 7
N = len(S)
L = N + K

ans = 0
p = N + K - 1
now = combinations_count(p, N - 1) % mod

for i in range(K + 1):
  a = pow(25, K - i, mod)
  b = pow(26, i, mod)
  c = a * b % mod
  ans += now * c % mod
  ans = ans % mod
  p -= 1
  now = int(now * (p - N + 2) / (p + 1)) % mod
print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
from functools import lru_cache
sys.setrecursionlimit(1_000_002)

MOD = 1000000007  # type: int

@lru_cache(maxsize=None)
def f(k, n):
    if k == 0:
        return 1
    if n == 0:
        return pow(26, k, MOD)
    return (25 * f(k-1, n) + f(k, n-1)) % MOD

def solve(K: int, S: str):
    return f(K, len(S))

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    print(solve(K, S))

def test():
    import doctest
    doctest.testmod()

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

Submission status: Runtime Error

Solution code:
import numpy as np

import math
K = int(input())
S = input()  
ans = (26)**K*math.factorial(K+len(S))/math.factorial(K)/math.factorial(len(S))

print(int(ans)%(10**9+7))

Submission status: Runtime Error

Solution code:
k=int(input())
s=input()
i=0
for j in range(k):
  i=i+((len(s)+1)*26)
  len(s)=len(s)+1
print(i)

Submission status: Runtime Error

Solution code:
import numpy as np

mod = 10 ** 9 + 7

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


def count(length, str_length):
    dp = np.zeros((length + 1, str_length + 1), dtype=np.int64)  # (length, str_length)
    dp[:, 0] = (26 ** np.arange(length + 1)) % mod
    for i in range(str_length + 1):
        dp[i, i] = 1
    dp[0] = 0
    for l in range(1, length + 1):
        for s in range(1, min(l, str_length + 1)):
            dp[l, s] = (dp[l - 1, s - 1] + 25 * dp[l - 1, s]) % mod
    return dp[length, str_length]


print(count(len(S) + K, len(S)))

Submission status: Runtime Error

Solution code:
K = int(input())
S = len(list(input()))

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

print(cmb(K+S, S, p) * (26 ** K) % p)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
K = int(input())
S = list(input())[: -1]
mod = 10 ** 9 + 7

class Factorial:
  def __init__(self, n, mod):
    self.f = [1]
    for i in range(1, n + 1):
      self.f.append(self.f[-1] * i % mod)
    self.i = [pow(self.f[-1], mod - 2, mod)]
    for i in range(1, n + 1)[: : -1]:
      self.i.append(self.i[-1] * i % mod)
    self.i.reverse()
  def factorial(self, i):
    return self.f[i]
  def ifactorial(self, i):
    return self.i[i]
  def combi(self, n, k):
    return self.f[n] * self.i[n - k] % mod * self.i[k] % mod
###
f = Factorial(10 ** 5 * 3, mod)
res = 0
for i in range(K + 1):
  #i ko migi soto
  t = f.combi(len(S) - 1 + K - i, len(S) - 1) * pow(25, K - i, mod) % mod
  t = t * pow(26, i, mod) % mod
  res += t
  res %= mod
print(res)

Submission status: Runtime Error

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

mod = 10**9+7
ls = len(S)

dp = [[0]*(ls) for _ in range(K+ls)]
dp[0][0] = 25
dp[0][1] = 1

for i in range(1, K+ls):
    dp[i][0] = dp[i-1][0]*25%mod
    for j in range(1, ls):
        dp[i][j] = dp[i-1][j-1] + dp[i-1][j]*25%mod

res = 1
for i in range(K+ls):
    res *= 26
    res %= mod

for d in dp[-1]:
    res -= d
    res %= mod

print(res)

Submission status: Runtime Error

Solution code:
k = int(input())
s = input()
l = len(s)
MOD = 10 ** 9 + 7
# 余事象でs が部分文字列として含まれない K + len(s)文字列の個数を求める
total = pow(26, k + l, MOD)
# dp[i][j]:k+l の長さの文字列の中で、長さi で、sのj番目の文字列まじで含む文字列の個数とする
# dp[i][j] = dp[i-1][j-1] + dp[i-1][j] * 25 となる
# これだと10**12でTLEなので、まとめる
# 答えたいのは、dp[k+l][l]で初期化はdp[1][1] = 1 dp[1][0] = 25
# l までいったら遷移の仕方が変わって*26を続けるだけで良いようになる
dp = [[0] * (l + 1) for _ in range(k + l + 1)]
dp[1][1] = 1
dp[1][0] = 25
for i in range(k + l + 1):
    for j in range(l + 1):
        if j == l:
            dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j] * 26
        else:
            dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j] * 25
        dp[i][j] %= MOD
total = total + MOD - dp[k + l][l]
print(total % MOD)

Submission status: Runtime Error

Solution code:
"""
import sys

sys.setrecursionlimit(10 ** 7)

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

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

MOD = 10 ** 9 + 7

LS = len(S)
if K == 0:
    print(1)
    exit()

L = LS + K
DP = [[0] * (LS + 1) for _ in range(L + 10)]
DP[0][0] = 1

for i in range(L + 1):
    for j in range(LS + 1):
        if j < LS:
            DP[i + 1][j] += DP[i][j] * 25
        else:
            DP[i + 1][j] += DP[i][j] * 26

        if j >= 1:
            DP[i + 1][j] += DP[i][j - 1]

        DP[i + 1][j] %= MOD


print(DP[L][LS])

Submission status: Runtime Error

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
from decimal import *
import heapq
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

#コンビネーション
def cmb(n, r):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % mod

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

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

pw = [1]
for i in range(N):
    pw.append((pw[-1] * 26) % mod)

def solv(n):
    res = pw[n]
    for i in range(1, n // l + 1):
        res -= cmb(n, l * i) * solv(n - l * i)
    #print(res)
    res %= mod
    return res

k = INT()
s = STR()
l = len(s)
ans = 0
for i in range(1, (k + l) // l + 1):
    tmp = cmb(k + l, l * i)
    #print(' ', i, tmp)
    tmp *= solv(k + l - l * i)
    #print(' ', i, tmp, solv(k + l - l * i))
    tmp %= mod
    ans += tmp
    ans %= mod
print(ans)

Submission status: Runtime Error

Solution code:
K = int(input())
S = input()
SF = len(S)+1
A = 1
for x in range(K):
    A = A*(SF)*26
    SF = SF+1
print(A%(

Submission status: Runtime Error

Solution code:
K = int(input())
S = input()
SF = len(S)+1
A = 1
for x in range(K):
    A = A*(SF)*26
    SF = SF+1
    #print(A)
print(A%

Submission status: Runtime Error

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

K = int(input())
S = str(input())
mod = 10**9+7
lens = len(S)
length = lens+K

L = 1
pow_dic = {}
pow_dic[0] = 1
for i in range(1, 10**6+1000):
    L = L*i%mod
    pow_dic[i] = L
ans = 0
for rest in range(K+1):
    lenall = length-rest-1
    nlens = lens-1
    l = pow_dic[lenall]*pow(pow_dic[lenall-nlens], mod-2, mod)%mod
    r = pow_dic[nlens]
    comb = l*pow(r, mod-2, mod)%mod
    ans += pow(25, K-rest, mod)*pow(26, rest, mod)*comb%mod
    ans %= mod
print(ans%mod)