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::ops;
use std::fmt;
use std::iter;
use std::collections::HashMap;

macro_rules! get_one {
    ($t:ty) => {{
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse::<$t>().unwrap()
    }};

    ($t:ty; $n:expr) => {
        (0..$n).map(|_| get_one!($t)).collect::<Vec<_>>()
    };
}

const MOD: i64 = 1_000_000_007;

fn main() {
    let k = get_one!(isize);
    let s = get_one!(String);
    let n = s.len() as isize;

    let mut kaijo = ModInt(1);
    let mut v_kaijo = vec![];
    let mut v_kaijo_r = vec![];
    for i in 1..=(n+k) {
        kaijo = kaijo * ModInt(i as i64);
        v_kaijo.push(kaijo);
        v_kaijo_r.push(kaijo.resiprocal());
    }

    // dbg!(&v_kaijo, &v_kaijo_r);

    let mut v_binom: Vec<_> = (1..=k).into_iter()
        .map(|i| v_kaijo[(n+k-1) as usize] * v_kaijo_r[(n+k-i-1) as usize] * v_kaijo_r[(i-1) as usize])
        .collect();
    v_binom.insert(0, ModInt(1));

    let mut v_pow = vec![ModInt(1), ];
    let mut pow = ModInt(1);
    for i in 1..=k {
        pow = pow * ModInt(25);
        v_pow.push(pow)
    }

    // dbg!(&v_pow, &v_binom);

    let ans: ModInt = v_binom.into_iter().zip(v_pow.into_iter())
        .map(|(a, b)| a * b)
        .sum();

    println!("{}", ans.0);

    // let mut v = vec![0; n];
    // v[0] = 1;

}

#[derive(Copy, Clone, Debug, PartialEq)]
struct ModInt (i64);

impl ModInt {
    fn new(value: i64) -> Self {
        ModInt(value % MOD)
    }

    /// a を (MOD - 2) 乗した余りを求める
    /// MOD - 2: 111011100110101100101000000101
    fn resiprocal(&self) -> Self {
        let mut v_res = [ModInt::new(0); 30];

        v_res[0] = self.clone();
        for i in 1..30 {
            v_res[i] = v_res[i - 1] * v_res[i - 1]
        }
        let mut prod = ModInt::new(1);
        for &i in [0, 2, 9, 11, 14, 15, 17, 19, 20, 23, 24, 25, 27, 28, 29].iter() {
            prod = prod * v_res[i]
        }
        prod
    }

    fn pow(&self, num: u32) -> Self {
        let mut res = ModInt::new(1);
        let mut num = num;
        let mut beki = *self;
        while num > 0 {
            if num % 2 == 1 {
                res = res * beki;
            }
            beki = beki * beki;
            num = num >> 1;
        }
        res
    }
}

impl ops::Add for ModInt {
    type Output = Self;
    fn add(self, rhs: ModInt) -> Self::Output {
        ModInt::new(self.0 + rhs.0)
    }
}

impl iter::Sum for ModInt {
    fn sum<I: Iterator<Item = ModInt>>(iter: I) -> Self {
        let mut total = ModInt::new(0);
        for i in iter {
            total = total + i
        }
        total
    }
}

impl ops::Sub for ModInt {
    type Output = Self;
    fn sub(self, rhs: ModInt) -> Self::Output {
        ModInt::new(self.0 - rhs.0)
    }
}

impl ops::Mul for ModInt {
    type Output = Self;
    fn mul(self, rhs: Self) -> Self::Output {
        ModInt::new(self.0 * rhs.0)
    }
}

impl ops::Div for ModInt {
    type Output = Self;
    fn div(self, rhs: Self) -> Self::Output {
        self * rhs.resiprocal()
    }
}

#[cfg(test)]
mod tests {

    use super::ModInt;

    #[test]
    fn resiprocal() {
        let one = ModInt::new(37);
        let res = one.resiprocal();
        let expect = ModInt::new(621621626);

        assert_eq!(expect, res);
    }

    #[test]
    fn division() {
        let a = ModInt::new(11111);
        let b = ModInt::new(271);
        let expect = ModInt::new(41);

        assert_eq!(expect, a / b);
    }

}