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 std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("faild to read char") as char)
        .take_while(|c| !c.is_whitespace())
        .collect();
    token
        .parse()
        .ok()
        .expect("faild to parse token")
}

fn main(){
    let k: u64 = read();
    let s: u64 = read::<String>().chars().collect::<Vec<_>>().len() as u64;

    let mut ret: ModInt = ModInt(0);

    let mut comb: Vec<ModInt> = Vec::with_capacity((s + k) as usize);
    comb.push(ModInt(1));

    for i in 1..=(s + k - 1) {
        comb.push(comb[i as usize - 1] * ModInt(s + i - 1) / ModInt(i));
    }

    for i in 0..=k {
        //ret += ModInt::comb(s + i - 1, i) * ModInt(25).pow(i) * ModInt(26).pow(k - i);
        ret += comb[i as usize] * ModInt(25).pow(i) * ModInt(26).pow(k - i);
    }
    println!("{}", ret);
}

#[derive(Clone, Copy)]
struct ModInt(u64);
const MOD: u64 = 1000000007;

impl std::ops::Add for ModInt {
    type Output = ModInt;

    fn add(self, other: ModInt) -> ModInt {
        let ModInt(a) = self;
        let ModInt(b) = other;
        ModInt((a + b) % MOD)
    }
}

impl std::ops::AddAssign for ModInt {
    fn add_assign(&mut self, other: ModInt) {
        let ModInt(a) = self;
        let ModInt(b) = other;
        *a += b;
        *a %= MOD;
    }
}

impl std::ops::Sub for ModInt {
    type Output = ModInt;

    fn sub(self, other: ModInt) -> ModInt {
        let ModInt(a) = self;
        let ModInt(b) = other;
        ModInt((a + MOD - b) % MOD)
    }
}

impl std::ops::SubAssign for ModInt {
    fn sub_assign(&mut self, other: ModInt) {
        let ModInt(a) = self;
        let ModInt(b) = other;
        // *a = (*a + MOD - b) % MOD;
        *a += MOD;
        *a -= b;
        *a %= MOD;
    }
}

impl std::ops::Mul for ModInt {
    type Output = ModInt;

    fn mul(self, other: ModInt) -> ModInt {
        let ModInt(a) = self;
        let ModInt(b) = other;
        ModInt((a * b) % MOD)
    }
}

impl std::ops::MulAssign for ModInt {
    fn mul_assign(&mut self, other: ModInt) {
        let ModInt(a) = self;
        let ModInt(b) = other;
        //*a = (*a * b) % MOD;
        *a *= b;
        *a %= MOD;
    }
}

impl ModInt {
    fn pow(&self, n: u64) -> ModInt {
        if n == 0 {
            return ModInt(1);
        }
        let prev = self.pow(n / 2);
        if n % 2 == 1 {
            prev.clone() * prev * self.clone()
        } else {
            prev.clone() * prev
        }
    }

    fn inverse(&self) -> ModInt {
        self.pow(MOD - 2)
    }

    fn comb(a: u64, b: u64) -> ModInt {
        let mut ret = ModInt(1);
        let m = std::cmp::min(b, a - b);
        for i in 0..m {
            ret *= ModInt(a - i);
            ret = ret / ModInt(i + 1);
        }
        ret
    }
}

impl std::ops::Div for ModInt {
    type Output = ModInt;

    fn div(self, other: ModInt) -> ModInt {
        self * other.inverse()
    }
}

impl std::ops::DivAssign for ModInt {
    fn div_assign(&mut self, other: ModInt) {
        *self *= other.inverse();
    }
}

impl std::fmt::Display for ModInt {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let ModInt(a) = self;
        write!(f, "{}", a)
    }
}