Problem p02632 (C++) — buggy submission, verdict: Time Limit Exceeded

//                                               KEEP GRINDING
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;

#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);

#define int long long
#define ld long double
#define MOD 1000000007
#define precise(i) fixed << setprecision(10) << i
#define f(i, a, b) for (int i = a; i < b; ++i)

#define endl '\\n'
#define debug cout << "\\n========================================\\n";
#define err1(a) cout << #a << " " << a << endl;
#define err2(a, b) cout << #a << " " << a << " " << #b << " " << b << endl;
#define err3(a, b, c)                                                          \\
  cout << #a << " " << a << " " << #b << " " << b << " " << #c << " " << c     \\
       << endl;
#define err4(a, b, c, d)                                                       \\
  cout << #a << " " << a << " " << #b << " " << b << " " << #c << " " << c     \\
       << " " << #d << " " << d << endl;

#define all(a) a.begin(), a.end()
#define show(a)                                                                \\
  for (auto xyz : a)                                                           \\
    cout << xyz << " ";                                                        \\
  cout << endl;
#define PQ priority_queue
#define mx(a) *max_element(a)
#define mn(a) *min_element(a)
#define LB                                                                     \\
  lower_bound // THIS GIVES THE ITR TO THE ELEMENT IN RANGE [SI,EI) THAT IS >=
              // OUR VALUE
#define UB                                                                     \\
  upper_bound // THIS GIVES THE ITR TO THE ELEMENT IN RANGE [SI,EI) THAT IS >
              // OUR VALUE

#define fr first
#define sc second

#define MAXN 2000100
#define INF 9223372036854775807
int fac[MAXN], p25[MAXN], p26[MAXN];
int power(int x, int y, int m = MOD) {
  if (y == 0)
    return 1;
  int p = power(x, y / 2, m) % m;
  p = (p * p) % m;

  return (y % 2 == 0) ? p : (x * p) % m;
}
int nCr(int n, int r, int M = MOD) {
  int num = fac[n], den = (fac[r] * fac[n - r]) % MOD;
  den = power(den, M - 2, M);
  int ans = (num * den) % M;
  return ans;
}
void solve() {
  int k;
  cin >> k;
  string s;
  cin >> s;
  int n = s.size();
  int sum = 0;
  f(pos, n, n + k + 1) {
    sum = (sum +
           ((nCr(pos - 1, n - 1) * p25[pos - n]) % MOD) * p26[n + k - pos]) %
          MOD;
  }
  cout << sum;
}
signed main() {
  fastio fac[0] = p25[0] = p26[0] = 1;
  f(i, 1, MAXN) fac[i] = (fac[i - 1] * i) % MOD,
                p25[i] = (25 * p25[i - 1]) % MOD,
                p26[i] = (26 * p26[i - 1]) % MOD;
  int t = 1;
  for (; t--; solve())
    ;
}

Error: TLE

Fixed submission:

//                                               KEEP GRINDING
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;

#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);

#define int long long
#define ld long double
#define MOD 1000000007
#define precise(i) fixed << setprecision(10) << i
#define f(i, a, b) for (int i = a; i < b; ++i)

#define endl '\\n'
#define debug cout << "\\n========================================\\n";
#define err1(a) cout << #a << " " << a << endl;
#define err2(a, b) cout << #a << " " << a << " " << #b << " " << b << endl;
#define err3(a, b, c)                                                          \\
  cout << #a << " " << a << " " << #b << " " << b << " " << #c << " " << c     \\
       << endl;
#define err4(a, b, c, d)                                                       \\
  cout << #a << " " << a << " " << #b << " " << b << " " << #c << " " << c     \\
       << " " << #d << " " << d << endl;

#define all(a) a.begin(), a.end()
#define show(a)                                                                \\
  for (auto xyz : a)                                                           \\
    cout << xyz << " ";                                                        \\
  cout << endl;
#define PQ priority_queue
#define mx(a) *max_element(a)
#define mn(a) *min_element(a)
#define LB                                                                     \\
  lower_bound // THIS GIVES THE ITR TO THE ELEMENT IN RANGE [SI,EI) THAT IS >=
              // OUR VALUE
#define UB                                                                     \\
  upper_bound // THIS GIVES THE ITR TO THE ELEMENT IN RANGE [SI,EI) THAT IS >
              // OUR VALUE

#define fr first
#define sc second

#define MAXN 2000100
#define INF 9223372036854775807
int fac[MAXN];
int power(int x, int y, int m = MOD) {
  if (y == 0)
    return 1;
  int p = power(x, y / 2, m) % m;
  p = (p * p) % m;

  return (y % 2 == 0) ? p : (x * p) % m;
}
int nCr(int n, int r, int M = MOD) {
  int num = fac[n], den = (fac[r] * fac[n - r]) % MOD;
  den = power(den, M - 2, M);
  int ans = (num * den) % M;
  return ans;
}
void solve() {
  int k;
  cin >> k;
  string s;
  cin >> s;
  int n = s.size();
  int sum = 0;
  f(pos, n, n + k + 1) {
    sum = (sum + ((nCr(pos - 1, n - 1) * power(25, pos - n)) % MOD) *
                     power(26, n + k - pos)) %
          MOD;
  }
  cout << sum;
}
signed main() {
  fastio fac[0] = 1;
  f(i, 1, MAXN) fac[i] = (fac[i - 1] * i) % MOD;
  int t = 1;
  for (; t--; solve())
    ;
}