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:
def main():
    import sys
    input = sys.stdin.readline
    K = int(input())
    S = input().rstrip()
    mod = 10**9 + 7
    ans = 1
    for i in range(len(S)+K):
        ans *= 26
        ans %= mod
    dp = [0] * (len(S)+K+1)
    x = 1
    for i in range(len(S)):
        dp[i] = x
        x *= 26
        x %= mod
    for i in range(len(S), len(S)+K+1):
        dp[i] = (26*(dp[i-1]-dp[i-len(S)])%mod + (dp[i-len(S)]*25)%mod) % mod
    ans -= dp[len(S)+K]
    ans %= mod
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

mod = 10 ** 9 + 7


def main():
    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 * 10**6 + 10, mod)
    k = int(readline())
    s = readline()
    lens = len(s)
    f = np.zeros(k + 1, np.int64)
    f = fac[lens - 1:k + lens] * finv[lens - 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

    print(f[-1])


if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
K = int(input())
M = len(input())
N = M + K

MOD = 10 ** 9 + 7
factorial = [1] * (N + 1)
inverse = [1] * (N + 1)
for x in range(1, N + 1):
    factorial[x] = factorial[x - 1] * x % MOD
inverse[N] = pow(factorial[N], MOD-2, MOD)
for x in range(N - 1, -1, -1):
    inverse[x] = inverse[x + 1] * (x + 1) % MOD

def binomail(n, k):
    return factorial[n] * inverse[n - k] % MOD * inverse[k] % MOD

mod_expo = pow(25, M, MOD)
ans = 0
for k in range(M, N + 1):
    ans += binomail(N, k) * mod_expo
    ans %= MOD
    mod_expo = (mod_expo * 25) % MOD
print(ans)

Submission status: Wrong Answer

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

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

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

pwr = pow(25, M, MOD)
ans = 0
for k in range(M, N + 1):
    ans += binom(N, k) * pwr
    ans %= MOD
    pwr = (pwr * 25) % MOD
print(ans)

Submission status: Wrong Answer

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

mod = 10 ** 9 + 7


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


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


fac, finv = make_fact(2 * 10**6 + 10, mod)
k = int(readline())
s = readline()
lens = len(s)

pow25 = [pow(25, i, mod) for i in range(k + 1)]
pow26 = [pow(26, i, mod) for i in range(k + 1)]

res = 0
for i in range(k + 1):
  res += (pow26[i] * pow25[k - i] % mod) * comb(lens + k - i - 1, lens - 1)
  res %= mod
print(res)

Submission status: Wrong Answer

Solution code:
import copy
import sys
input = sys.stdin.readline

def com(n,r,m):
    #a = math.factorial(n)%m
    a = 1
    for i in range(1,n+1):
        a *= i
        a %= m
    A = pow(a,m-2,m)
    
    
    b= copy.copy(A)   
    for i in range(n,r,-1):
        b = (b*i)%m
    
    c = copy.copy(A)
    for i in range(n,n-r,-1):
        c = (c*i)%m
       
    return (a*b*c)%m

def main():
    k = int(input())
    s = input()
    mod = 10**9+7
    z = [1]
    for i in range(1,k+1):
        y = z[-1]*26
        z.append(y%mod)
    l = len(s)

    N = k+2
    inv_t = [0]+[1]
    for i in range(2,N):
        inv_t.append(inv_t[mod % i] * (mod - int(mod / i)) % mod)
    #print(inv_t)
    
    ans = 0
    p = 1   #pow(25,i-len(s),mod)
    q = z[k]
    bai = 1
    for i in range(l,l+k+1):
        #base = p*q   #pow(26,len(s)+k-i,mod)
        #base = pow(25,i-len(s),mod) * pow(26,len(s)+k-i,mod)
        #bai = r
        #bai = com(i-1,len(s)-1,mod)
        #print(i,len(s),base,bai)
        ans += p*q*bai
        ans %= mod
        p *= 25
        q = z[l+k-i-1]
        bai = bai*i*inv_t[i+1-l]
        bai %= mod
    print(ans)
    
if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
from scipy.special import comb
input = sys.stdin.readline

K = int(input())
S = input()
s = len(S)
div_n = 10**9+7

c = 0
for i in range(0, K+1):
    c += ((comb(K-i+s-1, K-i, exact=True)%div_n)*((25**(K-i))%div_n)*((26**(i))%div_n))%div_n
print(c%div_n)

Submission status: Wrong Answer

Solution code:
MOD = 10 ** 9 + 7
K = int(input())
M = len(input())
N = M + K
fac = [1] * (N + 1)
inv = [1] * (N + 1)
for x in range(1, N + 1):
    fac[x] = fac[x - 1] * x % MOD
inv[N] = pow(fac[N], MOD-2, MOD)
for x in range(N - 1, -1, -1):
    inv[x] = inv[x + 1] * (x + 1) % MOD
def binom(n, k):
    return fac[n] * inv[n - k] % MOD * inv[k] % MOD
pwr = pow(25, M, MOD)
ans = 0
for k in range(M, N + 1):
    ans += binom(N, k) * pwr
    ans %= MOD
    pwr = (pwr * 25) % MOD
print(ans)

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:
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:
k=int(input())
s=input()

MOD = 1000000007

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



nagasa=len(s)
print(nagasa)
ans=1
for i in range(k):
  f=factorization(nagasa)
  print(f)
  hiku=0
  for j in range(len(f)):
    hiku = hiku + (f[j][1]-1)
  print(hiku)
  ans = ans*(nagasa*25+26-ans*(nagasa+1)-hiku) % MOD
  nagasa+=1
print(ans)

Submission status: Wrong Answer

Solution code:
k=int(input())
s=input()
l=len(s)
mod=10**9+7
ans=1
for i in range(k):
    ans=ans*26+pow(25,i+1,mod)*(l+i)*(l-1+i)//2
    ans%=mod
print(ans)

Submission status: Wrong Answer

Solution code:
l = int(input())
s = input()
k = len(s)
def make_array_for_comb(N, mod=10**9+7):
    fact = [1,1]
    fact_inv = [1,1]
    inv = [0,1]
    for i in range(2, N+1):
        fact.append((fact[-1]*i) % mod)
        # モジュラ逆数の性質
        inv.append((-inv[mod%i] * (mod//i)) % mod)
        fact_inv.append((fact_inv[-1]*inv[i]) % mod)
    return fact, fact_inv

def comb(n, r, mod=10**9+7):
  if (r < 0) or (n < r):
      return 0
  r = min(r, n - r)
  return fact[n] * fact_inv[r] * fact_inv[n-r] % mod

mod = 10**9+7
ans = 1
for p in range(k-1,l+k):
  fact, fact_inv = make_array_for_comb(p,mod)
  ans *= pow(25,p-(k-1),mod)
  ans *= comb(p,k-1,mod)
  ans %= mod
  ans *= pow(26,l+k-1-p,mod)
  ans %= mod
  
print(ans%mod)

Submission status: Wrong Answer

Solution code:
s = [input() for i in range(2)]
l0 = int(s[0])
l1 = len(s[1])
print(l0)
print(l1)

c = 0
# l = 0
# for i in range(l0):
#     l1 = l1 +1

l = sum([i for i in range(l1+1, l1+1+l0+1)])
# l = sum(range(l1+1, l1+1+l0+1))
#print(l)
#     c = 26 ** l1
#print(pow(26,l,(10 ** 9 + 7)))
print(c % (10 ** 9 + 7))

Submission status: Wrong Answer

Solution code:
MOD = 10**9 + 7


def main():
    from string import ascii_lowercase
    from collections import Counter
    dic = {i: a for i, a in enumerate(ascii_lowercase)}
    K = int(input())
    S = input()
    N = len(S)
    c = Counter(S)
    pre = 1
    dp = [1]*26
    for i in range(N+1, N+1+K):
        sumv = 0
        for j in range(26):
            v = i
            ch = dic[j]
            sub = (dp[j] - 1)
            for k in range(i - N):
                sub += 1
            v -= c[ch] + sub
            sumv += pre*v
            dp[j] = pre*v
        pre = sumv
    print(sumv % MOD)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n = 10 ** 9
k = 2 * 10 ** 5
mod = 10**9 + 7

# x ** a をmodで割った余りを、O(log(a))時間で求める。
def power(x, a):
    if a == 0:
        return 1
    elif a == 1:
        return x
    elif a % 2 == 0:
        return power(x, a//2) **2 % mod
    else:
        return power(x, a//2) **2 * x % mod

# xの逆元を求める。フェルマーの小定理より、 x の逆元は x ^ (mod - 2) に等しい。計算時間はO(log(mod))程度。
# https://qiita.com/Yaruki00/items/fd1fc269ff7fe40d09a6
def modinv(x):
    return power(x, mod-2)

def binomial_coefficients(n, k):
    numera = 1  # 分子
    denomi = 1  # 分母

    for i in range(k):
        numera *= n-i
        numera %= mod
        denomi *= i+1
        denomi %= mod
    return numera * modinv(denomi) % mod

print(binomial_coefficients(n, k))

K=int(input())
S=input()
M=len(S)
ans=0
for j in range(K-M):
    ans+=binomial_coefficients(25,j)%mod
print(ans%mod)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import numpy as np
from numba import njit


def read():
    K = int(input().strip())
    S = input().strip()
    return K, S


def binom_preprocess(n, MOD=10**9+7):
    f = [0 for i in range(n+1)]  # n!
    invf = [0 for i in range(n+1)]  # (n!)^-1
    f[0] = 1
    f[1] = 1
    invf[0] = 1
    invf[1] = 1
    for i in range(2, n+1):
        f[i] = f[i-1] * i % MOD
    invf[n] = pow(f[n], MOD-2, MOD)
    for i in range(n, 2, -1):
        invf[i-1] = invf[i] * i % MOD
    return f, invf


def binom(n, k, f, invf, MOD=10**9+7):
    if n < k or n < 0 or k < 0:
        return 0
    else:
        return (f[n] * invf[k] % MOD) * invf[n-k] % MOD


def solve(K, S, MOD=10**9+7):
    T = len(S)
    f, invf = binom_preprocess(K+T+1)
    ans = 0
    for i in range(K+1):
        L = pow(25, i, MOD) * binom(T-1+i, i, f, invf, MOD) % MOD
        R = pow(26, T-i, MOD)
        ans += L * R
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Submission status: Wrong Answer

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

print((n+k) * pow(25, k, mod) % mod)

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

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

a = 10 ** 9 + 7

al = 26 ** K
c = cmb(K+len(S), min(K,len(S)))

print(al*c % a)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


k = int(input())
s = input()
n = len(s)
M = 10**9+7
l = [chr(v) for v in range(ord("a"), ord("z")+1)]

# dp[i][j]: i文字追加して、最後がl[j]
dp = [[0]*26 for _ in range((k+1))]
cc = l.index(s[-1])
dp[0][cc] = 1

prevsum = 1
for i in range(1,k+1):
    tmp = 0
    for j in range(26):
        if j==cc:
            dp[i][j] = (dp[i-1][j]*(26*(n+i-1)-(n+i-2))) % M
        else:
            dp[i][j] = prevsum
        tmp += dp[i][j]
    prevsum = tmp%M
print(prevsum%M)

Submission status: Wrong Answer

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

print((n+k-1) * pow(25, k, mod) % mod)

Submission status: Wrong Answer

Solution code:
MOD = 10**9 + 7


def main():
    from string import ascii_lowercase
    from collections import Counter
    dic = {i: a for i, a in enumerate(ascii_lowercase)}
    K = int(input())
    S = input()
    N = len(S)
    c = Counter(S)
    pre = 1
    dp = [1]*26
    for i in range(N+1, N+1+K):
        sumv = 0
        for j in range(26):
            v = i
            ch = dic[j]
            sub = (dp[j] - 1)
            v -= c[ch] + sub
            sumv += pre*v
            dp[j] = pre*v
        pre = sumv
    print(sumv % MOD)


if __name__ == '__main__':
    main()

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, mod)
    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:
def main():
    MOD = 10 ** 9 + 7

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

    N = len(S)

    dp = [0] * (N + 3)
    dp[0] = 1

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

    print(dp[-1])

    # for i in range(1, K + N + 1):
    #     dp[N] = (dp[N] * 26 + dp[N - 1]) % MOD
    #     x = min(i, N)
    #     for j in range(x, x - 3, -1):
    #         dp[j] = (dp[j] * 25 + dp[j - 1]) % MOD
    #     dp[0] = dp[0] * 25 % MOD
    #
    # print(dp[-2])


if __name__ == '__main__':
    main()

# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok

Submission status: Wrong Answer

Solution code:
INF = 10 ** 9 + 7
K = int(input())
S = input()
lenS = len(S)
total = 1
for i in range(K):
    total *= pow(26, lenS + 1, INF)
    lenS += 1
    total %= INF

print(total % INF)

Submission status: Wrong Answer

Solution code:
class Mod:
    fac = []
    inv = []
    finv = []
    mod = 0
    def __init__(self,maxi:int ,mod:int):
        self.mod = mod
        self.fac = [1]*maxi
        self.inv = [1]*maxi
        self.finv = [1]*maxi
        for i in range(2,maxi):
            self.fac[i] = self.fac[i - 1]*i%mod
            self.inv[i] = mod - self.inv[mod%i]*(mod//i)%mod
            self.finv[i] = self.finv[i-1]*self.inv[i]%mod


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




def main():
    k = int(input())
    S = input()
    n = len(S)
    neko = Mod(n + k + 10,10**9 + 7)
    ans1 = 1
    for _ in range(k):
        ans1 = (ans1*26)%(10**9 + 7)
    ans2 = neko.com(n + k,k)
    print((ans1*ans2)%(10**9 + 7))
    return 

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

mod=1_000_000_000+7
p=n+1+k

ans=pow(26,p+1)%mod

print(ans)

Submission status: Wrong Answer

Solution code:
a=int(input())
b=str(input())
ans=(((len(b)+1)*26)**a)%(10^9+7)
print(int(ans))

Submission status: Wrong Answer

Solution code:
k = int(input())
s = list(input())

mod = 10**9+7 
fact = [1,1]
finv = [1,1]
inv = [0,1]
 
for i in range(2,k+len(s)+5):
    fact.append((fact[-1]*i)%mod)
    inv.append((inv[mod%i]*(mod-mod//i))%mod)
    finv.append((finv[-1]*inv[-1])%mod)
 
def nCr(n,r,mod):
    if r > n:
        return 0
    else: 
        return fact[n]*finv[r]*finv[n-r]%mod
t = len(s)
ans = 0
dp = [0]*(k+1)
dp[0] = 1
ans += pow(26,k)
for i in range(1,k+1):
    x = nCr(t+i,t,mod)*pow(26,i,mod)
    x %= mod
    x -= dp[i-1]*26
    dp[i] = x
    ans += x*pow(26,k-i,mod)
    ans %= mod

print(ans%mod)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
from collections import defaultdict

K = int(input())  # 偶数
S = input()
mod = 10**9 + 7
l = len(S)
ans = 1
for i in range(K):
    ans *= 25**(l + i) + 26
    ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

if __name__ == '__main__':
    n = int(sys.stdin.readline().rstrip())
    s = sys.stdin.readline().rstrip()
    ans = 1
    l = len(s)
    for _ in range(n):
        ans *= 26 * (l+1)-l
        ans %= 10**9+7
        l += 1
    print(ans)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

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

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

s = len(S)
T1 = 1
T2 = 1
T3 = K + s
ans = 0
for i in range( s, s+K+1):
  T3 = L26[K + s - i]
  #T4 = pow(26, K + s - i, base)
  #print(T3, T4)
  ans += T1 * T2 * T3
  ans %= base
  #print(ans, T1, T2, T3)
  T1 *= 25
  T1 %= base
  T2 = (T2 * i ) // (i+1-s) # T2 = (i, s-1) = (i-1, s-1) * i // (i+1-s)
  T2 %= base
  
print(ans % base)

Submission status: Wrong Answer

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

L26 = [ 1 for i in range(K+1)] # 26^i mod base 


s = len(S)
T1 = 1
T2 = 1
T3 = K + s
ans = 0
for i in range( s, s+K+1):
  T3 = pow(26, K + s - i, base)
  ans += T1 * T2 * T3
  ans %= base
  #print(ans, T1, T2, T3)
  T1 *= 25
  T1 %= base
  T2 = (T2 * i ) // (i+1-s) # T2 = (i, s-1) = (i-1, s-1) * i // (i+1-s)
  T2 %= base
  
print(ans % base)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline

P = 10 ** 9 + 7
def mod_prod(a,b):
    return (a % P) * (b % P) % P

def mod_fact(a):
    ret = 1
    for i in range(a):
        ret = ret * (i + 1) % P
    return ret

def mod_pow(a, n):
    ret = 1
    while n > 0:
        if n % 2 == 1:
            ret = ret * a % P
        a = a * a % P
        n = n >> 1
    return ret

def mod_div(a, b):
    b_inv = mod_pow(b, P - 2)
    return a * b_inv % P

def mod_comb(a,b):
    ret = 1
    b = min(b, a - b)
    for i in range(b):
        ret *= a - i
        ret %= P
    ret = mod_div(ret, mod_fact(b))
    return ret

def solve():
    K = int(readline())
    S = readline().rstrip()

    N = len(S)

    ans = 0
    for i in range(K + 1):
        ans += mod_pow(25, i) * mod_comb(i+N-1, i) * mod_pow(26, K-i)
    print(ans)

solve()

Submission status: Wrong Answer

Solution code:
M = 10**9 +7
def comb_mod(n,a, M = 10**9 +7):
    p = q = 1
    for i in range(a):
        p = p * (n - i) % M
        q = q * (i + 1) % M
    return p * pow(q, M - 2, M) % M
  
k = int(input())
s = input()
print(comb_mod(k,len(s))*pow(25,k)%M)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

K = 10**6 #int(input())
S = 10**6 #len(input())

mod = 10**9+7
N = K+S

# mod上の逆元の計算
inverse = [0, 1]
for i in range(2, N+1):
    inverse.append((-inverse[mod%i]*(mod//i))%mod)

# 階乗とその逆元の計算
factorial = [1, 1]
factorial_inv = [1, 1]
for i in range(2, N+1):
    factorial.append((factorial[-1]*i)%mod)
    factorial_inv.append((factorial_inv[-1]*inverse[i])%mod)

answer = 0
pow = -1
for i in range(K+1):
    if pow == -1:
        pow = 1
    else:
        pow = (pow*25)%mod
    answer = (answer+pow*factorial[N]*factorial_inv[i]*factorial_inv[N-i])%mod
print(answer)

Submission status: Wrong Answer

Solution code:
n=int(input())
p=len(input())
m=10**9+7
c=1
for i in range(n):
    c=((c*26)%m)*(25**p)%m
    p+=1

print(c)

Submission status: Wrong Answer

Solution code:
n=int(input())
p=len(input())
m=10**9+7
c=1
for i in range(n):
    c=c*26*(25**p)%m

print(c)

Submission status: Wrong Answer

Solution code:
# F - Strivore
import sys
sys.setrecursionlimit(10**8)
INF = 10**9+7
K = int(input())
S = input()
l = len(S)

def power(x,n):
    global INF
    if n==0:
        return 1
    elif n%2==0:
        return (power(x,n//2)**2)%INF
    else:
        return (x*(power(x,n//2)**2))%INF

def comb(n,k):
    global INF
    ans = 1
    if k>n//2:
        k = n-k
    for i in range(k):
        ans = (ans*(n-i)//(i+1))%INF
    return ans

ans = 0
for i in range(K+1):
    ans = (ans+power(26,i)*comb(K-i+l-1,l-1)*power(25,K-i))%INF
print(ans)

Submission status: Wrong Answer

Solution code:
a=int(input())
b=str(input())
ans=(((len(b)+1)*26)^a)%(10^9+7)
print(int(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np
K=int(input())
S=list(input())
L=len(S)
M=[]
for i in range(K):
 M.append(L+1+i)
print(np.prod(M)%(10**9+7))

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:
a=int(input())
b=str(input())
ans=((len(b)+1)*26)^a%(10^9+7)
print(int(ans))

Submission status: Wrong Answer

Solution code:
k = int(input())
s = input()
dp = [[0 for _ in range(len(s) + 1)] for _ in range(len(s) + k + 1)]
mod = 10 ** 9 + 7
dp[0][0] = 1
for x in range(len(s) + 1):
    for n in range(len(s) + k + 1):
        if (x == 0) & (n == 0):
            continue
        if x == 0:
            dp[n][x] = (dp[n - 1][x] * 25) % mod
        elif n > 0:
            dp[n][x] = (dp[n - 1][x - 1] + (dp[n - 1][x] * 25)) % mod
print(dp[-1][-1])

Submission status: Wrong Answer

Solution code:
import numpy as np
K=int(input())
S=list(input())
L=len(S)
M=[]
for i in range(K):
 M.append(L+1+i)
print(np.prod(M)%(10**9+7))

Submission status: Wrong Answer

Solution code:
a=int(input())
b=str(input())
ans=(len(b)+1)*a*26/(10^9+7)
print(int(ans))

Submission status: Wrong Answer

Solution code:
k = int(input())
s = input()
n = len(s)
mod = 1000000007
ans = 0
lst = [1]
l25 = [1]
l26 = [1]
for i in range(k):
    lst.append((lst[-1]*(n+i)//(1+i))% mod)
    l25.append(l25[-1]*25%mod)
    l26.append(l26[-1]*26%mod)

for i in range(k+1):
    ans += lst[i]*l25[i]*l26[k-i]
    ans %= mod

print(ans)

Submission status: Wrong Answer

Solution code:
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    k = int(ipt())
    s = input()
    ls = len(s)
    mod = 10**9+7
    #nCrをmodで割った余りを求める。Nに最大値を入れて使用。
    N = 2*10**6
    g1 = [1, 1] # 元テーブル
    g2 = [1, 1] #逆元テーブル
    inverse = [0, 1] #逆元テーブル計算用テーブル
    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
    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
    s25 = [1]
    s26 = [1]
    for i in range(k+1):
        s25.append(s25[-1]*25%mod)
        s26.append(s26[-1]*26%mod)

    for i in range(ls):
        ans += s25[k]*cmb(k+i-1,i,mod)%mod
    for i in range(1,k+1):
        ans += s25[k-i]*s26[i]%mod*cmb(k+ls-1-i,ls-1,mod)
    print(ans)

    return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
K=int(input())
S=list(input())
L=len(S)
M=[]
for i in range(L):
 M.append(L+1+i)

print(M)
print(np.prod(M)%(10**9+7))

Submission status: Wrong Answer

Solution code:
k=int(input())
s=input()
n=k+len(s)
f=[1]*(n+1)
for i in range(1,n+1):
    f[i]=f[i-1]*i
ans=26**k
ans*=f[n]
ans%=1000000007
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def COMinit():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2,max):
        fac[i] = fac[i-1]*i%mod
        inv[i] = mod - inv[mod%i]*(mod//i)%mod
        finv[i] = finv[i-1]*inv[i]%mod

def 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

mod = 10**9+7

K = int(input())
S = input()
N = len(S)
max = N+K
fac = [0] * max
finv = [0] * max
inv = [0] * max
COMinit()
modlist1 = []
modlist2 = []
a = 1
b = 1
for i in range(K+1):
    modlist1.append(a)
    modlist2.append(b)
    a = a*26%mod
    b = b*25%mod

ans = 0
for i in range(K+1):
    x = COM(N+K-i-1,N-1)
    y = modlist1[i]
    z = modlist2[K-i]
    xyz = ((x*y%mod)*z)%mod
    ans = (ans+xyz)%mod
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def COMinit():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2,max):
        fac[i] = fac[i-1]*i%mod
        inv[i] = mod - inv[mod%i]*(mod//i)%mod
        finv[i] = finv[i-1]*inv[i]%mod

def 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

mod = 10**9+7

K = int(input())
S = input()
N = len(S)
max = N+K
fac = [0] * max
finv = [0] * max
inv = [0] * max
COMinit()
ans = 0
for i in range(K+1):
    x = COM(N+K-i-1,N-1)
    y = pow(26,i,mod)
    z = pow(25,K-i,mod)
    xyz = (x*y*z)%mod
    ans = (ans+xyz)%mod
print(ans)

Submission status: Time Limit Exceeded

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

MOD = 10 ** 9 + 7
modinv = lambda a, mod=MOD: pow(a, -1, mod)

# x: 26^k*25^(K-k)
x = pow(26, K, MOD)

# comb: C(L+K-i-1, L-1)
comb = 1

ans = 0
for i in range(K, -1, -1):
    ans = (ans + comb * x) % MOD
    x = x * 25 * modinv(26) % MOD
    comb = comb * (L + K - i) * modinv(K - i + 1) % MOD
print(ans)

Submission status: Time Limit Exceeded

Solution code:
P = 10**9+7

fact = [1 for _ in range(2000001)]
inv = [1 for _ in range(2000001)]
fact_inv = [1 for _ in range(2000001)]

for i in range(2, 2000001):
    fact[i] = (fact[i-1]*i) % P
    inv[i] = P - (inv[P % i] * (P // i)) % P
    fact_inv[i] = (fact_inv[i-1] * inv[i]) % P

K = int(input())
S = input()
N = K + len(S)
p = 1
ans = 0
for i in range(K+1):
    ans += p * (fact[N] * fact_inv[N-i] * fact_inv[i] % P)
    ans = ans % P
    p *= 25
    p = p % P

print(ans)