Problem p02679 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1 << 30) - 1)
#define LINF (1LL << 60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

ll modpow(ll x, ll n) {
  ll res = 1;
  ll mul = x;
  while (n) {
    if (n % 2)
      res = res * mul % MOD;
    mul = mul * mul % MOD;
    n /= 2;
  }
  return res;
}

ll modinv(ll x, ll n) { return modpow(x, n - 2); }

ll a[100010];
ll b[100010];

int main() {
  ll n, cnt0 = 0;
  cin >> n;
  rep(i, n) cin >> a[i] >> b[i];
  map<P, ll> mp;
  vector<P> lp;
  rep(i, n) {
    if (a[i] == 0 && b[i] == 0)
      cnt0++;
    else if (a[i] == 0)
      mp[{0, 1}]++, lp.push_back({0, 1});
    else if (b[i] == 0)
      mp[{1, 0}]++, lp.push_back({1, 0});
    else if (b[i] > 0) {
      ll g = __gcd(abs(a[i]), abs(b[i]));
      mp[{a[i] / g, b[i] / g}]++;
      lp.push_back({a[i] / g, b[i] / g});
    } else {
      ll g = __gcd(abs(a[i]), abs(b[i]));
      mp[{-a[i] / g, -b[i] / g}]++;
      lp.push_back({-a[i] / g, -b[i] / g});
    }
  }

  ll ans = 1;

  map<P, ll> check;
  ll m = lp.size();
  rep(i, m) {
    ll x = lp[i].first;
    ll y = lp[i].second;
    ll c = mp[lp[i]];
    if (check[lp[i]] > 0)
      continue;

    check[lp[i]]++;

    ll d = 0, tmp = 1;
    if (x > 0 && y > 0) {
      d = mp[{-y, x}];
      tmp = modpow(2, c) + modpow(2, d) - 1 + MOD;
      check[{-y, x}]++;
    } else if (x < 0 || y < 0) {
      d = mp[{y, -x}];
      tmp = modpow(2, c) + modpow(2, d) - 1 + MOD;
      check[{y, -x}]++;
    } else if (x == 0 || y == 0) {
      d = mp[{y, x}];
      tmp = modpow(2, c) + modpow(2, d) - 1 + MOD;
      check[{y, x}]++;
    }
    tmp %= MOD;
    ans *= tmp;
    ans %= MOD;
  }
  ans = (ans + cnt0 - 1 + MOD) % MOD;
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1 << 30) - 1)
#define LINF (1LL << 60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

ll modpow(ll x, ll n) {
  ll res = 1;
  ll mul = x;
  while (n) {
    if (n % 2)
      res = res * mul % MOD;
    mul = mul * mul % MOD;
    n /= 2;
  }
  return res;
}

ll modinv(ll x, ll n) { return modpow(x, n - 2); }

ll a[200010];
ll b[200010];

int main() {
  ll n, cnt0 = 0;
  cin >> n;
  rep(i, n) cin >> a[i] >> b[i];
  map<P, ll> mp;
  vector<P> lp;
  rep(i, n) {
    if (a[i] == 0 && b[i] == 0)
      cnt0++;
    else if (a[i] == 0)
      mp[{0, 1}]++, lp.push_back({0, 1});
    else if (b[i] == 0)
      mp[{1, 0}]++, lp.push_back({1, 0});
    else if (b[i] > 0) {
      ll g = __gcd(abs(a[i]), abs(b[i]));
      mp[{a[i] / g, b[i] / g}]++;
      lp.push_back({a[i] / g, b[i] / g});
    } else {
      ll g = __gcd(abs(a[i]), abs(b[i]));
      mp[{-a[i] / g, -b[i] / g}]++;
      lp.push_back({-a[i] / g, -b[i] / g});
    }
  }

  ll ans = 1;

  map<P, ll> check;
  ll m = lp.size();
  rep(i, m) {
    ll x = lp[i].first;
    ll y = lp[i].second;
    ll c = mp[lp[i]];
    if (check[lp[i]] > 0)
      continue;

    check[lp[i]]++;

    ll d = 0, tmp = 1;
    if (x > 0 && y > 0) {
      d = mp[{-y, x}];
      tmp = modpow(2, c) + modpow(2, d) - 1 + MOD;
      check[{-y, x}]++;
    } else if (x < 0 || y < 0) {
      d = mp[{y, -x}];
      tmp = modpow(2, c) + modpow(2, d) - 1 + MOD;
      check[{y, -x}]++;
    } else if (x == 0 || y == 0) {
      d = mp[{y, x}];
      tmp = modpow(2, c) + modpow(2, d) - 1 + MOD;
      check[{y, x}]++;
    }
    tmp %= MOD;
    ans *= tmp;
    ans %= MOD;
  }
  ans = (ans + cnt0 - 1 + MOD) % MOD;
  cout << ans << endl;
  return 0;
}