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

#include <bits/stdc++.h>
#define ll int64_t
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <math.h>
#define FOR(I, A, B) for (ll I = (A); I <= (B); I++)
#define fo(i, n) for (ll i = 0; i < n; i++)
#define sz(a) ll((a).size())
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x, y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x, y, z)                                                          \\
  cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = "  \\
       << z << endl
#define dbg4(x, y, z, q)                                                       \\
  cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = "  \\
       << z << ", " << #q << " = " << q << endl
#define scan(char_array) scanf("%[^\\n]s", &char_array)
#define IOS                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
using namespace std;

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

const ll MOD = 1e9l + 7;

ll Power(ll base, ll e) {
  if (e == 0)
    return 1;
  ll ans = base;
  e--;
  while (e) {
    if (e & 1)
      ans = (((ans % MOD) * (base % MOD)) % MOD + MOD) % MOD;
    base = (((base % MOD) * (base % MOD)) % MOD + MOD) % MOD;
    e >>= 1;
  }
  return (ans + MOD) % MOD;
}

int main() {
  ll n;
  cin >> n;
  ll aa, bb;
  map<pair<ll, ll>, pair<ll, ll>> mp;
  ll zerr = 0;
  fo(i, n) {
    cin >> aa >> bb;

    // dbg2(aa,bb);
    if (aa == 0 && bb == 0)
      zerr++;

    else if (aa == 0)
      mp[{1, 0}].first++;

    else if (bb == 0)
      mp[{1, 0}].second++;

    else if ((aa < 0) && (bb < 0)) {
      ll h1 = abs(bb);
      ll h2 = abs(aa);
      ll h3 = gcd(h1, h2);
      h1 = h1 / h3;
      h2 = h2 / h3;
      mp[{h2, h1}].first++;

    }

    else if ((aa < 0) || (bb < 0)) {
      ll h1 = abs(bb);
      ll h2 = abs(aa);
      ll h3 = gcd(h1, h2);
      h1 = h1 / h3;
      h2 = h2 / h3;

      mp[{h1, h2}].second++;
      // dbg3(aa,bb,"nee");
    } else {
      ll h1 = abs(bb);
      ll h2 = abs(aa);
      ll h3 = gcd(h1, h2);
      h1 = h1 / h3;
      h2 = h2 / h3;
      mp[{h2, h1}].first++;
      // dbg2(aa,bb);
    }
  }
  ll aans = 1;
  for (auto pp : mp) {
    auto t = pp.second;
    aans = ((aans % MOD) * (Power(2, t.first) + Power(2, t.second) - 1 + MOD) %
            MOD) %
           MOD;
  }
  aans = (aans + zerr) % MOD;
  aans = (aans - 1 + MOD) % MOD;
  cout << aans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define ll int64_t
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <math.h>
#define FOR(I, A, B) for (ll I = (A); I <= (B); I++)
#define fo(i, n) for (ll i = 0; i < n; i++)
#define sz(a) ll((a).size())
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x, y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x, y, z)                                                          \\
  cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = "  \\
       << z << endl
#define dbg4(x, y, z, q)                                                       \\
  cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = "  \\
       << z << ", " << #q << " = " << q << endl
#define scan(char_array) scanf("%[^\\n]s", &char_array)
#define IOS                                                                    \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
using namespace std;

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

const ll MOD = 1e9l + 7;

ll Power(ll base, ll e) {
  if (e == 0)
    return 1;
  ll ans = base;
  e--;
  while (e) {
    if (e & 1)
      ans = (((ans % MOD) * (base % MOD)) % MOD + MOD) % MOD;
    base = (((base % MOD) * (base % MOD)) % MOD + MOD) % MOD;
    e >>= 1;
  }
  return (ans + MOD) % MOD;
}

int main() {
  ll n;
  cin >> n;
  ll aa, bb;
  map<pair<ll, ll>, ll> pos;
  map<pair<ll, ll>, ll> neg;

  fo(i, n) {
    cin >> aa >> bb;
    // dbg2(aa,bb);
    if ((aa < 0) && (bb < 0)) {
      ll h1 = abs(bb);
      ll h2 = abs(aa);
      ll h3 = gcd(h1, h2);
      h1 = h1 / h3;
      h2 = h2 / h3;
      pos[{h2, h1}]++;

    }

    else if ((aa < 0) || (bb < 0)) {
      ll h1 = abs(bb);
      ll h2 = abs(aa);
      ll h3 = gcd(h1, h2);
      h1 = h1 / h3;
      h2 = h2 / h3;

      neg[{h1, h2}]++;
      // dbg3(aa,bb,"nee");
    } else {
      ll h1 = abs(bb);
      ll h2 = abs(aa);
      ll h3 = gcd(h1, h2);
      h1 = h1 / h3;
      h2 = h2 / h3;
      pos[{h2, h1}]++;
      // dbg2(aa,bb);
    }
  }
  ll good = (Power(2, n) - 1) % MOD;
  ll bad = 1;

  vector<pair<ll, ll>> grps;
  for (auto jj : pos) {
    auto t1 = jj.first;

    if (neg.count({t1.first, t1.second})) {
      ll t2 = neg[{t1.first, t1.second}];
      grps.pb({jj.second, t2});
      // dbg("vsdvds");
    }
  }
  ll bad_cnt = 0;
  ll bads = 0;
  for (auto kk : grps) {
    bad_cnt += kk.first;
    bad_cnt += kk.second;
    bads++;
  }
  ll left = n - bad_cnt;
  for (auto kk : grps) {
    // dbg2(kk.first,kk.second);
    bad = (bad * (2)) % MOD;
    bad = (bad * ((Power(2, kk.second - 1)) % MOD)) % MOD;
    bad = (bad * ((Power(2, kk.first - 1)) % MOD)) % MOD;
  }
  bad = ((bad - 1) * (Power(2, left))) % MOD;
  if (sz(grps) == 0)
    bad = 0;

  ll aans = (good - bad) % MOD;
  cout << aans << endl;
}