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

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

#define REP(i, n) for (ll(i) = 0; (i) < (ll)(n); ++(i))
#define REPN(i, m, n) for (ll(i) = m; (i) < (ll)(n); ++(i))
#define REP_REV(i, n) for (ll(i) = (ll)(n)-1; (i) >= 0; --(i))
#define REPN_REV(i, m, n) for (ll(i) = (ll)(n)-1; (i) >= m; --(i))
#define ALL(x) (x).begin(), (x).end()
#define Ceil(x, n) (((((x)) + ((n)-1)) / n))
#define CeilN(x, n) (((((x)) + ((n)-1)) / n) * n)

#define INF 2e7
#define INF_LL 1LL << 60
#define ll long long
typedef pair<ll, ll> P;

struct modint {
  using i64 = int_fast64_t;
  i64 a;
  static constexpr i64 MOD = 1000000007;
  modint() { a = 0; }
  modint(i64 a_) {
    a = a_ % MOD;
    if (a < 0)
      a += MOD;
  }
  modint inv() const {
    i64 n = 1, m = MOD - 2, A = a;
    while (m) {
      if (m & 1)
        (n *= A) %= MOD;
      (A *= A) %= MOD;
      m >>= 1;
    }
    modint y(n);
    return y;
  }
  bool operator==(const modint &x) { return a == x.a; }
  bool operator!=(const modint &x) { return a != x.a; }
  modint &operator=(const modint &x) {
    a = x.a;
    return *this;
  }
  modint operator+(const modint &x) {
    modint y;
    y.a = a + x.a;
    if (y.a > MOD)
      y.a -= MOD;
    return y;
  }
  modint operator-(const modint &x) {
    modint y;
    y.a = a - x.a;
    if (y.a < 0)
      y.a += MOD;
    return y;
  }
  modint operator*(const modint &x) {
    modint y;
    y.a = (a * x.a) % MOD;
    return y;
  }
  modint operator/(const modint &x) {
    modint y;
    y.a = (a * x.inv().a) % MOD;
    return y;
  }
  modint &operator+=(const modint &x) {
    a += x.a;
    if (a >= MOD)
      a -= MOD;
    return *this;
  }
  modint &operator-=(const modint &x) {
    a -= x.a;
    if (a < 0)
      a += MOD;
    return *this;
  }
  modint &operator*=(const modint &x) {
    (a *= x.a) %= MOD;
    return *this;
  }
  modint &operator/=(const modint &x) {
    (a *= x.inv().a) %= MOD;
    return *this;
  }
};
istream &operator>>(istream &in, modint &x) {
  int_fast64_t a_;
  in >> a_;
  modint y(a_);
  x = y;
  return in;
}
ostream &operator<<(ostream &out, const modint &x) {
  out << x.a;
  return out;
}
modint pwr(int_fast64_t a, int_fast64_t b) {
  modint _;
  int_fast64_t n = 1, A = a;
  while (b) {
    if (b & 1)
      (n *= A) %= modint::MOD;
    (A *= A) %= modint::MOD;
    b >>= 1;
  }
  _.a = n;
  return _;
}

ll gcd(ll a, ll b) {
  ll tmp;
  if (a < b) {
    tmp = a;
    a = b;
    b = tmp;
  }
  if (b == 0)
    return a;

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

  return b;
}

