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 C (GCC 9.2.1) (judge verdict: Accepted)

#include <stdio.h>
#include <string.h>
#include <inttypes.h>

#define MOD_BY UINT32_C(1000000007)

uint32_t add(uint32_t a, uint32_t b) {
	uint32_t r = a + b;
	if (r >= MOD_BY) r -= MOD_BY;
	return r;
}

uint32_t sub(uint32_t a, uint32_t b) {
	return b == 0 ? a : add(a, MOD_BY - b);
}

uint32_t mul(uint32_t a, uint32_t b) {
	return (uint32_t)((uint64_t)a * b % MOD_BY);
}

uint32_t pou(uint32_t a, uint32_t b) {
	uint32_t r = 1;
	while (b > 0) {
		if (b & 1) r = mul(r, a);
		a = mul(a, a);
		b >>= 1;
	}
	return r;
}

uint32_t inv(uint32_t a) {
	return pou(a, MOD_BY - 2);
}

int K;
int len;
int total;
char S[1234567];

uint32_t bikkuri[2345678];
uint32_t bikkuri_inv[2345678];
uint32_t enuzyou[2345678];
uint32_t enuzyou[2345678];

uint32_t nCk(uint32_t n, uint32_t k) {
	if (n < k) return 0;
	return mul(mul(bikkuri[n], bikkuri_inv[n - k]), bikkuri_inv[k]);
}

int main(void) {
	int i;
	uint32_t ans;
	if (scanf("%d", &K) != 1) return 1;
	if (scanf("%1234566s", S) != 1) return 1;
	len = (int)strlen(S);
	total = K + len;

	bikkuri[0] = 1;
	bikkuri_inv[0] = 1;
	enuzyou[0] = 1;
	for (i = 1; i <= total; i++) {
		bikkuri[i] = mul(bikkuri[i - 1], i);
		bikkuri_inv[i] = inv(bikkuri[i]);
		enuzyou[i] = mul(enuzyou[i - 1], 25);
	}

	ans = pou(26, total);
	for (i = 0; i < len; i++) {
		ans = sub(ans, mul(nCk(total, i), enuzyou[total - i]));
	}

	printf("%" PRIu32 "\n", ans);
	return 0;
}

/*

int search(int allpos, int spos) {
	int ans = 0;
	int i;
	if (allpos >= K + |S|) return spos == |S|;
	// メモ読み
	for (i = 0; i < 26; i++) {
		ans += search(allpos + 1, spos + (spos != |S| && S[spos] == 'a' + i));
	}
	// メモ書き
	return ans;
}

*/

/*

spos < |S| のとき、一致するパターンが必ず1個、他が必ず25個

Sの文字を全部aにしてもおｋ (多分)

全部のパターン数 - aを使う回数が|S|未満のパターン数

aを使う回数がkのパターン数 = (K+|S|)Ck * 26**(K+|S|-k)

nCrは掛け算3回 → テーブル
*/