Problem p02862 (C++)

Buggy submission (status: Runtime Error):
// #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll long long
#define ld long double
#define pi pair<int, int>
#define pd pair<ld, ld>
#define ft first
#define sd second
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define F(i, a, b) FOR(i, (a), (b)-1)
#define REV(i, a, b) for (int i = (a); i >= (b); i--)
#define VI vector<int>
#define VPI vector<pi>
#define VPD vector<pd>
#define PI 3.14159265
#define all(x) (x).begin(), (x).end()
#define sz(a) (int)((a).size())
#define int long long

template <class TH> void _dbg(const char *sdbg, TH h) {
  cerr << sdbg << "=" << h << "\n";
}
template <class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',')
    cerr << *sdbg++;
  cerr << "=" << h << ",";
  _dbg(sdbg + 1, a...);
}
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
mt19937 r(chrono::steady_clock::now().time_since_epoch().count());
int rand_range(int a, int b) {
  assert(a <= b);
  return a + r() % (b - a + 1);
}
const long long K = 1000;
const long long KK = K * K;
const long long MIL = KK * K;
const long long INF = MIL * MIL;
const long long MOD = MIL + 7;
const long long N = 1e6 + 10, M = 10;

int silnia[N], odsilnia[N];

int dwumian(int a, int b) {
  return (((silnia[a] * odsilnia[b]) % MOD) * odsilnia[a - b]) % MOD;
}

int pot(int x, int p) {
  int tmp = 1;
  for (; p; p /= 2, x = (x * x) % MOD) {
    if (p & 1)
      tmp = (tmp * x) % MOD;
  }
  return tmp;
}

void solve() {
  silnia[0] = 1;
  F(i, 1, N)
  silnia[i] = (silnia[i - 1] * i) % MOD;

  odsilnia[N - 1] = pot(silnia[N - 1], MOD - 2);
  REV(i, N - 2, 0)
  odsilnia[i] = (odsilnia[i + 1] * (i + 1)) % MOD;

  int x, y;
  cin >> x >> y;
  if ((x + y) % 3 != 0) {
    cout << "0\n";
    return;
  }
  if (y < x)
    swap(x, y);
  if (2 * x < y) {
    cout << "0\n";
    return;
  }

  int ile = (y + x) / 3;
  int ile1 = y - x + ile / 2;
  //    debug(ile1, ile);
  cout << dwumian(ile, ile1) << "\n";
}

int32_t main() {
  //	freopen("input.txt", "r", stdin);
  //	freopen("output.txt", "w", stdout);

  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cerr.tie(0);
  cout << setprecision(9) << fixed;
  cerr << setprecision(6) << fixed;
  int test = 1, f;
  // cin>>test;
  F(_test, 0, test) {
    // cout<<"Case #"<<_test + 1<<": ";
    solve();
    //		if(_test == 1)
    //            return 0;
  }
}


Fixed submission:
// #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll long long
#define ld long double
#define pi pair<int, int>
#define pd pair<ld, ld>
#define ft first
#define sd second
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define F(i, a, b) FOR(i, (a), (b)-1)
#define REV(i, a, b) for (int i = (a); i >= (b); i--)
#define VI vector<int>
#define VPI vector<pi>
#define VPD vector<pd>
#define PI 3.14159265
#define all(x) (x).begin(), (x).end()
#define sz(a) (int)((a).size())
#define int long long

template <class TH> void _dbg(const char *sdbg, TH h) {
  cerr << sdbg << "=" << h << "\n";
}
template <class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',')
    cerr << *sdbg++;
  cerr << "=" << h << ",";
  _dbg(sdbg + 1, a...);
}
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
mt19937 r(chrono::steady_clock::now().time_since_epoch().count());
int rand_range(int a, int b) {
  assert(a <= b);
  return a + r() % (b - a + 1);
}
const long long K = 1000;
const long long KK = K * K;
const long long MIL = KK * K;
const long long INF = MIL * MIL;
const long long MOD = MIL + 7;
const long long N = 1e6 + 10, M = 10;

int silnia[N], odsilnia[N];

int dwumian(int a, int b) {
  return (((silnia[a] * odsilnia[b]) % MOD) * odsilnia[a - b]) % MOD;
}

int pot(int x, int p) {
  int tmp = 1;
  for (; p; p /= 2, x = (x * x) % MOD) {
    if (p & 1)
      tmp = (tmp * x) % MOD;
  }
  return tmp;
}

void solve() {
  silnia[0] = 1;
  F(i, 1, N)
  silnia[i] = (silnia[i - 1] * i) % MOD;

  odsilnia[N - 1] = pot(silnia[N - 1], MOD - 2);
  REV(i, N - 2, 0)
  odsilnia[i] = (odsilnia[i + 1] * (i + 1)) % MOD;

  int x, y;
  cin >> x >> y;
  if ((x + y) % 3 != 0) {
    cout << "0\n";
    return;
  }
  if (y < x)
    swap(x, y);
  if (2 * x < y) {
    cout << "0\n";
    return;
  }

  int ile = (y + x) / 3;
  int ile1 = y - x + (ile - y + x) / 2;
  //    debug(ile1, ile);
  cout << dwumian(ile, ile1) << "\n";
}

int32_t main() {
  //	freopen("input.txt", "r", stdin);
  //	freopen("output.txt", "w", stdout);

  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cerr.tie(0);
  cout << setprecision(9) << fixed;
  cerr << setprecision(6) << fixed;
  int test = 1, f;
  // cin>>test;
  F(_test, 0, test) {
    // cout<<"Case #"<<_test + 1<<": ";
    solve();
    //		if(_test == 1)
    //            return 0;
  }
}