Problem:
Score: 600 points

Problem Statement

How many strings can be obtained by applying the following operation on a string S exactly K times: "choose one lowercase English letter and insert it somewhere"?

The answer can be enormous, so print it modulo (10^9+7).

Constraints

K is an integer between 1 and 10^6 (inclusive).

S is a string of length between 1 and 10^6 (inclusive) consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

K
S

Output

Print the number of strings satisfying the condition, modulo (10^9+7).

Sample Input 1

5
oof

Sample Output 1

575111451

For example, we can obtain proofend, moonwolf, and onionpuf, while we cannot obtain oofsix, oofelevennn, voxafolt, or fooooooo.

Sample Input 2

37564
whydidyoudesertme

Sample Output 2

318008117

Solution in PyPy3 (7.3.0) (judge verdict: Time Limit Exceeded)

def extgcd(x, y):
    return _extgcd(x, 1, 0, y, 0, 1)

def _extgcd(x, a, b, y, c, d):
    if y == 0:
        return (x, a, b)
    k = x // y
    return _extgcd(y, c, d, x % y, a - k * c, b - k * d)

def inverse(x, m):
    _, a, _ = extgcd(x, m)
    a %= m
    return a

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

MOD = int(1e9+7)
n = len(s)
comb = [0 for _ in range(n + k + 1)]
comb[0] = 1
for i in range(n + k):
    comb[i + 1] = comb[i]
    comb[i + 1] *= (n + k - i)
    comb[i + 1] *= inverse(i + 1, MOD)
    comb[i + 1] %= MOD

ans = pow(26, n + k, MOD)
for i in range(n):
    ans -= comb[i] * pow(25, n + k - i, MOD)
    ans %= MOD
print(ans)