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

#include <cmath>
#include <fstream>
#include <iostream>
#include <map>

// BE CAREFUL WITH HASH TABLE & UNORDERED MAP
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;

#define MOD 1000000007
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, b) FOR(i, 0, b)
#define RFO(i, a, b) for (int i = (b - 1); i >= (a); i--)
#define RF0(i, b) RFO(i, 0, b)
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mp(a, b) make_pair(a, b)
#define add(a, b) ((int)(((ll)(a) + (b)) % MOD))
#define mul(a, b) ((int)(((ll)(a) * (b)) % MOD))
#define PB emplace_back
#define F first
#define S second

// ifstream cin ("cinput.in");
// ofstream cout ("coutput.out");

int N;
int pw2[200001];
ll A, B;
map<pll, pii> track;

ll gcd(ll a, ll b) { // MAKE SURE NONE IS NEGATIVE
  while (a != 0 && b != 0) {
    if (a > b)
      a = a % b;
    else
      b = b % a;
  }
  if (a == 0)
    return b;
  else
    return a;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N;

  pw2[0] = 1;
  FOR(i, 1, N + 1) pw2[i] = mul(pw2[i - 1], 2);

  int zz = 0;
  F0R(i, N) {
    cin >> A >> B;
    if (A == 0 && B == 0) {
      zz++;
      continue;
    }

    ll C = gcd(abs(A), abs(B));
    A /= C;
    B /= C;
    if (track.count(mp(-A, -B)))
      track[mp(-A, -B)].F++;
    else if (track.count(mp(-B, A)))
      track[mp(-B, A)].S++;
    else if (track.count(mp(B, -A)))
      track[mp(B, -A)].S++;
    else
      track[mp(A, B)].F++;
  }
  int ans = 1;
  for (auto it = track.begin(); it != track.end(); it++) {
    ans = mul(ans, add(add(pw2[(it->S).F], pw2[(it->S).S]), MOD - 1));
  }
  cout << add(ans, MOD - 1) + zz << '\\n';
}

// edge: 0

Error: WA

Fixed submission:

#include <cmath>
#include <fstream>
#include <iostream>
#include <map>

// BE CAREFUL WITH HASH TABLE & UNORDERED MAP
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;

#define MOD 1000000007
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, b) FOR(i, 0, b)
#define RFO(i, a, b) for (int i = (b - 1); i >= (a); i--)
#define RF0(i, b) RFO(i, 0, b)
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mp(a, b) make_pair(a, b)
#define add(a, b) ((int)(((ll)(a) + (b)) % MOD))
#define mul(a, b) ((int)(((ll)(a) * (b)) % MOD))
#define PB emplace_back
#define F first
#define S second

// ifstream cin ("cinput.in");
// ofstream cout ("coutput.out");

int N;
int pw2[200001];
ll A, B;
map<pll, pii> track;

ll gcd(ll a, ll b) { // MAKE SURE NONE IS NEGATIVE
  while (a != 0 && b != 0) {
    if (a > b)
      a = a % b;
    else
      b = b % a;
  }
  if (a == 0)
    return b;
  else
    return a;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N;

  pw2[0] = 1;
  FOR(i, 1, N + 1) pw2[i] = mul(pw2[i - 1], 2);

  int zz = 0;
  F0R(i, N) {
    cin >> A >> B;
    if (A != 0 && B != 0) {
      zz++;
      continue;
    }

    ll C = gcd(abs(A), abs(B));
    A /= C;
    B /= C;
    if (track.count(mp(-A, -B)))
      track[mp(-A, -B)].F++;
    else if (track.count(mp(-B, A)))
      track[mp(-B, A)].S++;
    else if (track.count(mp(B, -A)))
      track[mp(B, -A)].S++;
    else
      track[mp(A, B)].F++;
  }
  int ans = 1;
  ans = mul(ans, zz + 1);
  for (auto it = track.begin(); it != track.end(); it++) {
    ans = mul(ans, add(add(pw2[(it->S).F], pw2[(it->S).S]), MOD - 1));
  }
  cout << add(ans, MOD - 1) << '\\n';
}

// edge: 0