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

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> //required
// #include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define lb long double
#define pb push_back
#define loop(i, start, n) for (ll i = start; i < n; i++)
#define rloop(i, n, start) for (ll i = n; i >= start; i--)
#define mod 1000000007
#define endl "\\n"
#define INF 1e15
#define NEG_INF -1e15
#define pll pair<ll, ll>
#define x first
#define y second
#define all(x) x.begin(), x.end()
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\\'' << x << '\\''; }
void __print(const char *x) { cerr << '\\"' << x << '\\"'; }
void __print(const string &x) { cerr << '\\"' << x << '\\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V> void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T> void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x)
    cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v))
    cerr << ", ";
  _print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...)                                                            \\
  cerr << "[" << #x << "] = [";                                                \\
  _print(x)
#else
#define debug(x...)
#endif
// template <typename T> using ordered_set =  tree<T, null_type, less<T>,
// rb_tree_tag, tree_order_statistics_node_update>; using namespace __gnu_pbds;
ll power(ll x, ll y) {
  ll temp, f;
  if (y == 0)
    return 1;
  temp = power(x, y / 2) % mod;
  if (y % 2 == 0)
    return (temp * temp) % mod;
  else {
    f = (x * temp) % mod;
    f = (f * temp) % mod;
    return f;
  }
}
map<pll, ll> pos, neg;
int main() {
  IOS;
  ll n;
  cin >> n;
  ll num = 0, den = 0, both = 0;
  ll x, y;
  loop(i, 1, n + 1) {
    cin >> x >> y;
    if (x == 0 && y == 0) {
      both++;
      continue;
    }
    ll a = (x > 0 ? 1 : -1), b = (y > 0 ? 1 : -1);
    x = abs(x), y = abs(y);
    if (x == 0) {
      num++;
      continue;
    }
    if (y == 0) {
      den++;
      continue;
    }
    ll temp = __gcd(x, y);
    x = x / temp, y = y / temp;
    debug(x, y, a * b);
    if (a * b > 0)
      pos[{x, y}]++;
    else
      neg[{x, y}]++;
  }

  ll ans = 1;
  for (auto &node : pos)
    ans = (ans *
           (power(2, pos[{node.x.x, node.x.y}]) +
            power(2, neg[{node.x.y, node.x.x}]) + mod - 1) %
           mod) %
          mod;

  debug(ans);
  for (auto &node : neg) {
    debug(node);
    if (pos.find({node.x.y, node.x.x}) == pos.end())
      ans = (ans * power(2, neg[{node.x.x, node.x.y}])) % mod;
  }
  debug(ans);
  ans = (ans * (power(2, num) + power(2, den) + mod - 1) % mod) % mod;
  ans = (ans + both + mod - 1) % mod;
  cout << ans << endl;
}

Error: 0
[a[i], t1, t2] = [{1,2}, 5000006, 5000620]
[a[i], t1, t2] = [{-1,1}, 1, 1]
[a[i], t1, t2] = [{2,-1}, 2, 2]
[node.x, inv1, inv2] = [{5000006,5000620}, 2, 2]
[ans] = [3]
[node.x, inv1] = [{1,1}, 1]
[ans, den, num] = [6, 0, 0]


Fixed submission:

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> //required
// #include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define lb long double
#define pb push_back
#define loop(i, start, n) for (ll i = start; i < n; i++)
#define rloop(i, n, start) for (ll i = n; i >= start; i--)
#define mod 1000000007
#define endl "\\n"
#define INF 1e15
#define NEG_INF -1e15
#define pll pair<ll, ll>
#define x first
#define y second
#define all(x) x.begin(), x.end()
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\\'' << x << '\\''; }
void __print(const char *x) { cerr << '\\"' << x << '\\"'; }
void __print(const string &x) { cerr << '\\"' << x << '\\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V> void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T> void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x)
    cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v))
    cerr << ", ";
  _print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...)                                                            \\
  cerr << "[" << #x << "] = [";                                                \\
  _print(x)
#else
#define debug(x...)
#endif
// template <typename T> using ordered_set =  tree<T, null_type, less<T>,
// rb_tree_tag, tree_order_statistics_node_update>; using namespace __gnu_pbds;

ll power(ll x, ll y) {
  ll temp, f;
  if (y == 0)
    return 1;
  temp = power(x, y / 2) % mod;
  if (y % 2 == 0)
    return (temp * temp) % mod;
  else {
    f = (x * temp) % mod;
    f = (f * temp) % mod;
    return f;
  }
}
ll gcdExtended(ll a, ll b, ll *x, ll *y) {
  // Base Case
  if (a == 0) {
    *x = 0, *y = 1;
    return b;
  }

  ll x1, y1; // To store results of recursive call
  ll gcd = gcdExtended(b % a, a, &x1, &y1);

  // Update x and y using results of recursive
  // call
  *x = y1 - (b / a) * x1;
  *y = x1;
  return gcd;
}
ll modInverse(ll a, ll m) {
  ll x, y;
  ll g = gcdExtended(a, m, &x, &y);
  if (g != 1)
    assert(0);
  else {

    ll res = (x % m + m) % m;
    return res;
  }
}
map<pll, ll> hash1, hash2;
ll MOD1 = 10000011, MOD2 = 10001239;
int main() {
  IOS;
  ll n;
  cin >> n;
  pll a[n + 1];
  ll no[n + 1], num = 0, den = 0;
  loop(i, 1, n + 1) {
    cin >> a[i].x >> a[i].y;
    ll a1 = (a[i].x > 0 ? 1 : -1), b1 = (a[i].y > 0 ? 1 : -1);

    if (a[i].x == 0 && a[i].y == 0)
      continue;

    if (a[i].y != 0 && a[i].x != 0) {
      ll t1 =
          (abs(a[i].x) % MOD1 * modInverse(abs(a[i].y) % MOD1, MOD1)) % MOD1;
      ll t2 =
          (abs(a[i].x) % MOD2 * modInverse(abs(a[i].y) % MOD2, MOD2)) % MOD2;
      debug(a[i], t1, t2);
      if (a1 * b1 > 0)
        hash1[{t1, t2}]++;
      else
        hash2[{t1, t2}]++;
    } else {
      if (a[i].y == 0)
        den++;
      else
        num++;
    }
  }

  ll ans = 1;
  for (auto &node : hash1) {
    ll inv1 = modInverse(node.x.x, MOD1), inv2 = modInverse(node.x.y, MOD2);
    debug(node.x, inv1, inv2);
    ans = (ans *
           (power(2, hash1[{node.x.x, node.x.y}]) +
            power(2, hash2[{inv1, inv2}]) + mod - 1) %
           mod) %
          mod;
  }
  debug(ans);
  for (auto &node : hash2) {
    ll inv1 = modInverse(node.x.x, MOD1), inv2 = modInverse(node.x.y, MOD2);
    if (hash1.find({inv1, inv2}) == hash1.end()) {
      debug(node.x, inv1);
      ans = (ans * (power(2, hash2[{node.x.x, node.x.y}])) % mod) % mod;
    }
  }
  debug(ans, den, num);
  ans = (ans * (power(2, den) + power(2, num) + mod - 1)) % mod;
  ans = (ans + mod - 1) % mod;
  cout << ans << endl;
}