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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
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() {
  int n;
  cin >> n;
  int zero = 0;
  map<pair<ll, ll>, P> mp;
  rep(i, n) {
    ll x, y;
    cin >> x >> y;
    if (x == 0 && y == 0) {
      zero++;
      continue;
    }
    ll g = gcd(x, y);
    x /= g;
    y /= g;
    if (y < 0)
      x = -x, y = -y;
    if (y == 0 && x < 0)
      x = -x, y = -y;
    bool rot90 = (x <= 0);
    if (rot90) {
      ll tmp = x;
      x = y;
      y = -tmp;
    }
    if (rot90)
      mp[{x, y}].first++;
    else
      mp[{x, y}].second++;
  }

  mint ans = 1;
  for (auto p : mp) {
    int s = p.second.first;
    int 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;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

// マクロ
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 // 10^12
#define MOD 10000007      // 10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  // itmのkeyのfirstはa_i, secondはb_i valueは出現回数
  map<pair<ll, ll>, ll> itm;
  int zero = 0;
  REP(i, n) {
    int a, b;
    cin >> a >> b;
    if (a == 0 && b == 0) {
      zero++;
      continue;
    }

    else if (a == 0) {
      itm[make_pair(0, 1)]++;
    } else if (b == 0) {
      itm[make_pair(1, 0)]++;
    } else {
      int g = __gcd(a, b);
      a = a / g;
      b = b / g;
      if (a > 0)
        itm[make_pair(a, b)]++;
      else
        itm[make_pair(-a, -b)]++;
    }
  }

  // bad_pairは含まれては行けない組のペアの個数をカウントする.
  vector<pair<ll, ll>> bad_pair;
  for (auto pir : itm) {
    ll a = pir.F.F, b = pir.F.S, num = pir.S;
    if (num == 0)
      continue;
    pair<ll, ll> search_pair;
    if (b > 0)
      search_pair = make_pair(b, -a);
    else
      search_pair = make_pair(-b, a);

    ll search_num = itm[search_pair];
    if (search_num != 0)
      bad_pair.PB(make_pair(min(num, search_num), max(num, search_num)));
  }

  ll ans = 1;
  ll bad_itm = 0;
  for (auto pir : bad_pair) {
    ans *= pow(2, pir.F) + pow(2, pir.S) - 1;
    ans %= MOD;
    bad_itm += pir.F + pir.S;
  }

  ll res = pow(2, n - bad_itm / 2 - zero) * sqrt(ans) - 1;
  res %= MOD;
  cout << res + zero << endl;
  return 0;
}