Problem p02554 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const ll llINF = 1LL << 60;
const int iINF = 1e9;

//---snuke mint---
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x = 0)
      : x((x % mod + mod) % mod) {} // ll = x; x = x%mod+mod)%mod; と同じらしい
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

//---main---------------------------------------------
int main() {
  // main
  int N;
  cin >> N;
  mint ans = 0;
  if (N == 1) {
    cout << ans << endl;
    return 0;
  }

  vector<mint> e(N);
  e[N] = 1;
  for (int i = N - 1; i >= 2; i--) {
    e[i] = e[i + 1] * 8;
  }

  mint c, t;
  c = N;
  t = 0;
  for (int i = 2; i <= N; i++) {
    c = (c * (N - i + 1)) / i;
    t = t * 2 + 2;
    // cout << i << ":" << c << "," << t << "," << e[i] << endl;
    ans += c * t * e[i];
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const ll llINF = 1LL << 60;
const int iINF = 1e9;

//---snuke mint---
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x = 0)
      : x((x % mod + mod) % mod) {} // ll = x; x = x%mod+mod)%mod; と同じらしい
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

//---main---------------------------------------------
int main() {
  // main
  int N;
  cin >> N;
  mint ans = 0;
  if (N == 1) {
    cout << ans << endl;
    return 0;
  }

  vector<mint> e(N + 1);
  e[N] = 1;
  for (int i = N - 1; i >= 2; i--) {
    e[i] = e[i + 1] * 8;
  }

  mint c, t;
  c = N;
  t = 0;
  for (int i = 2; i <= N; i++) {
    c = (c * (N - i + 1)) / i;
    t = t * 2 + 2;
    // cout << i << ":" << c << "," << t << "," << e[i] << endl;
    ans += c * t * e[i];
  }

  cout << ans << endl;

  return 0;
}