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

#define ENABLE_LL
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;

#ifdef ENABLE_LL
#define int long long
#endif

#ifdef ENABLE_LL
#define I "%lld"
#define II "%lld%lld"
#define III "%lld%lld%lld"
#define IIII "%lld%lld%lld%lld"
#define IN "%lld\\n"
#define IIN "%lld%lld\\n"
#define IIIN "%lld%lld%lld\\n"
#define IIIIN "%lld%lld%lld%lld\\n"
#else
#define I "%d"
#define II "%d%d"
#define III "%d%d%d"
#define IIII "%d%d%d%d"
#define IN "%d\\n"
#define IIN "%d%d\\n"
#define IIIN "%d%d%d\\n"
#define IIIIN "%d%d%d%d\\n"
#endif

#ifdef __LOCALE__
#define see(a) std::cout << #a << "=" << a << std::endl
#define ses(a) std::cout << #a << "=" << a << " "
#else
#define see(a) // std::cout << #a << "=" << a << std::endl
#define ses(a)
#endif
#define repe(a, b) for (int a = 0; a < (int)b.size(); a++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define repa(i, n) for (int i = 1; i <= n; i++)
#define repi(i, a, b) for (int i = a; i <= b; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
typedef pair<int, int> pr;
typedef pair<pr, int> prr;
#define L first
#define R second
template <class T> inline bool checkMin(T &a, T b) {
  return (a > b ? a = b, 1 : 0);
}
template <class T> inline bool checkMax(T &a, T b) {
  return (a < b ? a = b, 1 : 0);
}
class Scanner {
private:
  istream &ist;

public:
  Scanner(istream &in) : ist(in) {}
  string next() {
    string r;
    ist >> r;
    return r;
  }
  string nextLine() {
    string r;
    getline(ist, r);
    return r;
  }
  int nextInt() {
    int r;
    ist >> r;
    return r;
  }
  double nextDouble() {
    double r;
    ist >> r;
    return r;
  }
};
Scanner sc(cin);

const int MOD = 1000000007;
const int N = 200005;
int n;

void init() { scanf(I, &n); }

int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }

int power(int exp) {
  int res = 1;
  while (exp--)
    (res *= 2) %= MOD;
  return res;
}

int calc(int u, int v) { return (power(u) + power(v) - 1) % MOD; }

void solve() {
  int preans = 0;
  map<pr, pr> st;
  rep(i, n) {
    int a, b;
    scanf(II, &a, &b);
    if (b < 0) {
      a = -a;
      b = -b;
    }
    if (a == 0 && b == 0)
      preans++;
    else {
      auto g = abs(gcd(abs(a), abs(b)));
      a /= g;
      b /= g;
      if (a <= 0)
        ++st[pr(b, -a)].R;
      else
        ++st[pr(a, b)].L;
    }
  }
  int res = 1;
  for (auto p : st) {
    auto t = p.R;
    (res *= calc(t.L, t.R)) %= MOD;
  }
  printf(IN, (res + preans - 1 + MOD) % MOD);
}

#ifdef ENABLE_LL
#undef int
#endif
int main() {
  init();
  solve();
  return 0;
}


Error: 0

Fixed submission:

#define ENABLE_LL
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;

#ifdef ENABLE_LL
#define int long long
#endif

#ifdef ENABLE_LL
#define I "%lld"
#define II "%lld%lld"
#define III "%lld%lld%lld"
#define IIII "%lld%lld%lld%lld"
#define IN "%lld\\n"
#define IIN "%lld%lld\\n"
#define IIIN "%lld%lld%lld\\n"
#define IIIIN "%lld%lld%lld%lld\\n"
#else
#define I "%d"
#define II "%d%d"
#define III "%d%d%d"
#define IIII "%d%d%d%d"
#define IN "%d\\n"
#define IIN "%d%d\\n"
#define IIIN "%d%d%d\\n"
#define IIIIN "%d%d%d%d\\n"
#endif

#ifdef __LOCALE__
#define see(a) std::cout << #a << "=" << a << std::endl
#define ses(a) std::cout << #a << "=" << a << " "
#else
#define see(a) // std::cout << #a << "=" << a << std::endl
#define ses(a)
#endif
#define repe(a, b) for (int a = 0; a < (int)b.size(); a++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define repa(i, n) for (int i = 1; i <= n; i++)
#define repi(i, a, b) for (int i = a; i <= b; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
typedef pair<int, int> pr;
typedef pair<pr, int> prr;
#define L first
#define R second
template <class T> inline bool checkMin(T &a, T b) {
  return (a > b ? a = b, 1 : 0);
}
template <class T> inline bool checkMax(T &a, T b) {
  return (a < b ? a = b, 1 : 0);
}
class Scanner {
private:
  istream &ist;

public:
  Scanner(istream &in) : ist(in) {}
  string next() {
    string r;
    ist >> r;
    return r;
  }
  string nextLine() {
    string r;
    getline(ist, r);
    return r;
  }
  int nextInt() {
    int r;
    ist >> r;
    return r;
  }
  double nextDouble() {
    double r;
    ist >> r;
    return r;
  }
};
Scanner sc(cin);

const int MOD = 1000000007;
const int N = 200005;
int n;
pr x[N];

void init() {
  scanf(I, &n);
  rep(i, n) {
    int a, b;
    scanf(II, &a, &b);
    if (a < 0) {
      a = -a;
      b = -b;
    }
    x[i] = pr(a, b);
  }
}

int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }

int power(int exp) {
  int res = 1;
  while (exp--)
    (res *= 2) %= MOD;
  return res;
}

int calc(int u, int v) { return (power(u) + power(v) - 1) % MOD; }

void solve() {
  int preans = 0;
  multiset<pr> st0, st1;
  rep(i, n) {
    int g = gcd(abs(x[i].L), abs(x[i].R));
    x[i] = pr(x[i].L / g, x[i].R / g);
    if (x[i].L == x[i].R && x[i].R == 0) {
      preans++;
      continue;
    }
    if (x[i].L == 0 || x[i].R == 0) {
      if (x[i].L == 0)
        st0.insert(pr(0, 1));
      else
        st1.insert(pr(0, 1));
      continue;
    }
    if (x[i].R > 0) {
      st0.insert(x[i]);
    } else if (x[i].R < 0) {
      st1.insert(pr(-x[i].R, x[i].L));
    }
  }
  int res = 1;
  while (!st0.empty()) {
    pr it = *st0.begin();
    ses(it.L);
    see(it.R);
    (res *= calc((int)st0.count(it), (int)st1.count(it))) %= MOD;
    st0.erase(it);
    st1.erase(it);
  }
  while (!st1.empty()) {
    pr it = *st1.begin();
    ses(it.L);
    see(it.R);
    (res *= calc((int)st0.count(it), (int)st1.count(it))) %= MOD;
    st0.erase(it);
    st1.erase(it);
  }
  printf(IN, (res + preans - 1 + MOD) % MOD);
}

#ifdef ENABLE_LL
#undef int
#endif
int main() {
  init();
  solve();
  return 0;
}