Problem p02632 (C++) — buggy submission, verdict: Runtime Error

// Abhinav ---IIIT_A
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define f(i, x, n) for (int i = x; i < (int)n; ++i)
#define vpii vector<pair<int, int>>
ld pie = 3.141592653589793238462643383279;
int mod = 1e9 + 7;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, 1, -1};

int dig(int a) {
  int r = 0;
  while (a != 0) {
    int xp = a % 10;
    a /= 10;
    if (xp == 1)
      ++r;
  }
  return r;
}

int fact[2000005];
int infact[2000005];

int inv(int a) {
  int y = mod - 2;
  int r = 1;
  while (y != 0) {
    if (y & 1) {
      r *= a;
      r %= mod;
    }
    y /= 2;
    a *= a;
    a %= mod;
  }
  return r;
}

int po(int a, int y) {
  int r = 1;
  while (y != 0) {
    if (y & 1) {
      r *= a;
      r %= mod;
    }
    y /= 2;
    a *= a;
    a %= mod;
  }
  return r;
}

void facto() {
  fact[0] = 1;
  f(i, 1, 2000005) {
    fact[i] = i * fact[i - 1];
    fact[i] %= mod;
  }
  f(i, 0, 2000005) infact[i] = inv(fact[i]);
}

int nck(int n, int k) {
  if (k < 0 || k > n)
    return 0;
  int ret = fact[n];
  ret *= infact[k];
  ret %= mod;
  ret *= infact[n - k];
  ret %= mod;
  return ret;
}
int32_t main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  facto();
  int k;
  cin >> k;
  string s;
  cin >> s;
  int l = k + s.size();
  int xp = s.size();
  // total = 26^l - those which do not contain subsequence
  // --- i= 0 to  xp-1 prefix present as subseqeunce and remaining have 25^(l-i)
  int ret = 1;
  f(i, 0, l) {
    ret *= 26;
    ret %= mod;
  }
  int sub = 0;

  f(i, 0, xp) {
    // l choose i
    sub += (nck(l, i) * po(25, l - i));
    sub %= mod;
  }

  cout << ((ret - sub) % mod + mod) % mod << "\\n";
  return 0;
}


Error: WA

Fixed submission:

// Abhinav ---IIIT_A
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define f(i, x, n) for (int i = x; i < (int)n; ++i)
#define vpii vector<pair<int, int>>
ld pie = 3.141592653589793238462643383279;
int mod = 1e9 + 7;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, 1, -1};

int dig(int a) {
  int r = 0;
  while (a != 0) {
    int xp = a % 10;
    a /= 10;
    if (xp == 1)
      ++r;
  }
  return r;
}

int fact[1000005];
int infact[1000005];

int inv(int a) {
  int y = mod - 2;
  int r = 1;
  while (y != 0) {
    if (y & 1) {
      r *= a;
      r %= mod;
    }
    y /= 2;
    a *= a;
    a %= mod;
  }
  return r;
}

int po(int a, int y) {
  int r = 1;
  while (y != 0) {
    if (y & 1) {
      r *= a;
      r %= mod;
    }
    y /= 2;
    a *= a;
    a %= mod;
  }
  return r;
}

void facto() {
  fact[0] = 1;
  f(i, 1, 1000005) {
    fact[i] = i * fact[i - 1];
    fact[i] %= mod;
  }
  f(i, 0, 1000005) infact[i] = inv(fact[i]);
}

int nck(int n, int k) {
  if (k < 0 || k > n)
    return 0;
  int ret = fact[n];
  ret *= infact[k];
  ret %= mod;
  ret *= infact[n - k];
  ret %= mod;
  return ret;
}
int32_t main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  facto();
  int k;
  cin >> k;
  string s;
  cin >> s;
  int l = k + s.size();
  int xp = s.size();
  // total = 26^l - those which do not contain subsequence
  // --- i= 0 to  xp-1 prefix present as subseqeunce and remaining have 25^(l-i)
  int ret = 1;
  f(i, 0, l) {
    ret *= 26;
    ret %= mod;
  }
  int sub = 0;

  f(i, 0, xp) {
    // l choose i
    sub += (nck(l, i) * po(25, l - i));
    sub %= mod;
  }

  cout << ((ret - sub) % mod + mod) % mod << "\\n";
  return 0;
}