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

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ldouble = long double;

const int mod = 1000000007;
// const int mod = 998244353;

struct mint {
  int64_t x;
  mint(int64_t 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(int64_t 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) { 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;
  vector<ll> b(n);
  vector<ll> a(n);
  rep(i, n) { cin >> a[i] >> b[i]; }

  map<pair<ll, ll>, P> mp;
  vector<int> jj(3);
  rep(i, n) {
    if (a[i] != 0 && b[i] != 0) {
      ll a_ = abs(a[i]);
      ll b_ = abs(b[i]);
      if (a_ < b_) {
        swap(a_, b_);
      }
      while (a_ % b_) {
        ll cc = a_ % b_;
        a_ = b_;
        b_ = cc;
      }
      a[i] /= b_;
      b[i] /= b_;

      if ((a[i] < 0 && b[i] < 0) || (a[i] > 0 && b[i] > 0)) {
        a[i] = abs(a[i]);
        b[i] = abs(b[i]);
        mp[make_pair(a[i], b[i])].first++;
      } else {
        a[i] = abs(a[i]);
        b[i] = abs(b[i]);
        mp[make_pair(b[i], a[i])].second++;
      }
    } else if (a[i] == 0 && b[i] != 0) {
      jj[0]++;
    } else if (a[i] != 0 && b[i] == 0) {
      jj[1]++;
    } else {
      jj[2]++;
    }
  }

  mint ans = 1;
  for (auto x : mp) {
    ans *= (mint(2).pow(x.second.first) + mint(2).pow(x.second.second) - 1);
  }
  ans *= (mint(2).pow(jj[0]) + mint(2).pow(jj[1]) - 1);

  ans += jj[2];

  ans -= 1;

  cout << ans << endl;
}

Error: 0

Fixed submission:

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

const int mod = 1000000007;
// const int mod = 998244353;

struct mint {
  int64_t x;
  mint(int64_t 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(int64_t 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) { 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;
  vector<double> a(n), b(n);
  rep(i, n) { cin >> a[i] >> b[i]; }

  map<double, int> mp;
  rep(i, n) {
    if (a[i])
      mp[b[i] / a[i]]++;
    else
      mp[M_PI * 12]++;
  }

  mint ans = 1;
  mint m2 = 2;
  for (auto x : mp) {
    if (x.second == -1)
      continue;
    if (!mp.count(-1 / x.first)) {
      ans *= m2.pow(x.second);
    } else {
      ans *= (m2.pow(x.second) + m2.pow(mp[-1 / x.first]) - 1);
      mp[-1 / x.first] = -1;
    }
  }

  cout << ans - 1 << endl;
}