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: Wrong Answer

Solution code:
from operator import mul
from functools import reduce


def ccnt(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


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

ans = 0

for i in range(length, length + k + 1):
    ans += ccnt(i - 1, length - 1) * pow(25, i - length, MOD) * pow(26, length + k - i, MOD) % MOD

print(ans)

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce


def ccnt(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


k = 5
s = "oof"
length = len(s)
MOD = 10**9 + 7

ans = 0

for i in range(length, length + k + 1):
    ans += ccnt(i - 1, length - 1) * pow(25, i - length, MOD) * pow(26, length + k - i, MOD) % MOD

print(ans)

Submission status: Wrong Answer

Solution code:
from numba import njit, i8
import numpy as np


def main():
    mod = 10**9+7
    k = int(input())
    n = len(input())

    @njit(i8[:](i8, i8), cache=True)
    def num_calc(n, mod):
        fact = np.ones(n+1, dtype=np.int64)
        for i in range(2, n+1):
            fact[i] = fact[i-1]*i % mod
        return fact

    @njit(i8[:](i8, i8), cache=True)
    def num_calc2(k, mod):
        power = np.ones(k+1, dtype=np.int64)
        for i in range(1, k+1):
            power[i] = power[i-1]*25 % mod
        return power

    @njit(i8(i8, i8, i8), cache=True)
    def pow(n, k, mod=10**9+7):
        l, now = np.ones(64, np.int64), 1
        l[0] = n
        for i in range(1, 64):
            l[i] = l[i-1]*l[i-1] % mod
        for i in range(64):
            if k & 1:
                now = now*l[i] % mod
            k >>= 1
        return now

    fact = num_calc(n+k, mod)
    nk = fact[n+k]
    fact = fact[n+k:n-1:-1]*fact[:k+1] % mod
    power = (num_calc2(k, mod)*nk) % mod

    print(sum([pow(i, mod-2, mod)*j for i, j in zip(fact, power)]) % mod)


main()

Submission status: Wrong Answer

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

m = 1000000007

result = 0
t = pow(26, K, m)
u = pow(26, -1, m) * 25 % m
l = len(S)
for i in range(K + 1):
    # result += pow(26, K - i, m) * mcomb(len(S) - 1 + i, i) * pow(25, i, m)
    result += (result + t) % m
    t = (t * u) % m * (l + i) %m * pow(i + 1, -1, m) % m
print(result)

Submission status: Wrong Answer

Solution code:
# フェルマーの小定理
def main():
    from builtins import pow

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

    m = 1000000007

    result = 0
    t = pow(26, K, m)
    u = pow(26, m - 2, m) * 25 % m
    l = len(S)
    for i in range(K + 1):
        # result += pow(26, K - i, m) * mcomb(len(S) - 1 + i, i) * pow(25, i, m)
        result += t
        result %= m
        t *= u
        t %= m
        t *= (l + i)
        t %= m
        t *= pow(i + 1, m - 2, m)
        t %= m
    print(result)

Submission status: Wrong Answer

Solution code:
# フェルマーの小定理
def main():
    from builtins import len, pow

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

    m = 1000000007

    result = 0
    a = 1
    b = 1
    t = pow(26, K, m)
    u = pow(26, m - 2, m) * 25 % 26
    for i in range(K + 1):
        # result += pow(26, K - i, m) * mcomb(len(S) - 1 + i, i) * pow(25, i, m)
        result += t * (a * pow(b, m - 2, m))
        result %= m
        t *= u
        t %= m
        a *= len(S) - 1 + (i + 1)
        a %= m
        b *= i + 1
        b %= m
    print(result)


main()

Submission status: Wrong Answer

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

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

def cmb(n, r):
  return fac[n] * ( finv[r] * finv[n-r] % mod ) % mod

p25 = [1]
p26 = [1]

for i in range(K):
  p25.append(p25[i]*25%mod)
  p26.append(p26[i]*26%mod)

ans = 0

for i in range(K+1):
  ans += cmb(s+K-i-1, s-1) * p25[K-i] % mod * p26[i] % mod

print(ans)

Submission status: Wrong Answer

Solution code:
m = 10**9 + 7
k = int(input())
s = input()

# k, s = 5, 'oof'
# k, s = 37564, 'whydidyoudesertme'
l = len(s) + 1
ans = 1
for i in range(k):
    ans = ans * (l + i) * 26 % m
print(ans)

Submission status: Wrong Answer

Solution code:
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readline
mod = 10 ** 9 +7
    
K = int(readline())
S = readline().decode()
s = len(S)-1

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

def comb(n,r):
  return fact[n] * fact_inv[r] * fact_inv[n-r] % mod

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

Submission status: Wrong Answer

Solution code:
K=10**6
N=10**6
mod=10**9+7

fact=[1]*(K+N)
for i in range(2,K+N):
    fact[i]=fact[i-1]*i%mod
    
inv=[1]*(K+N)
inv[K+N-1]=pow(fact[K+N-1],mod-2,mod)
for i in range(K+N-2,-1,-1):
    inv[i]=inv[i+1]*(i+1)%mod
    
def comb(n,r):
    ret=fact[n]*inv[r]*inv[n-r]%mod
    return ret

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

print(ans)

Submission status: Wrong Answer

Solution code:

Submission status: Wrong Answer

Solution code:
k = int(input())
s = str(input())
big = 10**9+7
ans = 1
f = len(s)
for i in range(k):
  ans = (ans*26*(f+1))
  f += 1
ans = ans%big
print(ans)

Submission status: Wrong Answer

Solution code:
mod = 10**9 + 7
K = int(input())
S = input()
n = len(S)
tmp = pow(26, K, mod)
waru = pow(26, -1, mod)
ans = tmp
for i in range(1, K+1):
    tmp = (tmp * 25 // waru)%mod
    tmp = (tmp * (i + n -1) // pow(i, -1, mod))%mod
    ans = (ans+tmp)%mod
print(ans%mod)

Submission status: Wrong Answer

Solution code:
mod = 10**9 + 7
K = int(input())
S = input()
n = len(S)
tmp = pow(26, K, mod)
waru = pow(26, -1)
ans = tmp
for i in range(1, K+1):
    tmp = (tmp * 25 // 26)%mod
    tmp = (tmp * (i + n -1) // i)%mod
    ans = (ans+tmp)%mod
print(ans%mod)

Submission status: Wrong Answer

Solution code:
mod = pow(10, 9) + 7
K = int(input())
S = input()
n = len(S)
tmp = pow(26, K, mod)
waru = pow(26, -1)
ans = tmp
for i in range(1, K+1):
    tmp = (tmp * 25 * waru)%mod
    tmp = (tmp * (i + n -1) * pow(i, -1))%mod
    ans = (ans+tmp)%mod
print(int(ans%mod))

Submission status: Wrong Answer

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

#output
# (o以外) o (o以外) o (f以外) f (何でも)

#こちらもmodで割った余り。maxが決まっていて、大きくない時はこちらが早い。
mod = pow(10, 9) + 7

n_ = 5 * pow(10, 6)
fun = [1] * (n_+1)
for i in range(1, n_+1):
    fun[i] = fun[i-1] * i % mod
rev = [1] * (n_+1)
rev[n_] = pow(fun[n_], mod-2, mod)
for i in range(n_-1, 0, -1):
    rev[i] = rev[i+1] * (i+1) % mod
def cmb(n,r):
    if n <= 0 or r < 0 or r > n: return 0
    return fun[n] * rev[r] % mod * rev[n-r] % mod

#重複組み合わせはH(n, r) = cmb(n+r-1, r)

L = len(S)
answer = 0
for i in range(L, L+K+1):
    answer += pow(25, i-L, mod) * pow(26, L+K-i, mod) * cmb(i-1, L-1)
    answer %= mod
print(answer)

Submission status: Wrong Answer

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

#output
# (o以外) o (o以外) o (f以外) f (何でも)

#こちらもmodで割った余り。maxが決まっていて、大きくない時はこちらが早い。
mod = pow(10, 9) + 7

n_ = 5 * pow(10, 6)
fun = [1] * (n_+1)
for i in range(1, n_+1):
    fun[i] = fun[i-1] * i % mod
rev = [1] * (n_+1)
rev[n_] = pow(fun[n_], mod-2, mod)
for i in range(n_-1, 0, -1):
    rev[i] = rev[i+1] * (i+1) % mod
def cmb(n,r):
    if n <= 0 or r < 0 or r > n: return 0
    return fun[n] * rev[r] % mod * rev[n-r] % mod

#重複組み合わせはH(n, r) = cmb(n+r-1, r)

L = len(S)
answer = 0
for i in reversed(range(K+1)):
    answer += pow(25, K-i, mod) * pow(26, i, mod) * cmb(L+K-1-i, L-1)
    answer %= mod
print(answer)

Submission status: Wrong Answer

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

#output
# (o以外) o (o以外) o (f以外) f (何でも)

#こちらもmodで割った余り。maxが決まっていて、大きくない時はこちらが早い。
mod = pow(10, 9) + 7

n_ = 2 * pow(10, 6) + 1
fun = [1] * (n_+1)
for i in range(1, n_+1):
    fun[i] = fun[i-1] * i % mod
rev = [1] * (n_+1)
rev[n_] = pow(fun[n_], mod-2, mod)
for i in range(n_-1, 0, -1):
    rev[i] = rev[i+1] * (i+1) % mod
def cmb(n,r):
    if n <= 0 or r < 0 or r > n: return 0
    return fun[n] * rev[r] % mod * rev[n-r] % mod

#重複組み合わせはH(n, r) = cmb(n+r-1, r)

L = len(S)
answer = 0
for i in reversed(range(K+1)):
    answer += pow(25, K-i, mod) * pow(26, i, mod) * cmb(L+K-1-i, L-1)
    answer %= mod
print(answer)

Submission status: Wrong Answer

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

#output
# (o以外) o (o以外) o (f以外) f (何でも)

#こちらもmodで割った余り。maxが決まっていて、大きくない時はこちらが早い。
mod = pow(10, 9) + 7

n_ = 2 * pow(10, 6) + 1
fun = [1] * (n_+1)
for i in range(1, n_+1):
    fun[i] = fun[i-1] * i % mod
rev = [1] * (n_+1)
rev[n_] = pow(fun[n_], mod-2, mod)
for i in range(n_-1, 0, -1):
    rev[i] = rev[i+1] * (i+1) % mod
def cmb(n,r):
    if n <= 0 or r < 0 or r > n: return 0
    return fun[n] * rev[r] % mod * rev[n-r] % mod

#重複組み合わせはH(n, r) = cmb(n+r-1, r)

N = len(S)
answer = 0
for i in range(K+1):
    answer += pow(25, K-i, mod) * pow(26, i, mod) * cmb(N+K-i-1, N-1)
    answer %= mod
print(answer % mod)

Submission status: Wrong Answer

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

#output
# (o以外) o (o以外) o (f以外) f (何でも)

#こちらもmodで割った余り。maxが決まっていて、大きくない時はこちらが早い。
mod = pow(10, 9) + 7

n_ = 2 * pow(10, 6) + 1
fun = [1] * (n_+1)
for i in range(1, n_+1):
    fun[i] = fun[i-1] * i % mod
rev = [1] * (n_+1)
rev[n_] = pow(fun[n_], mod-2, mod)
for i in range(n_-1, 0, -1):
    rev[i] = rev[i+1] * (i+1) % mod
def cmb(n,r):
    if n <= 0 or r < 0 or r > n: return 0
    return fun[n] * rev[r] % mod * rev[n-r] % mod

#重複組み合わせはH(n, r) = cmb(n+r-1, r)

N = len(S)
answer = 0
for i in range(K+1):
    answer += pow(25, K-i, mod) * pow(26, i, mod) * cmb(N+K-i-1, K-i)
    answer %= mod
print(answer)

Submission status: Wrong Answer

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

#output
# (o以外) o (o以外) o (f以外) f (何でも)

#こちらもmodで割った余り。maxが決まっていて、大きくない時はこちらが早い。
mod = pow(10, 9) + 7

n_ = 2 * pow(10, 6) + 1
fun = [1] * (n_+1)
for i in range(1, n_+1):
    fun[i] = fun[i-1] * i % mod
rev = [1] * (n_+1)
rev[n_] = pow(fun[n_], mod-2, mod)
for i in range(n_-1, 0, -1):
    rev[i] = rev[i+1] * (i+1) % mod
def cmb(n,r):
    if n <= 0 or r < 0 or r > n: return 0
    return fun[n] * rev[r] % mod * rev[n-r] % mod

#重複組み合わせはH(n, r) = cmb(n+r-1, r)

N = len(S)
answer = 0
for i in range(K+1):
    answer += pow(25, i, mod) * pow(26, K-i, mod) * cmb(N-1+i, N-1)
    answer %= mod
print(answer)

Submission status: Wrong Answer

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

#output
# (o以外) o (o以外) o (f以外) f (何でも)

#こちらもmodで割った余り。maxが決まっていて、大きくない時はこちらが早い。
mod = pow(10, 9) + 7

n_ = 2 * pow(10, 6) + 1
fun = [1] * (n_+1)
for i in range(1, n_+1):
    fun[i] = fun[i-1] * i % mod
rev = [1] * (n_+1)
rev[n_] = pow(fun[n_], mod-2, mod)
for i in range(n_-1, 0, -1):
    rev[i] = rev[i+1] * (i+1) % mod
def cmb(n,r):
    if n <= 0 or r < 0 or r > n: return 0
    return fun[n] * rev[r] % mod * rev[n-r] % mod

#重複組み合わせはH(n, r) = cmb(n+r-1, r)

N = len(S)
answer = 0
for i in range(K+1):
    answer += pow(25, i, mod) * pow(26, K-i, mod) * cmb(N-1+i, i)
    answer %= mod
print(answer)

Submission status: Wrong Answer

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

#output
# (o以外) o (o以外) o (f以外) f (何でも)

#こちらもmodで割った余り。maxが決まっていて、大きくない時はこちらが早い。
mod = pow(10, 9) + 7

n_ = 2 * pow(10, 6) + 5
fun = [1] * (n_+1)
for i in range(1, n_+1):
    fun[i] = fun[i-1] * i % mod
rev = [1] * (n_+1)
rev[n_] = pow(fun[n_], mod-2, mod)
for i in range(n_-1, 0, -1):
    rev[i] = rev[i+1] * (i+1) % mod
def cmb(n,r):
    if n <= 0 or r < 0 or r > n: return 0
    return fun[n] * rev[r] % mod * rev[n-r] % mod

#重複組み合わせはH(n, r) = cmb(n+r-1, r)

N = len(S)
answer = 0
for i in range(K+1):
    answer += pow(25, i, mod) * pow(26, K-i, mod) * cmb(N-1+i, i)
    answer %= mod
print(answer % mod)

Submission status: Wrong Answer

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

#output
# (o以外) o (o以外) o (f以外) f (何でも)

#こちらもmodで割った余り。maxが決まっていて、大きくない時はこちらが早い。
mod = pow(10, 9) + 7

n_ = 2 * pow(10, 6) + 5
fun = [1] * (n_+1)
for i in range(1, n_+1):
    fun[i] = fun[i-1] * i % mod
rev = [1] * (n_+1)
rev[n_] = pow(fun[n_], mod-2, mod)
for i in range(n_-1, 0, -1):
    rev[i] = rev[i+1] * (i+1) % mod
def cmb(n,r):
    if n <= 0 or r < 0 or r > n: return 0
    return fun[n] * rev[r] % mod * rev[n-r] % mod

#重複組み合わせはH(n, r) = cmb(n+r-1, r)

N = len(S)
answer = 0
for i in range(K+1):
    answer += pow(25, i, mod) * pow(26, K-i, mod) * cmb(N-1+i, i)
    answer %= mod
print(answer)

Submission status: Wrong Answer

Solution code:
from scipy.special import comb, perm

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

n = len(S)

mod = 10**9 + 7

ans = 0
for i in range(K+1):
    now = pow(26, K-i, mod)
    now *= pow(26, i, mod)

    now *= comb(n+i-1, n-1, True)
    ans += now
    ans %= mod
    
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
from decimal import *

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	K = inputInt()
	S = inputStr()

	lenS = len(S)

	ans = 1
	for i in range(K):
		ans = (ans * ((26 * (lenS + 1 + i)) % mod)) % mod

	print(ans)



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

Submission status: Wrong Answer

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

#output
# (o以外) o (o以外) o (f以外) f (何でも)

#こちらもmodで割った余り。maxが決まっていて、大きくない時はこちらが早い。
mod = pow(10, 9) + 7

n_ = 2 * pow(10, 6) + 5
fun = [1] * (n_+1)
for i in range(1, n_+1):
    fun[i] = fun[i-1] * i % mod
rev = [1] * (n_+1)
rev[n_] = pow(fun[n_], mod-2, mod)
for i in range(n_-1, 0, -1):
    rev[i] = rev[i+1] * (i+1) % mod
def cmb(n,r):
    if n <= 0 or r < 0 or r > n: return 0
    return fun[n] * rev[r] % mod * rev[n-r] % mod

#重複組み合わせはH(n, r) = cmb(n+r-1, r)

N = len(S)
answer = 0
for i in range(K+1):
    answer += pow(25, i, mod) * pow(26, K-i, mod) * cmb(N-1+i, N-1) % mod
print(answer % mod)

Submission status: Wrong Answer

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

#output
# (o以外) o (o以外) o (f以外) f (何でも)

#こちらもmodで割った余り。maxが決まっていて、大きくない時はこちらが早い。
mod = pow(10, 9) + 7

n_ = 3 * pow(10, 6) + 1
fun = [1] * (n_+1)
for i in range(1, n_+1):
    fun[i] = fun[i-1] * i % mod
rev = [1] * (n_+1)
rev[n_] = pow(fun[n_], mod-2, mod)
for i in range(n_-1, 0, -1):
    rev[i] = rev[i+1] * (i+1) % mod
def cmb(n,r):
    if n <= 0 or r < 0 or r > n: return 0
    return fun[n] * rev[r] % mod * rev[n-r] % mod

#重複組み合わせはH(n, r) = cmb(n+r-1, r)

N = len(S)
answer = 0
for i in range(K+1):
    answer += pow(25, i, mod) * pow(26, K-i, mod) * cmb(N-1+i, N-1) % mod
print(answer % mod)

Submission status: Wrong Answer

Solution code:
import sys

def main():
    input = sys.stdin.readline
    mod = pow(10, 9)+7
    k = int(input())
    s = input()
    n = len(s)

    ans = 0
    key = pow(26, k)
    sub = 1
    c = 1
    for i in range(k+1):
        ans += key*sub*c
        ans %= mod
        sub *= 25
        sub %= mod
        key = key*pow(26, mod-2, mod)%mod
        c *= (n+i)
        c *= pow(i+1, mod-2, mod)
        c %= mod
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

#output
# (o以外) o (o以外) o (f以外) f (何でも)

#こちらもmodで割った余り。maxが決まっていて、大きくない時はこちらが早い。
mod = pow(10, 9) + 7

n_ = 2 * pow(10, 6) + 1
fun = [1] * (n_+1)
for i in range(1, n_+1):
    fun[i] = fun[i-1] * i % mod
rev = [1] * (n_+1)
rev[n_] = pow(fun[n_], mod-2, mod)
for i in range(n_-1, 0, -1):
    rev[i] = rev[i+1] * (i+1) % mod
def cmb(n,r):
    if n <= 0 or r < 0 or r > n: return 0
    return fun[n] * rev[r] % mod * rev[n-r] % mod

#重複組み合わせはH(n, r) = cmb(n+r-1, r)

N = len(S)
answer = 0
for i in range(K+1):
    answer += pow(25, i, mod) * pow(26, K-i, mod) * cmb(N-1+i, N-1) % mod
print(answer % mod)

Submission status: Wrong Answer

Solution code:
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readline
mod = 10 ** 9 +7
    
K = int(readline())
S = readline().decode()
s = len(S)-1

### nCrの前処理
n = s+K
fact = [1] * (n+1)
fact_inv = [1] * (n+1)
for i in range(1,n+1):
    fact[i] = fact[i-1] * i % mod 
fact_inv[n] = pow(fact[n],mod-2,mod)
for i in range(n,0,-1):
    fact_inv[i-1] = (i * fact_inv[i]) % mod 
### nCrの計算
def comb(n,r):
  return fact[n] * fact_inv[r] * fact_inv[n-r] % mod

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

Submission status: Wrong Answer

Solution code:
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readline
mod = 10 ** 9 +7
    
K = int(readline())
S = readline().decode()
s = len(S)-1

### nCrの前処理
n = s+K
fact = [1] * (n+1)
fact_inv = [1] * (n+1)
for i in range(1,n+1):
    fact[i] = fact[i-1] * i % mod 
fact_inv[n] = pow(fact[n],mod-2,mod)
for i in range(n,0,-1):
    fact_inv[i-1] = (i * fact_inv[i]) % mod 
### nCrの計算
def comb(n,r):
  return fact[n] * fact_inv[r] * fact_inv[n-r] % mod

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

Submission status: Wrong Answer

Solution code:
class Combination:
    def __init__(self, size, MOD):
        self.MOD = MOD
        self.size = size + 2

        f = 1
        self.fact = fact = [f]
        for i in range(1, size+1):
            f = f * i % MOD
            fact.append(f)
        f = pow(f, MOD-2, MOD)
        self.factInv = factInv = [f]
        for i in range(size, 0, -1):
            f = f * i % MOD
            factInv.append(f)
        factInv.reverse()

    def npr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * self.factInv[n - r] % self.MOD

    def ncr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * (self.factInv[r] * self.factInv[n - r] % self.MOD) % self.MOD

    def nhr(self, n, r):  # 重複組合せ: x_1 + ... + x_n = r
        return self.ncr(n + r - 1, n - 1)

def sol():
    K = int(input())
    N = len(input())
    MOD = 10**9 + 7
    comb = Combination(N + K + 10, MOD)

    ans = 0
    n = 1
    for l in range(K + 1):
        r = K - l
        ans += comb.nhr(N, l) * n# * pow(26, r, MOD)
        ans %= MOD
        n = n * 25 % MOD
    print(ans)
sol()

Submission status: Wrong Answer

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

com = [1]*(k+1)
p25 = [1]*(k+1)
p26 = [1]*(k+1)
for i in range(k):
  com[i+1] = com[i]*(L+i)//(i+1)%mod
  p25[i+1] = p25[i]*25%mod
  p26[i+1] = p26[i]*26%mod

ans = 0
for p in range(k+1):
  chk = 1
  chk *= p25[p]
  chk *= com[p]
  chk %= mod
  chk *= p26[k-p]
  chk %= mod
  ans += chk
  ans %= mod
  
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
from operator import mul
from functools import reduce

MOD = 10**9 + 7

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

def comb(m, n):
    if n == 0:
        return 1
    return reduce(mul, np.arange(m, m - n, -1)) // reduce(mul, np.arange(n, 0, -1))

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

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

K = int(sys.stdin.readline())
M = len(sys.stdin.readline())
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


X = Combi(N, mod)
for i in range(M):
    ans -= X.combi(N, i)*pow(25, N-i, mod)
    ans %= mod
print(ans)

Submission status: Wrong Answer

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

length = len(S)
length_all = K + length
ans = 0
list_25 = [1] * (10**6 + 5)
list_26 = [1] * (10**6 + 5)
for i in range(1,10**6 + 5):
  list_25[i] = list_25[i - 1] * 25 % MOD
  list_26[i] = list_26[i - 1] * 26 % MOD
  
fact = [1] * (2 * 10**6 + 5)
fact_inv = [1] * (2 * 10**6 + 5)
for i in range(1, 10**6 + 5):
  fact[i] = fact[i-1] * i % MOD
  fact_inv[i] = fact_inv[i - 1] * pow(i, MOD - 2, MOD) % MOD

for i in range(K + 1):
  ans += list_26[i] * list_25[K - i] % MOD * fact[length_all - i - 1] * fact_inv[length - 1] * fact_inv[K - i] % MOD

print(ans % MOD)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
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(N,mod)
for i in range(M):
    ans-=c.combi(N,i)*pow(25,N-i,mod)
    ans%=mod
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
input=sys.stdin.readline
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+10000,mod)
for i in range(M):
    ans-=c.combi(N,i)*pow(25,N-i,mod)
    ans%=mod
print(ans%mod)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
input=sys.stdin.readline
K=int(input())
S=input()
print(S)
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+10000,mod)
for i in range(M):
    ans-=c.combi(N,i)*pow(25,N-i,mod)
    ans%=mod
print(ans)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
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(readline())
print(main(K, N, MOD))

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
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[: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(readline())
print(main(K, N, MOD))

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
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, inv = fact_table(2_000_010, MOD)
    f = np.zeros(K + 1, np.int64)
    f = fac[N - 1:K + N] * finv[N - 1] % MOD * finv[: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(readline())
print(main(K, N, MOD))

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np
readline = sys.stdin.buffer.readline

MOD = 10 ** 9 + 7


def main(K, N, MOD):
    def cumprod(A, mod=MOD):
        L = len(A)
        Lsq = int(L**.5 + 1)
        A = np.resize(A, Lsq**2).reshape(Lsq, Lsq)
        for n in range(1, Lsq):
            A[:, n] *= A[:, n - 1]
            A[:, n] %= mod
        for n in range(1, Lsq):
            A[n] *= A[n - 1, -1]
            A[n] %= mod
        return A.ravel()[:L]

    def make_fact(U, mod=MOD):
        x = np.arange(U, dtype=np.int64)
        x[0] = 1
        fact = cumprod(x, mod)
        x = np.arange(U, 0, -1, dtype=np.int64)
        x[0] = pow(int(fact[-1]), mod - 2, mod)
        fact_inv = cumprod(x, mod)[::-1]
        fact.flags.writeable = False
        fact_inv.flags.writeable = False
        return fact, fact_inv

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

K = int(readline())
N = len(readline())
print(main(K, N, MOD))

Submission status: Wrong Answer

Solution code:
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 = 1
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)