Problem p02632 (C++)

Buggy submission (status: Runtime Error):
/**
 *    author:  boutarou
 *    created: 21.06.2020 21:30:14
 **/

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define fcout cout << fixed << setprecision(15)
using lint = long long;
using P = pair<int, int>;

template <class T> inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

const double PI = 3.1415926535897932;
const lint MOD = 1e9 + 7;

long long mod_pow(long long n, long long p, long long m) {
  if (p == 0)
    return 1;
  if (p % 2 == 0) {
    long long t = mod_pow(n, p / 2, m);
    return (t * t) % m;
  }
  return n * mod_pow(n, p - 1, m) % m;
}
long long modinv(long long a, long long mod) {
  return mod_pow(a, mod - 2, mod);
}

const int MAX = 1000005;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint k;
lint n;
string s;

lint ans;
lint rest;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> k >> s;
  n = k + s.size();
  ans = mod_pow(26, n, MOD);
  COMinit();
  rep(i, s.size()) {
    rest += mod_pow(25, n - i, MOD) * COM(n, i) % MOD;
    rest %= MOD;
  }
  lint out = ans - rest;
  out %= MOD;
  if (out < 0)
    out += MOD;
  cout << out << endl;

  return 0;
}

Fixed submission:
/**
 *    author:  boutarou
 *    created: 21.06.2020 21:30:14
 **/

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define fcout cout << fixed << setprecision(15)
using lint = long long;
using P = pair<int, int>;

template <class T> inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

const double PI = 3.1415926535897932;
const lint MOD = 1e9 + 7;

long long mod_pow(long long n, long long p, long long m) {
  if (p == 0)
    return 1;
  if (p % 2 == 0) {
    long long t = mod_pow(n, p / 2, m);
    return (t * t) % m;
  }
  return n * mod_pow(n, p - 1, m) % m;
}
long long modinv(long long a, long long mod) {
  return mod_pow(a, mod - 2, mod);
}

const lint MAX = 2000005;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint k;
lint n;
string s;

lint ans;
lint rest;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> k >> s;
  n = k + s.size();
  ans = mod_pow(26, n, MOD);
  COMinit();
  rep(i, s.size()) {
    rest += mod_pow(25, n - i, MOD) * COM(n, i) % MOD;
    rest %= MOD;
  }
  lint out = ans - rest;
  out %= MOD;
  if (out < 0)
    out += MOD;
  cout << out << endl;

  return 0;
}