Problem p02632 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())
#define pb push_back
#define pii pair<int, int>
#define print(x)                                                               \
  for (auto it : x)                                                            \
    cout << it << ' ';
#define endl "\n" // TODO: remove
#define int long long

const int N = (int)(1e6) + 322;
const int inf = (int)(2e18);
const int mod = (int)(1e9) + 7; // check modulo

int fact[N], inv[N];

inline int mult(int a, int b) { return 1ll * a * b % mod; }

inline int binpow(int a, int n) {
  int res = 1;
  while (n) {
    if (n & 1) {
      res = mult(res, a);
    }
    a = mult(a, a);
    n >>= 1;
  }
  return res;
}

inline int add(int a, int b) {
  if (a + b >= mod)
    return a + b - mod;
  else
    return a + b;
}

inline int sub(int a, int b) {
  if (a - b < 0)
    return a - b + mod;
  else
    return a - b;
}

inline int getinv(int a) { return binpow(a, mod - 2); }

inline int divide(int a, int b) { return mult(a, getinv(b)); }

inline int C(int n, int k) {
  if (n < k)
    return 0;
  return mult(fact[n], mult(inv[k], inv[n - k]));
}

void init(int lim) {
  fact[0] = 1;
  inv[0] = 1;
  for (int i = 1; i < lim; ++i) {
    fact[i] = fact[i - 1] * i % mod;
    inv[i] = binpow(fact[i], mod - 2);
  }
}

void solve(int test) {
  init(N);
  int k;
  cin >> k;
  string s;
  cin >> s;
  int n = sz(s);
  k += n;
  int all = binpow(26, k);
  for (int i = 0; i < n; ++i) {
    all = sub(all, mult(C(k, i), binpow(25, k - i)));
  }
  cout << all;
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int test = 1; // cin >> test;
  for (int tt = 1; tt <= test; ++tt) {
    solve(tt);
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())
#define pb push_back
#define pii pair<int, int>
#define print(x)                                                               \
  for (auto it : x)                                                            \
    cout << it << ' ';
#define endl "\n" // TODO: remove
#define int long long

const int N = (int)(2e6) + 322;
const int inf = (int)(2e18);
const int mod = (int)(1e9) + 7; // check modulo

int fact[N], inv[N];

inline int mult(int a, int b) { return 1ll * a * b % mod; }

inline int binpow(int a, int n) {
  int res = 1;
  while (n) {
    if (n & 1) {
      res = mult(res, a);
    }
    a = mult(a, a);
    n >>= 1;
  }
  return res;
}

inline int add(int a, int b) {
  if (a + b >= mod)
    return a + b - mod;
  else
    return a + b;
}

inline int sub(int a, int b) {
  if (a - b < 0)
    return a - b + mod;
  else
    return a - b;
}

inline int getinv(int a) { return binpow(a, mod - 2); }

inline int divide(int a, int b) { return mult(a, getinv(b)); }

inline int C(int n, int k) {
  if (n < k)
    return 0;
  return mult(fact[n], mult(inv[k], inv[n - k]));
}

void init(int lim) {
  fact[0] = 1;
  inv[0] = 1;
  for (int i = 1; i < lim; ++i) {
    fact[i] = fact[i - 1] * i % mod;
    inv[i] = binpow(fact[i], mod - 2);
  }
}

void solve(int test) {
  init(N);
  int k;
  cin >> k;
  string s;
  cin >> s;
  int n = sz(s);
  k += n;
  int all = binpow(26, k);
  for (int i = 0; i < n; ++i) {
    all = sub(all, mult(C(k, i), binpow(25, k - i)));
  }
  cout << all;
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int test = 1; // cin >> test;
  for (int tt = 1; tt <= test; ++tt) {
    solve(tt);
  }

  return 0;
}