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

#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <bitset>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <random>
#define all(x) (x).begin(), (x).end()

using namespace std;
void dout() { cerr << endl; }
typedef long long ll;
template <typename Head, typename... Tail> void dout(Head H, Tail... T) {
  cerr << H << ' ';
  dout(T...);
}

#define debug(x) cout << #x " = " << (x) << endl

using ll = long long;
using pii = pair<ll, ll>;
using ld = long double;
using pll = pair<long long, long long>;

template <typename T> void do_uniq(vector<T> vec) {
  sort(all(vec));
  vec.resize(unique(all(vec)) - vec.begin());
}

#define solvsh
// #define multi
#ifdef solvsh

const int MAXN = 1e5 + 20;

ll mod = 1e9 + 7;

ll gcd(ll x, ll y) { return y == 0 ? x : gcd(y, x % y); }

ll add(ll a, ll b) { return (a + b) % mod; }

ll ml(ll a, ll b) { return (a * b) % mod; }

ll bin_p(ll b, ll p) {
  if (p == 0)
    return 1;
  if (p % 2 == 1)
    return ml(b, bin_p(b, p - 1));
  ll v = bin_p(b, p >> 1);
  return ml(v, v);
}

void solve() {
  int n;
  cin >> n;

  map<pair<ll, ll>, ll> mp1;
  ll cnt0 = 0;

  for (int i = 0; i < n; ++i) {
    ll a, b;
    cin >> a >> b;

    if (a < 0) {
      a *= -1;
      b *= -1;
    }
    if (abs(a) == 0) {
      if (b != 0)
        b = 1;
      else {
        ++cnt0;
        continue;
      }
    } else if (abs(b) == 0) {
      a = 1;
    } else {
      ll g = gcd(abs(a), abs(b));
      a /= g;
      b /= g;
    }
    mp1[{a, b}]++;
  }

  ll answr = 1;

  while (!mp1.empty()) {

    auto e = mp1.begin();
    ll x = e->first.first;
    ll y = e->first.second;
    ll cnt = e->second;

    ll cnt1 = mp1[{-y, x}] + mp1[{y, -x}];

    mp1.erase({x, y});
    mp1.erase({-y, x});
    mp1.erase({y, -x});

    if (cnt1 != 0) {
      ll curr = add(bin_p(2, cnt), bin_p(2, cnt1));
      answr *= (mod + curr - 1) % mod;
      answr %= mod;
    } else {
      answr *= bin_p(2, cnt);
      answr %= mod;
    }
  }

  answr = mod + answr - 1;
  answr %= mod;

  answr += cnt0;
  answr %= mod;

  cout << answr;
}

#else

void solve() {}

#endif

void multisolve() {

  int t;
  cin >> t;

  int i = 1;
  while (t--) {
    //        cout << "Case #" << (i++) << ": ";
    solve();
    cout << "\\n";
  }
}

#define int int
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
  cout << fixed << setprecision(20);

#ifdef multi
  multisolve();
#else
  solve();
  //    gen();
#endif
}


Error: WA

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <bitset>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <random>
#define all(x) (x).begin(), (x).end()

using namespace std;
void dout() { cerr << endl; }
typedef long long ll;
template <typename Head, typename... Tail> void dout(Head H, Tail... T) {
  cerr << H << ' ';
  dout(T...);
}

#define debug(x) cout << #x " = " << (x) << endl

using ll = long long;
using pii = pair<ll, ll>;
using ld = long double;
using pll = pair<long long, long long>;

template <typename T> void do_uniq(vector<T> vec) {
  sort(all(vec));
  vec.resize(unique(all(vec)) - vec.begin());
}

#define solvsh
// #define multi
#ifdef solvsh

const int MAXN = 1e5 + 20;

ll mod = 1e9 + 7;

ll gcd(ll x, ll y) { return y == 0 ? x : gcd(y, x % y); }

ll add(ll a, ll b) { return (a + b) % mod; }

ll ml(ll a, ll b) { return (a * b) % mod; }

ll bin_p(ll b, ll p) {
  if (p == 0)
    return 1;
  if (p % 2 == 1)
    return ml(b, bin_p(b, p - 1));
  ll v = bin_p(b, p >> 1);
  return ml(v, v);
}

void solve() {
  int n;
  cin >> n;

  vector<pair<ll, ll>> v;
  map<pair<ll, ll>, ll> mp1;

  for (int i = 0; i < n; ++i) {
    ll a, b;
    cin >> a >> b;

    if (a < 0) {
      a *= -1;
      b *= -1;
    }

    ll g = gcd(abs(a), abs(b));
    a /= g;
    b /= g;

    mp1[{a, b}]++;
  }

  ll answr = 1;

  while (mp1.size()) {

    auto e = mp1.begin();
    ll x = e->first.first;
    ll y = e->first.second;
    ll cnt = e->second;

    mp1.erase(e);
    ll cnt1 = mp1[{-y, x}] + mp1[{y, -x}];
    mp1.erase({-y, x});
    mp1.erase({y, -x});

    if (cnt1 != 0) {
      ll curr = add(bin_p(2, cnt), bin_p(2, cnt1));
      answr *= (mod + curr - 1) % mod;
      answr %= mod;
    } else {
      answr *= bin_p(2, cnt);
      answr %= mod;
    }
  }

  answr = mod + answr - 1;
  answr %= mod;

  cout << answr;
}

#else

void solve() {}

#endif

void multisolve() {

  int t;
  cin >> t;

  int i = 1;
  while (t--) {
    //        cout << "Case #" << (i++) << ": ";
    solve();
    cout << "\\n";
  }
}

#define int int
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
  cout << fixed << setprecision(20);

#ifdef multi
  multisolve();
#else
  solve();
  //    gen();
#endif
}