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

#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll, ll> P;
typedef priority_queue<P, vector<P>, greater<P>> P_queue;

const ll MOD = 998244353;
const ll mod = 1000000007;
const ll INF = 1e15;
const double PI = 3.1415926535897932;
const double LIT = 0.000000000001;

#define REP(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define rep(i, n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a, b) a = (a + b) % mod
#define MUL(a, b) a = (a * b) % mod

ll yaku(ll a, ll b) {
  if (a > b)
    return yaku(b, a);
  return b % a ? yaku(b % a, a) : a;
}
map<P, ll> d;
ll Count = -1;

void input() {
  ll x, y;
  cin >> x >> y;
  P X;
  if (!x) {
    if (!y) {
      Count++;
      return;
    }
    X = mp(0, -1);
  } else if (!y)
    X = mp(1, 0);
  else {
    ll K = yaku(abs(x), abs(y));
    if (x < 0)
      K = -K;
    X = mp(x / K, y / K);
  }
  d[X]++;
  return;
}

ll ruijou(ll n, ll k) {
  if (!k)
    return 1;
  ll a = ruijou(n, k / 2);
  a = (a * a) % mod;
  return k % 2 ? (a * n) % mod : a;
}

P tsui(P x) {
  return x.second >= 0 ? mp(x.second, -x.first) : mp(-x.second, x.first);
}

int main() {
  ll N;
  cin >> N;
  rep(i, N) input();
  ll ans = 1;
  for (auto itr = d.begin(); itr != d.end(); itr++) {
    P A = itr->first;
    // cout<<A.first<<' '<<A.second<<':'<<d[A]<<endl;
    if (A.second >= 0) {
      P B = tsui(A);
      if (d.count(B)) {
        ll kari = ruijou(2, d[B]);
        ADD(kari, mod - 1);
        kari += ruijou(2, d[A]);
        MUL(ans, kari);
      } else
        MUL(ans, ruijou(2, d[A]));
    } else {
      P B = tsui(A);
      if (!d.count(B))
        MUL(ans, ruijou(2, d[A]));
    }
  }
  ADD(ans, mod + Count);
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll, ll> P;
typedef priority_queue<P, vector<P>, greater<P>> P_queue;

const ll MOD = 998244353;
const ll mod = 1000000007;
const ll INF = 1e15;
const double PI = 3.1415926535897932;
const double LIT = 0.000000000001;

#define REP(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define rep(i, n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a, b) a = (a + b) % mod
#define MUL(a, b) a = (a * b) % mod

ll yaku(ll a, ll b) {
  if (a > b)
    return yaku(b, a);
  return b % a ? yaku(b % a, a) : a;
}
map<P, ll> d;

void input() {
  ll x, y;
  cin >> x >> y;
  P X;
  if (!x) {
    if (!y)
      return;
    X = mp(0, -1);
  }
  if (!y)
    X = mp(1, 0);
  ll K = yaku(abs(x), abs(y));
  if (x < 0)
    K = -K;
  X = mp(x / K, y / K);
  d[X]++;
  return;
}

ll ruijou(ll n, ll k) {
  if (!k)
    return 1;
  ll a = ruijou(n, k / 2);
  a = (a * a) % mod;
  return k % 2 ? (a * n) % mod : a;
}

P tsui(P x) {
  return x.second >= 0 ? mp(x.second, -x.first) : mp(-x.second, x.first);
}

int main() {
  ll N;
  cin >> N;
  rep(i, N) input();
  ll ans = 1;
  for (auto itr = d.begin(); itr != d.end(); itr++) {
    P A = itr->first;
    // cout<<A.first<<' '<<A.second<<':'<<d[A]<<endl;
    if (A.second >= 0) {
      P B = tsui(A);
      if (d.count(B)) {
        ll kari = ruijou(2, d[B]);
        ADD(kari, mod - 1);
        kari += ruijou(2, d[A]);
        MUL(ans, kari);
      } else
        MUL(ans, ruijou(2, d[A]));
    } else {
      P B = tsui(A);
      if (!d.count(B))
        MUL(ans, ruijou(2, d[A]));
    }
  }
  ADD(ans, mod - 1);
  cout << ans << endl;
}