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 Rust (1.42.0) (judge verdict: Accepted)

use proconio::input;

const M: u64 = 1000_000_007;

fn main() {
    input! {
        k: u64,
        s: String,
    }
    let slen = s.len() as u64;
    let e = k + slen;

    let mut r = 0;
    let mut ncr = 1;
    for n in slen..(e + 1) {
        r += ncr * (modpow(25, n - slen) * modpow(26, e - n) % M);
        r %= M;
        ncr *= n * modpow(n - slen + 1, M - 2) % M;
        ncr %= M;
    }

    println!("{}", r);
}

fn modpow(x: u64, y: u64) -> u64 {
    let mut result = 1;
    let mut a = x;
    let mut b = y;
    while b > 0 {
        if b % 2 == 1 {
            result = result * a % M;
        }
        a = a * a % M;
        b /= 2;
    }
    result
}

pub fn binom_pascal( n: u64, k: u64 ) -> u64 {
    if k == 0 || k == n {
        return 1;
    }
    let k = k as usize;

    let mut p = vec![ 1 ];

    for _ in 0..n-1 {
        let mut c = vec![ 1 ];

        for x in p.windows(2) {
            c.push( x[0] + x[1] );
        }
        c.push( 1 );

        p = c;
    }

    p[k-1] + p[k]
}