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

#include <bits/stdc++.h>
template <typename T> T mod_pow(T x, T n, const T &p) {
  if (x < 0)
    return 0;
  T ret = 1;
  while (n > 0) {
    if (n & 1)
      (ret *= x) %= p;
    (x *= x) %= p;
    n >>= 1;
  }
  return ret;
}
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  for (int i = 0; i < ((int)(v.size())); ++i) {
    if (i)
      os << " ";
    os << v[i];
  }
  return os;
}
using ld = long double;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int n;
  cin >> n;
  map<pair<ll, ll>, ll> mp;
  ll zero = 0;
  ll lzero = 0, rzero = 0;
  for (int i = 0; i < (n); ++i) {
    ll a, b;
    cin >> a >> b;
    if (a == 0 || b == 0) {
      if (a == 0 && b == 0)
        zero++;
      else if (a == 0)
        lzero++;
      else if (b == 0)
        rzero++;
      continue;
    }
    if (a < 0) {
      a = -a;
      b = -b;
    }
    ll g = __gcd(abs(a), abs(b));
    a /= g;
    b /= g;
    mp[{a, b}]++;
  }
  ll ans = mod_pow<ll>(2, lzero, MOD);
  ans += mod_pow<ll>(2, rzero, MOD);
  ans %= MOD;
  ans += MOD - 1;
  ans %= MOD;
  map<pair<ll, ll>, bool> sel;
  for (auto &e : mp) {
    pair<ll, ll> b = {e.first.second, -e.first.first};
    if (b.first < 0) {
      b.first = -b.first;
      b.second = -b.second;
    }
    if (sel[e.first] || sel[b])
      continue;
    sel[e.first] = true;
    sel[b] = true;
    ll now = 0;
    now += mod_pow<ll>(2, e.second, MOD);
    now %= MOD;
    now += mod_pow<ll>(2, mp[b], MOD);
    now %= MOD;
    now += MOD - 1;
    now %= MOD;
    ans *= now;
    ans %= MOD;
  }
  ans += zero;
  ans %= MOD;
  cout << (ans + MOD - 1) % MOD << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
template <typename T> T mod_pow(T x, T n, const T &p) {
  if (x < 0)
    return 0;
  T ret = 1;
  while (n > 0) {
    if (n & 1)
      (ret *= x) %= p;
    (x *= x) %= p;
    n >>= 1;
  }
  return ret;
}
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  for (int i = 0; i < ((int)(v.size())); ++i) {
    if (i)
      os << " ";
    os << v[i];
  }
  return os;
}
using ld = long double;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int n;
  cin >> n;
  map<pair<ll, ll>, ll> mp;
  for (int i = 0; i < (n); ++i) {
    ll a, b;
    cin >> a >> b;
    if (a < 0) {
      a = -a;
      b = -b;
    }
    ll g = __gcd(abs(a), abs(b));
    a /= g;
    b /= g;
    mp[{a, b}]++;
  }
  ll ans = mp[{0, 0}] + 1;
  ans %= MOD;
  map<pair<ll, ll>, bool> sel;
  for (auto &e : mp) {
    if (abs(e.first.first) > abs(e.first.second))
      continue;
    if (e.first.first == 1 && e.first.second == -1)
      continue;
    sel[e.first] = true;
    P b = {e.first.second, -e.first.first};
    if (b.first < 0) {
      b.first = -b.first;
      b.second = -b.second;
    }
    sel[b] = true;
    ll now = 0;
    now += mod_pow<ll>(2, e.second, MOD);
    now %= MOD;
    now += mod_pow<ll>(2, mp[b], MOD);
    now %= MOD;
    now += MOD - 1;
    now %= MOD;
    ans *= now;
    ans %= MOD;
  }
  for (auto &e : mp) {
    if (!sel[e.first]) {
      ans *= mod_pow<ll>(2, e.second, MOD);
      ans %= MOD;
    }
  }
  cout << (ans + MOD - 1) % MOD << endl;
}