Problem p03365 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define Rep(i, a, b) for (register int i = (a); i <= int(b); ++i)
#define Dep(i, a, b) for (register int i = (a); i >= int(b); --i)
#define rep(i, a, b) for (register int i = (a); i < int(b); ++i)
#define mem(x, v) memset(x, v, sizeof(x))
#define gc getchar
#define pc putchar
#define fi first
#define queue QQQ
#define se second
#define debug(x) cout << #x " = " << x << endl;
#define pp(x, y) cout << "pp: " << x << " " << y << endl;
#define rank __RAnK
inline ll read() {
  register ll x = 0, f = 1;
  register char c = gc();
  for (; !isdigit(c); c = gc())
    if (c == '-')
      f = -1;
  for (; isdigit(c); c = gc())
    x = (x << 1) + (x << 3) + (c ^ 48);
  return x * f;
}
#define rd read
void write(ll x) {
  if (x < 0)
    x = -x, pc('-');
  if (x >= 10)
    write(x / 10);
  putchar(x % 10 + '0');
}
void writeln(ll x) {
  write(x);
  puts("");
}
const int maxn = 2e5 + 233;
const int mod = 1e9 + 7;
int fac[maxn], inv[maxn], f[maxn], n;
inline int qpow(int a, int b) {
  int ans = 1;
  for (; b; b >>= 1, a = 1ll * a * a % mod)
    if (b & 1)
      ans = 1ll * ans * a % mod;
  return ans;
}
inline int C(int n, int m) {
  return 1ll * fac[n] * inv[m] % mod * inv[n - m] % mod;
}
int main() {
  n = rd();
  fac[0] = 1;
  Rep(i, 1, n) fac[i] = 1ll * fac[i - 1] * i % mod;
  inv[n] = qpow(fac[n], mod - 2);
  Dep(i, n - 1, 0) inv[i] = 1ll * inv[i + 1] * (i + 1) % mod;
  Dep(i, n - 1, (n + 1) / 2) {
    f[i] = 1ll * C(i - 1, n - 1 - i) * fac[i] % mod * fac[n - 1 - i] % mod;
    f[i + 1] = (f[i + 1] - f[i] + mod) % mod;
  }
  int ans = 0;
  Dep(i, n - 1, (n + 1) / 2) ans = (ans + 1ll * i * f[i] % mod) % mod;
  writeln(ans);
}
// f[i]表示答案小于等于i的方案数：i步可以完成
// 也就是相当于有i个变量


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define Rep(i, a, b) for (register int i = (a); i <= int(b); ++i)
#define Dep(i, a, b) for (register int i = (a); i >= int(b); --i)
#define rep(i, a, b) for (register int i = (a); i < int(b); ++i)
#define mem(x, v) memset(x, v, sizeof(x))
#define gc getchar
#define pc putchar
#define fi first
#define queue QQQ
#define se second
#define debug(x) cout << #x " = " << x << endl;
#define pp(x, y) cout << "pp: " << x << " " << y << endl;
#define rank __RAnK
inline ll read() {
  register ll x = 0, f = 1;
  register char c = gc();
  for (; !isdigit(c); c = gc())
    if (c == '-')
      f = -1;
  for (; isdigit(c); c = gc())
    x = (x << 1) + (x << 3) + (c ^ 48);
  return x * f;
}
#define rd read
void write(ll x) {
  if (x < 0)
    x = -x, pc('-');
  if (x >= 10)
    write(x / 10);
  putchar(x % 10 + '0');
}
void writeln(ll x) {
  write(x);
  puts("");
}
const int maxn = 2e6 + 233;
const int mod = 1e9 + 7;
int fac[maxn], inv[maxn], f[maxn], n;
inline int qpow(int a, int b) {
  int ans = 1;
  for (; b; b >>= 1, a = 1ll * a * a % mod)
    if (b & 1)
      ans = 1ll * ans * a % mod;
  return ans;
}
inline int C(int n, int m) {
  return 1ll * fac[n] * inv[m] % mod * inv[n - m] % mod;
}
int main() {
  n = rd();
  fac[0] = 1;
  Rep(i, 1, n) fac[i] = 1ll * fac[i - 1] * i % mod;
  inv[n] = qpow(fac[n], mod - 2);
  Dep(i, n - 1, 0) inv[i] = 1ll * inv[i + 1] * (i + 1) % mod;
  Dep(i, n - 1, (n + 1) / 2) {
    f[i] = 1ll * C(i - 1, n - 1 - i) * fac[i] % mod * fac[n - 1 - i] % mod;
    f[i + 1] = (f[i + 1] - f[i] + mod) % mod;
  }
  int ans = 0;
  Dep(i, n - 1, (n + 1) / 2) ans = (ans + 1ll * i * f[i] % mod) % mod;
  writeln(ans);
}
// f[i]表示答案小于等于i的方案数：i步可以完成
// 也就是相当于有i个变量