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# (.NET Core 3.1.201) (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace AtCoder0621
{
	class Program
	{
		static void Main(string[] args)
		{
			F();
		}

		// Extended Euclidean algorithm
		static long xGCD(long a, long b, out long x, out long y)
		{
			if (b == 0)
			{
				x = 1;
				y = 0;
				return a;
			}

			long x1, y1;
			long gcd = xGCD(b, a % b, out x1, out y1);
			x = y1;
			y = (int)(x1 - (long)(a / b) * y1);
			return gcd;
		}
		static long inverse(long a)
		{
			long x, y;
			xGCD(a, (int)MOD, out x, out y);
			return x;
		}
		const long MOD = 1000000007;

		static void F()
		{
			var la = int.Parse(Console.ReadLine());
			var s = Console.ReadLine();
			long k = s.Length;
			long n = s.Length + la;
			long d = 26;

			long sum = 0;
			long mod = 1000000007;
			BigInteger val = 0;

			var pows = new long[n - k + 1];
			pows[pows.Length - 1] = 1;

			for (int j = pows.Length - 2; j >= 0; j--)
				pows[j] = (pows[j + 1] * (d - 1)) % mod;

			long i = 0;
			for (long j = n - k; j >= 0; j--)
			{
				var inv = (inverse((int)i) + mod) % mod;
				if (val == 0)
					val = 1;
				else
					val = (val * (n - i + 1) * inv) % mod;

				i++;
				long current = (long)((val * pows[j]) % mod);
				sum = (sum + current) % mod;
			}

			Console.WriteLine(sum);
		}

		static void E()
		{
			var n = int.Parse(Console.ReadLine());
			var a = Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();
			long last = 0;
			for (int i = 0; i < n - 1; i++)
				last ^= a[i];

			var res = new long[n];
			res[n - 1] = last;
			for (int i = n - 2; i >= 0; i--)
			{
				var two = a[i] ^ a[i + 1];
				var el = two ^ last;
				last = el;
				res[i] = el;
			}

			Console.WriteLine(string.Join(' ', res));
		}

		static void D()
		{
			var n = int.Parse(Console.ReadLine());
			var a = Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();
			var q = int.Parse(Console.ReadLine());
			var bc = Enumerable.Range(0, q).Select(i => new IntPair(Console.ReadLine())).ToArray();
			long s0 = a.Sum();

			var m1 = a.Max();
			var m2 = bc.Max(x => Math.Max(x.First, x.Second));
			var m = Math.Max(m1, m2);

			var valueCounts = new long[m + 1];
			foreach (var val in a)
				valueCounts[val]++;

			for (int i = 0; i < q; i++)
			{
				var b = bc[i].First;
				var c = bc[i].Second;

				s0 += valueCounts[b] * (c - b);

				valueCounts[c] += valueCounts[b];
				valueCounts[b] = 0;

				Console.WriteLine(s0);
			}
		}

		static void C()
		{
			var n = long.Parse(Console.ReadLine());
			var cur = 26L;
			int chars = 1;
			while (n > cur)
			{
				n -= cur;
				cur *= 26L;
				chars++;
			}
			n -= 1;
			var l = new char[chars];
			chars--;
			while (chars >= 0)
			{
				l[chars--] = (char)('a' + n % 26);
				n /= 26;
			}

			Console.WriteLine(new string(l));
		}

		static void B()
		{
			var ints = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
			var k = ints[1];
			var a = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
			Array.Sort(a);

			Console.WriteLine(a.Take(k).Sum());
		}

		static void A()
		{
			var s = Console.ReadLine();
			if (s == s.ToLower())
				Console.WriteLine('a');
			else
				Console.WriteLine('A');
		}
	}

	public struct IntPair
	{
		public int First;
		public int Second;

		public IntPair(string s)
		{
			var split = s.Split();
			First = int.Parse(split[0]);
			Second = int.Parse(split[1]);
		}

		public IntPair(int first, int second)
		{
			First = first;
			Second = second;
		}

		public static bool operator ==(IntPair p1, IntPair p2) => p1.First == p2.First && p1.Second == p2.Second;
		public static bool operator !=(IntPair p1, IntPair p2) => p1.First != p2.First || p1.Second != p2.Second;
		public override string ToString() => $"{First} {Second}";
		public override bool Equals(object obj)
		{
			var p = obj as IntPair?;
			return p.HasValue && p.Value.First == First && p.Value.Second == Second;
		}

		public override int GetHashCode()
		{
			uint rol5 = ((uint)First << 5) | ((uint)First >> 27);
			return ((int)rol5 + First) ^ Second;
		}

		public static long UpperBound(long min, long max, Predicate<long> test)
		{
			long ans = min;
			long s = min;
			long e = max;
			while (s <= e)
			{
				long mid = (s + e) / 2;
				if (test(mid))
				{
					ans = mid;
					s = mid + 1;
				}
				else
					e = mid - 1;
			}

			return ans;
		}

		public static long LowerBound(long min, long max, Predicate<long> test)
		{
			long ans = max;
			long e = max;
			long s = min;

			while (s <= e)
			{
				long mid = (s + e) / 2;

				if (test(mid))
				{
					ans = mid;
					e = mid - 1;
				}
				else
					s = mid + 1;
			}

			return ans;
		}

	}

}