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)

#![allow(unused_imports)]
#![allow(dead_code)]
use datastructure::*;
use grapth::*;
use input_scanner::*;
use math::*;
use string_algorithm::*;
use util::*;

use std::cmp;
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};

fn main() {
    const MOD: u64 = 1_000_000_007;
    let mut scan = Scanner::new();
    let k: u64 = scan.next();
    let s: Vec<u8> = scan.next_word();
    let si = s.len() as u64;

    let comb = Combination::new((k + si) as usize, MOD);
    let mut ans: u64 = 0;
    for i in si..k+si+1 {
        ans += comb.comb((i - 1) as usize, (si - 1) as usize) * pow_mod(25, i - si, MOD) %MOD * pow_mod(26, si+k - i, MOD);
        ans %= MOD;
    }
    println!("{}", ans);
}

mod datastructure {}
mod grapth {}
mod math {
    pub struct Combination {
        size: usize,
        modv: u64,
        inv: Vec<u64>,
        fact: Vec<u64>,
        invfact: Vec<u64>,
    }

    impl Combination {
        pub fn new(n: usize, modv: u64) -> Self {
            let mut inv = vec![0; n + 1];
            let mut fact = vec![0; n + 1];
            let mut invfact = vec![0; n + 1];
            inv[0] = 0 as u64;
            inv[1] = 1 as u64;
            for i in 2..(n + 1) {
                inv[i] = inv[modv as usize % (i as usize)] * (modv - modv / i as u64) as u64 % modv;
            }
            fact[0] = 1 as u64;
            invfact[0] = 1 as u64;
            for i in 1..(n + 1) {
                fact[i] = i as u64 * fact[i - 1] % modv;
                invfact[i] = invfact[i - 1] * inv[i] % modv;
            }

            Combination {
                size: n,
                modv: modv,
                inv: inv,
                fact: fact,
                invfact: invfact,
            }
        }
        pub fn comb(&self, n: usize, r: usize) -> u64 {
            if r > n {
                return 0;
            }
            self.fact[n] * self.invfact[n - r] % self.modv * self.invfact[r] % self.modv
        }
    }
    pub fn pow_mod(mut x: u64, mut y: u64, modv: u64) -> u64 {
        let mut ret: u64 = 1;
        while y > 0 {
            if (y & 1) != 0 {
                ret = ret * x % modv;
            }
            y >>= 1;
            x = x * x % modv;
        }
        ret
    }
}
mod string_algorithm {}
mod util {}
mod input_scanner {
    pub struct Scanner {
        bytes: Vec<u8>,
        begin: usize,
        end: usize,
    }

    impl Scanner {
        pub fn new() -> Self {
            use std::io::Read;
            let mut buffer: Vec<u8> = Vec::new();
            std::io::stdin().read_to_end(&mut buffer).unwrap();
            let end = (0..buffer.len())
                .find(|i| buffer[*i].is_ascii_whitespace())
                .unwrap_or(buffer.len());
            Scanner {
                bytes: buffer,
                begin: 0,
                end: end,
            }
        }
        pub fn next<T: std::str::FromStr>(&mut self) -> T {
            let s: &str =
                unsafe { std::str::from_utf8_unchecked(&self.bytes[self.begin..self.end]) };
            let ret: T = s.parse::<T>().ok().expect("Parse error.");
            self.skip();
            ret
        }
        pub fn next_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }
        pub fn next_word(&mut self) -> Vec<u8> {
            let r = Vec::from(&self.bytes[self.begin..self.end]);
            self.skip();
            r
        }
        fn skip(&mut self) {
            self.begin = (self.end..self.bytes.len())
                .find(|i| !self.bytes[*i].is_ascii_whitespace())
                .unwrap_or(self.bytes.len());
            self.end = (self.begin..self.bytes.len())
                .find(|i| self.bytes[*i].is_ascii_whitespace())
                .unwrap_or(self.bytes.len());
        }
    }
}