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

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
// const int INF = 2e9;
// const ll INF = 9e18;

ll gcd(ll a, ll b) {
  if (a < 0)
    a = -a;
  if (b < 0)
    b = -b;
  if (a < b)
    swap(a, b);
  if (b == 0)
    return a;
  return a % b == 0 ? b : gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

const int 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; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<pair<ll, ll>> d;
  int zero = 0;
  for (int i = 0; i < N; i++) {
    ll a, b;
    cin >> a >> b;
    if (a == 0 && b == 0)
      zero++;
    else
      d.emplace_back(a, b);
  }
  map<pair<ll, ll>, pair<int, int>> mp;
  for (int i = 0; i < d.size(); i++) {
    ll g = gcd(d[i].first, d[i].second);
    pair<ll, ll> p = make_pair(d[i].first / g, d[i].second / g);
    if (p.second < 0) {
      p.first = -p.first;
      p.second = -p.second;
    }
    if (p.second == 0 && p.first < 0) {
      p.first = -p.first;
    }
    bool rot = false;
    if (p.first <= 0) {
      ll tmp = p.second;
      p.second = -p.first;
      p.first = tmp;
      rot = true;
    }
    if (rot)
      mp[p].second++;
    else
      mp[p].first++;
  }
  mint ans = 1;
  for (auto p : mp) {
    int s = p.second.first;
    int t = p.second.second;
    mint u = 1;
    u += mint(2).pow(s) - 1;
    u += mint(2).pow(t) - 1;
    ans *= u;
  }
  ans -= 1;
  ans += zero;

  cout << ans << "\\n";
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
// const int INF = 2e9;
// const ll INF = 9e18;

ll gcd(ll a, ll b) {
  if (a < 0)
    a = -a;
  if (b < 0)
    b = -b;
  if (a < b)
    swap(a, b);
  return a % b == 0 ? b : gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

const int 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; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<pair<ll, ll>> d;
  int zero = 0;
  for (int i = 0; i < N; i++) {
    ll a, b;
    cin >> a >> b;
    if (a == 0 && b == 0)
      zero++;
    else
      d.emplace_back(a, b);
  }
  map<pair<ll, ll>, pair<int, int>> mp;
  for (int i = 0; i < d.size(); i++) {
    ll g = gcd(d[i].first, d[i].second);
    pair<ll, ll> p = make_pair(d[i].first / g, d[i].second / g);
    if (p.second < 0) {
      p.first = -p.first;
      p.second = -p.second;
    }
    if (p.second == 0 && p.first < 0) {
      p.first = -p.first;
      p.second = -p.second;
    }
    bool rot = false;
    if (p.first <= 0) {
      ll tmp = p.second;
      p.second = -p.first;
      p.first = tmp;
      rot = true;
    }
    if (rot)
      mp[p].second++;
    else
      mp[p].first++;
  }
  mint ans = 1;
  for (auto p : mp) {
    int s = p.second.first;
    int t = p.second.second;
    mint u = 1;
    u += mint(2).pow(s) - 1;
    u += mint(2).pow(t) - 1;
    ans *= u;
  }
  ans -= 1;
  ans += zero;

  cout << ans << "\\n";
}