int main() {
  int n;
  cin >> n;
  int both_zero = 0;
  map<P, P> mp;
  modint ans = 1;

  REP(i, n) {
    ll x, y;
    cin >> x >> y;
    if (x == 0 && y == 0) {
      both_zero++;
      continue;
    }

    ll gcd_ = gcd(x, y);
    x /= gcd_, y /= gcd_;
    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++;
  }

  for (auto p : mp) {
    int s = p.second.first;
    int t = p.second.second;
    modint now = 1; /* なにも選ばない */
    now += pwr(2, s) - 1;
    now += pwr(2, t) - 1;
    ans *= now;
  }

  ans -= 1;
  ans += both_zero;

  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

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

#define REP(i, n) for (ll(i) = 0; (i) < (ll)(n); ++(i))
#define REPN(i, m, n) for (ll(i) = m; (i) < (ll)(n); ++(i))
#define REP_REV(i, n) for (ll(i) = (ll)(n)-1; (i) >= 0; --(i))
#define REPN_REV(i, m, n) for (ll(i) = (ll)(n)-1; (i) >= m; --(i))
#define ALL(x) (x).begin(), (x).end()
#define Ceil(x, n) (((((x)) + ((n)-1)) / n))
#define CeilN(x, n) (((((x)) + ((n)-1)) / n) * n)

#define INF 2e7
#define INF_LL 1LL << 60
#define ll long long
typedef pair<ll, ll> P;

struct modint {
  using i64 = int_fast64_t;
  i64 a;
  static constexpr i64 MOD = 1000000007;
  modint() { a = 0; }
  modint(i64 a_) {
    a = a_ % MOD;
    if (a < 0)
      a += MOD;
  }
  modint inv() const {
    i64 n = 1, m = MOD - 2, A = a;
    while (m) {
      if (m & 1)
        (n *= A) %= MOD;
      (A *= A) %= MOD;
      m >>= 1;
    }
    modint y(n);
    return y;
  }
  bool operator==(const modint &x) { return a == x.a; }
  bool operator!=(const modint &x) { return a != x.a; }
  modint &operator=(const modint &x) {
    a = x.a;
    return *this;
  }
  modint operator+(const modint &x) {
    modint y;
    y.a = a + x.a;
    if (y.a > MOD)
      y.a -= MOD;
    return y;
  }
  modint operator-(const modint &x) {
    modint y;
    y.a = a - x.a;
    if (y.a < 0)
      y.a += MOD;
    return y;
  }
  modint operator*(const modint &x) {
    modint y;
    y.a = (a * x.a) % MOD;
    return y;
  }
  modint operator/(const modint &x) {
    modint y;
    y.a = (a * x.inv().a) % MOD;
    return y;
  }
  modint &operator+=(const modint &x) {
    a += x.a;
    if (a >= MOD)
      a -= MOD;
    return *this;
  }
  modint &operator-=(const modint &x) {
    a -= x.a;
    if (a < 0)
      a += MOD;
    return *this;
  }
  modint &operator*=(const modint &x) {
    (a *= x.a) %= MOD;
    return *this;
  }
  modint &operator/=(const modint &x) {
    (a *= x.inv().a) %= MOD;
    return *this;
  }
};
istream &operator>>(istream &in, modint &x) {
  int_fast64_t a_;
  in >> a_;
  modint y(a_);
  x = y;
  return in;
}
ostream &operator<<(ostream &out, const modint &x) {
  out << x.a;
  return out;
}
modint pwr(int_fast64_t a, int_fast64_t b) {
  modint _;
  int_fast64_t n = 1, A = a;
  while (b) {
    if (b & 1)
      (n *= A) %= modint::MOD;
    (A *= A) %= modint::MOD;
    b >>= 1;
  }
  _.a = n;
  return _;
}

ll gcd(ll a, ll b) {
  ll tmp;
  if (a < b) {
    tmp = a;
    a = b;
    b = tmp;
  }

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

  return b;
}

int main() {
  int n;
  cin >> n;
  int both_zero = 0;
  map<P, P> mp;
  modint ans = 1;

  REP(i, n) {
    ll x, y;
    cin >> x >> y;
    if (x == 0 && y == 0) {
      both_zero++;
      continue;
    }

    ll gcd_ = gcd(x, y);
    x /= gcd_, y /= gcd_;
    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++;
  }

  for (auto p : mp) {
    int s = p.second.first;
    int t = p.second.second;
    modint now = 1; /* なにも選ばない */
    now += pwr(2, s) - 1;
    now += pwr(2, t) - 1;
    ans *= now;
  }

  ans -= 1;
  ans += both_zero;

  cout << ans << endl;

  return 0;
}