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)

struct Combination {
    m: usize,
    fact: Vec<usize>,
    inv_fact: Vec<usize>,
}

impl Combination {
    fn new(n: usize, m: usize) -> Combination {
        let mut fact = vec![0; n + 1];
        let mut inv_fact = vec![0; n + 1];
        fact[0] = 1;
        for i in 1..=n {
            fact[i] = fact[i - 1] * i % m;
        }
        inv_fact[n] = Self::pow(fact[n], m - 2, m);
        for i in (1..=n).rev() {
            inv_fact[i - 1] = inv_fact[i] * i % m;
        }

        Combination { m, fact, inv_fact }
    }

    fn pow(mut a: usize, mut n: usize, m: usize) -> usize {
        let mut res = 1;
        while n > 0 {
            if n & 1 > 0 {
                res = res * a % m;
            }
            a = a * a % m;
            n >>= 1;
        }
        res
    }
    
    fn c(&self, n: usize, r: usize) -> usize {
        if n < r { return 0; }
        let tmp = self.inv_fact[n - r] * self.inv_fact[r] % self.m;
        self.fact[n] * tmp % self.m
    }
}

fn main() {
    const MOD: usize = 1_000_000_007;

    let k: usize = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().parse().unwrap()
    };

    let s: Vec<char> = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().chars().collect()
    };

    let n = s.len();
    let m = k + n;

    let combination = Combination::new(m, MOD);

    let mut ans = 0;
    for i in n..=m {
        let mut res = 1;
        res = res * combination.c(i - 1, n - 1) % MOD;
        res = res * Combination::pow(25, i - n, MOD) % MOD;
        res = res * Combination::pow(26, m - i, MOD) % MOD;
        ans = (ans + res) % MOD;
    }
    println!("{}", ans);
}