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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = 1e18;

#define PB push_back
#define MP make_pair
#define F first
#define S second

long long POW(long long x, long long n) {
  long long ret = 1;
  while (n > 0) {
    if (n & 1)
      ret = ret * x % MOD;
    x = x * x % MOD;
    n >>= 1;
  }
  return ret;
}

template <typename T, typename U> bool chmax(T &max, const U &x) {
  if (max < x) {
    max = x;
    return true;
  }
  return false;
}

template <typename T, typename U> bool chmin(T &min, const U &x) {
  if (min > x) {
    min = x;
    return true;
  }
  return false;
}

int main() {
  ll n;
  map<pair<ll, ll>, ll> ab;
  cin >> n;
  ll corner = 0;

  for (ll j = 0; j < n; j++) {
    ll a, b;
    cin >> a >> b;
    ll d = abs(__gcd(a, b));
    if (a < 0) {
      a *= -1;
      b *= -1;
    }
    if (a == b && a == 0) {
      corner++;
    } else if (a == 0) {
      ab[MP(0, 1)]++;
    } else if (b == 0) {
      ab[MP(1, 0)]++;
    } else {
      ab[MP(a / d, b / d)]++;
    }
  }

  vector<ll> ans;
  ans.PB(0);

  map<pair<ll, ll>, bool> used;
  for (auto iter = ab.begin(); iter != ab.end(); iter++) {
    if (used[MP(iter->F.F, iter->F.S)])
      continue;
    if (iter->S == 0)
      continue;
    if (ab[(MP(iter->F.S, -iter->F.F))] != 0) {
      ans.PB((POW(2, iter->S) + POW(2, ab[MP(iter->F.S, -iter->F.F)]) - 1) %
             MOD);
      used[MP(iter->F.S, -iter->F.F)] = true;
    } else if (ab[(MP(-iter->F.S, iter->F.F))] != 0) {
      ans.PB((POW(2, iter->S) + POW(2, ab[MP(-iter->F.S, iter->F.F)]) - 1) %
             MOD);
      used[MP(-iter->F.S, iter->F.F)] = true;
    } else {
      ans[0] = ans[0] + iter->S;
    }
  }
  ll fa = 1;
  ans[0] = POW(2, ans[0]);
  for (auto e : ans) {
    fa = fa * e % MOD;
  }
  fa = fa - 1 + corner;
  if (fa - 1 + corner < 0) {
    fa = fa + MOD;
  }
  cout << fa << endl;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
const ll MOD = 1000000007;
const ll INF = 1e18;

#define PB push_back
#define MP make_pair
#define F first
#define S second

long long pow(long long x, long long n) {
  long long ret = 1;
  while (n > 0) {
    if (n & 1)
      ret = ret * x % MOD;
    x = x * x % MOD;
    n >>= 1;
  }
  return ret;
}

template <typename T, typename U> bool chmax(T &max, const U &x) {
  if (max < x) {
    max = x;
    return true;
  }
  return false;
}

template <typename T, typename U> bool chmin(T &min, const U &x) {
  if (min > x) {
    min = x;
    return true;
  }
  return false;
}

int main() {
  ll n;
  vector<pair<double, ll>> ab;
  vector<ll> chokkou;
  cin >> n;
  for (ll j = 0; j < n; j++) {
    ll a, b;
    cin >> a >> b;
    bool f = true;
    ll now;
    for (ll i = 0; i < ab.size(); i++) {
      if (abs(ab[i].F - b / a) < 0.00000000000001) {
        ab[i].S++;
        f = false;
        now = i;
      }
    }
    if (f) {
      ab.PB(MP(b / a, 1));
      chokkou.PB(-1);
      now = chokkou.size();
    }
    for (ll i = 0; i < ab.size(); i++) {
      if (ab[i].F / a * b + 1 < 0.00000000000001) {
        chokkou[now] = i;
      }
    }
  }

  ll ans = 0;
  ll base = 0;
  vector<ll> niku;

  for (ll i = 0; i < ab.size(); i++) {
    if (chokkou[i] == -1) {
      base += ab[i].S;
    } else {
      niku.PB(pow(2, ab[i].S) * pow(2, ab[chokkou[i]].S) - 1);
      chokkou[chokkou[i]] = -1;
      cout << endl;
    }
  }
  ans = pow(2, base);
  for (auto &e : niku) {
    ans = ans * e % MOD;
  }
  cout << ans - 1 << endl;
}