Problem p02679 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT                                                                   \
  cin.tie(0);                                                                  \
  ios::sync_with_stdio(false);

template <class T> inline bool chmax(T &a, T b) { return a = (a < b) ? b : a; }
template <class T> inline bool chmin(T &a, T b) { return a = (a > b) ? b : a; }

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}

  mint operator-() const { return mint(-x); }

  mint &operator+=(const mint a) {
    if ((x += a.x) >= MOD)
      x -= MOD;
    return *this;
  }

  mint &operator-=(const mint a) {
    if ((x += MOD - a.x) >= MOD)
      x -= MOD;
    return *this;
  }

  mint &operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }

  mint operator+(const mint a) const { return mint(*this) += a; }

  mint operator-(const mint a) const { return mint(*this) -= a; }

  mint operator*(const mint a) const { return mint(*this) *= a; }

  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(MOD - 2); }
  mint &operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

// ユークリッドの互除法
ll euclidean_gcd(ll a, ll b) {
  if (a < b)
    return euclidean_gcd(b, a);

  ll r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }

  return b;
}

int main() {
  INIT;

  ll N;
  cin >> N;
  vector<ll> A(N), B(N);
  rep(i, N) { cin >> A[i] >> B[i]; }

  ll zero = 0;
  map<pair<ll, ll>, pair<ll, ll>> mp;

  rep(i, N) {
    if (A[i] == 0 && B[i] == 0) {
      zero++;
      continue;
    }

    ll g = euclidean_gcd(A[i], B[i]);
    A[i] /= g;
    B[i] /= g;

    if (B[i] < 0) {
      A[i] = -A[i];
      B[i] = -B[i];
    }
    if (B[i] == 0 && A[i] < 0) {
      A[i] = -A[i];
      B[i] = -B[i];
    }

    bool rot90 = (A[i] <= 0);
    if (rot90) {
      ll tmp = A[i];
      A[i] = B[i];
      B[i] = -tmp;
    }

    if (rot90)
      mp[{A[i], B[i]}].first++;
    else
      mp[{A[i], B[i]}].second++;
  }

  // for (auto elem : mp) {
  //     cout << "{" << elem.first.first << ", " << elem.first.second << "}:
  //     {"
  //          << elem.second.first << ", " << elem.second.second << "}" <<
  //          endl;
  // }

  mint ans = 1;
  for (auto p : mp) {
    ll s = p.second.first;
    ll t = p.second.second;

    mint now = 1;
    now += mint(2).pow(s) - 1;
    now += mint(2).pow(t) - 1;
    ans *= now;
  }
  ans -= 1;
  ans += zero;
  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT                                                                   \
  cin.tie(0);                                                                  \
  ios::sync_with_stdio(false);

template <class T> inline bool chmax(T &a, T b) { return a = (a < b) ? b : a; }
template <class T> inline bool chmin(T &a, T b) { return a = (a > b) ? b : a; }

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}

  mint operator-() const { return mint(-x); }

  mint &operator+=(const mint a) {
    if ((x += a.x) >= MOD)
      x -= MOD;
    return *this;
  }

  mint &operator-=(const mint a) {
    if ((x += MOD - a.x) >= MOD)
      x -= MOD;
    return *this;
  }

  mint &operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }

  mint operator+(const mint a) const { return mint(*this) += a; }

  mint operator-(const mint a) const { return mint(*this) -= a; }

  mint operator*(const mint a) const { return mint(*this) *= a; }

  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(MOD - 2); }
  mint &operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

// ユークリッドの互除法
ll euclidean_gcd(ll a, ll b) {
  if (a < b)
    return euclidean_gcd(b, a);

  ll r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }

  return b;
}

int main() {
  INIT;

  ll N;
  cin >> N;
  vector<ll> A(N), B(N);
  rep(i, N) { cin >> A[i] >> B[i]; }

  ll zero = 0;
  map<pair<ll, ll>, pair<ll, ll>> mp;

  rep(i, N) {
    if (A[i] == 0 && B[i] == 0) {
      zero++;
      continue;
    }

    ll g = __gcd(A[i], B[i]);
    A[i] /= g;
    B[i] /= g;

    if (B[i] < 0) {
      A[i] = -A[i];
      B[i] = -B[i];
    }
    if (B[i] == 0 && A[i] < 0) {
      A[i] = -A[i];
      B[i] = -B[i];
    }

    bool rot90 = (A[i] <= 0);
    if (rot90) {
      ll tmp = A[i];
      A[i] = B[i];
      B[i] = -tmp;
    }

    if (rot90)
      mp[{A[i], B[i]}].first++;
    else
      mp[{A[i], B[i]}].second++;
  }

  // for (auto elem : mp) {
  //     cout << "{" << elem.first.first << ", " << elem.first.second << "}:
  //     {"
  //          << elem.second.first << ", " << elem.second.second << "}" <<
  //          endl;
  // }

  mint ans = 1;
  for (auto p : mp) {
    ll s = p.second.first;
    ll t = p.second.second;

    mint now = 1;
    now += mint(2).pow(s) - 1;
    now += mint(2).pow(t) - 1;
    ans *= now;
  }
  ans -= 1;
  ans += zero;
  cout << ans << endl;

  return 0;
}