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::{fastout, input};

const MOD: u32 = 1_000_000_007;

#[derive(Clone, Copy)]
struct ModU32(u32);
impl std::ops::Add for ModU32 {
    type Output = ModU32;
    fn add(self, rhs: ModU32) -> Self::Output {
        let mut d = self.0 + rhs.0;
        if d >= MOD {
            d -= MOD;
        }
        ModU32(d)
    }
}

impl std::ops::AddAssign for ModU32 {
    fn add_assign(&mut self, rhs: ModU32) {
        *self = *self + rhs;
    }
}

impl std::ops::Sub for ModU32 {
    type Output = ModU32;
    fn sub(self, rhs: ModU32) -> Self::Output {
        let mut d = self.0 + MOD - rhs.0;
        if d >= MOD {
            d -= MOD;
        }
        ModU32(d)
    }
}

impl std::ops::SubAssign for ModU32 {
    fn sub_assign(&mut self, rhs: ModU32) {
        *self = *self - rhs;
    }
}

impl std::ops::Mul for ModU32 {
    type Output = ModU32;
    fn mul(self, rhs: ModU32) -> Self::Output {
        ModU32((self.0 as u64 * rhs.0 as u64 % MOD as u64) as u32)
    }
}

impl std::ops::MulAssign for ModU32 {
    fn mul_assign(&mut self, rhs: ModU32) {
        *self = *self * rhs;
    }
}

impl std::ops::Neg for ModU32 {
    type Output = ModU32;
    fn neg(self) -> Self::Output {
        ModU32(if self.0 == 0 { 0 } else { MOD - self.0 })
    }
}

impl std::fmt::Display for ModU32 {
    fn fmt<'a>(&self, f: &mut std::fmt::Formatter<'a>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}

impl std::str::FromStr for ModU32 {
    type Err = std::num::ParseIntError;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        let val = s.parse::<u32>()?;
        Ok(ModU32::new(val))
    }
}

impl From<usize> for ModU32 {
    fn from(val: usize) -> ModU32 {
        ModU32((val % MOD as usize) as u32)
    }
}

impl From<i64> for ModU32 {
    fn from(val: i64) -> ModU32 {
        let m = MOD as i64;
        ModU32::new((val % m + m) as u32)
    }
}

impl ModU32 {
    pub fn new(n: u32) -> ModU32 {
        ModU32(n % MOD)
    }
    pub fn zero() -> ModU32 {
        ModU32(0)
    }
    pub fn one() -> ModU32 {
        ModU32(1)
    }
    pub fn pow(self, mut n: u32) -> ModU32 {
        let mut t = ModU32::one();
        let mut s = self;
        while n > 0 {
            if n & 1 == 1 {
                t *= s;
            }
            s *= s;
            n >>= 1;
        }
        t
    }
    pub fn inv(self) -> ModU32 {
        assert!(self.0 > 0);
        self.pow(MOD - 2)
    }
}

struct Combination {
    fact: Vec<ModU32>,
    fact_inv: Vec<ModU32>,
}

impl Combination {
    pub fn new(n: usize) -> Self {
        let mut fact = vec![ModU32::one(); n + 1];
        let mut fact_inv = vec![ModU32::one(); n + 1];
        for i in 2..(n + 1) {
            fact[i] = fact[i - 1] * ModU32(i as u32);
        }
        fact_inv[n] = fact[n].inv();
        for i in (1..n).rev() {
            fact_inv[i] = fact_inv[i + 1] * ModU32((i + 1) as u32);
        }
        Self { fact,fact_inv }
    }
    pub fn eval(&self, n: usize, k: usize) -> ModU32 {
        if k > n {
            return ModU32::zero();
        }
        self.fact[n] * self.fact_inv[k] * self.fact_inv[n - k]
    }
}

#[fastout]
fn main() {
    input! {
        k:usize,
        s: String
    }
    let n = s.len();
    let cmb = Combination::new(n + k);
    let rad = ModU32(26);
    let mut ans = ModU32::zero();
    for i in 0..=k {
        ans += rad.pow(i as u32)
            * cmb.eval(k - i + n - 1, n - 1)
            * (rad - ModU32::one()).pow((k - i) as u32);
    }
    println!("{}", ans);
}