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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef pair<ll, pair<ll, ll> > P;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;

#define reps(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) reps(i, 0, n)
#define REP(i, n) reps(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)((x).size()))

const double PI = acos(-1.0);
const double EPS = 1e-9;
const ll INF = 1e15 + 10;
const ll mod = 1e9 + 7; // 998244353;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define print(x) cerr << #x << " is " << x << endl;

map<P, int> m;
set<P> s;
int N;
ll powx[200001];

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

int main() {
  cin >> N;
  int z_z = 0, z_non = 0, non_z = 0;
  rep(i, N) {
    ll a, b;
    cin >> a >> b;
    if (a == 0 && b == 0) {
      z_z++;
    } else if (a == 0) {
      z_non++;
    } else if (b == 0) {
      non_z++;
    } else {
      ll gg = gcd(a, b);
      a /= gg;
      b /= gg;
      if (a < 0)
        a = -a, b = -b;
      m[P(a, b)]++;
    }
  }
  // N -= z_z - z_non - non_z;

  powx[0] = 1;
  rep(i, N) powx[i + 1] = powx[i] * 2 % mod; // 2^N;

  ll ans = (powx[z_non] + powx[non_z] - 1) % mod;

  for (auto ite = m.begin(); ite != m.end(); ite++) {
    ll a = ite->first.first;
    ll b = ite->first.second;
    int cnt = ite->second;
    ll aa = -b;
    ll bb = a;
    if (aa < 0)
      aa = -aa, bb = -bb;
    if (s.find(P(aa, bb)) == s.end()) {
      s.insert(P(aa, bb));
      s.insert(P(a, b));
      int cnt2 = m[P(aa, bb)];
      // fprintf(stderr, "%d (%d, %d), %d\\n", cnt, a, b, cnt2);
      ll tmp = (powx[cnt] + powx[cnt2] - 1) % mod;

      (ans *= tmp) %= mod;
    }
  }
  cout << (ans + mod + z_z - 1) % mod;

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef pair<ll, pair<ll, ll> > P;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;

#define reps(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) reps(i, 0, n)
#define REP(i, n) reps(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)((x).size()))

const double PI = acos(-1.0);
const double EPS = 1e-9;
const ll INF = 1e15 + 10;
const ll mod = 1e9 + 7; // 998244353;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define print(x) cerr << #x << " is " << x << endl;

map<P, int> m;
set<P> s;
// vector<double> theta;
int N;
ll powx[200001], A[200001], B[200001];

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

int main() {
  cin >> N;
  int z_z = 0, z_non = 0, non_z = 0;
  rep(i, N) {
    ll a, b;
    cin >> a >> b;
    A[i] = a, B[i] = b;
    if (a == 0 && b == 0) {
      z_z++;
    } else if (a == 0) {
      z_non++;
    } else if (b == 0) {
      non_z++;
    } else {
      int gg = gcd(a, b);
      a /= gg;
      b /= gg;
      if (a < 0)
        a = -a, b = -b;
      m[P(a, b)]++;
    }
  }
  // sort(ALL(theta));
  N -= z_z - z_non - non_z;

  powx[0] = 1;
  rep(i, N) powx[i + 1] = powx[i] * 2 % mod; // 2^N;

  ll ans = (powx[z_non] + powx[non_z] - 1) % mod;

  for (auto ite = m.begin(); ite != m.end(); ite++) {
    ll a = ite->first.first;
    ll b = ite->first.second;
    int cnt = ite->second;
    ll aa = -b;
    ll bb = a;
    if (aa < 0)
      aa = -aa, bb = -bb;
    if (s.find(P(aa, bb)) == s.end()) {
      s.insert(P(aa, bb));
      s.insert(P(a, b));
      int cnt2 = m[P(aa, bb)];
      // fprintf(stderr, "%d (%d, %d), %d\\n", cnt, a, b, cnt2);
      ll tmp = (powx[cnt] + powx[cnt2] - 1) % mod;

      (ans *= tmp) %= mod;
    }
  }
  cout << (ans + mod + z_z - 1) % mod;

  return 0;
}