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

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(...) ;
#else
#define debug(...)                                                             \\
  cerr << __LINE__ << " : " << #__VA_ARGS__ << " = " << _tostr(__VA_ARGS__)    \\
       << endl;

template <typename T> ostream &operator<<(ostream &out, const vector<T> &v);

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T> ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v)
    out << item << ", ";
  out << "\\b\\b}";
  return out;
}

void _tostr_rec(ostringstream &oss) { oss << "\\b\\b \\b"; }

template <typename Head, typename... Tail>
void _tostr_rec(ostringstream &oss, Head &&head, Tail &&...tail) {
  oss << head << ", ";
  _tostr_rec(oss, forward<Tail>(tail)...);
}

template <typename... T> string _tostr(T &&...args) {
  ostringstream oss;
  int size = sizeof...(args);
  if (size > 1)
    oss << "{";
  _tostr_rec(oss, forward<T>(args)...);
  if (size > 1)
    oss << "}";
  return oss.str();
}
#endif

#define mod 1000000007              // 1e9+7(prime number)
#define INF 1000000000              // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 200010

// GCC __gcd(long long A, long long B)

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

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll power(ll k, ll n, int M) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * k % M;
    k = k * k % M;
    n /= 2;
  }
  return res;
}

int main() {
  int N;
  int counter0 = 0;
  map<pair<ll, ll>, int> counter;
  map<pair<ll, ll>, bool> used;

  scanf("%d", &N);

  for (int i = 0; i < N; i++) {
    ll A, B;
    scanf("%lld%lld", &A, &B);

    if (A == 0 && B == 0) {
      counter0++;
      continue;
    }

    ll g = gcd(A, B);
    A /= g;
    B /= g;

    counter[{A, B}]++;
  }

  ll ans = 1;

  for (auto p : counter) {
    ll A = p.first.first;
    ll B = p.first.second;

    if (used[{A, B}])
      continue;

    ll x = counter[{A, B}] + counter[{-A, -B}];
    ll y = counter[{B, -A}] + counter[{-B, A}];

    used[{A, B}] = true;
    used[{-A, -B}] = true;
    used[{B, -A}] = true;
    used[{-B, A}] = true;

    ll z = (power(2, x, mod) + power(2, y, mod) - 1) % mod;
    ans = z * ans % mod;

    debug(x, y, z);
  }

  printf("%lld\\n", (ans + mod - 1 + counter0) % mod);

  return 0;
}

Error: 0

Fixed submission:

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(...) ;
#else
#define debug(...)                                                             \\
  cerr << __LINE__ << " : " << #__VA_ARGS__ << " = " << _tostr(__VA_ARGS__)    \\
       << endl;

template <typename T> ostream &operator<<(ostream &out, const vector<T> &v);

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T> ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v)
    out << item << ", ";
  out << "\\b\\b}";
  return out;
}

void _tostr_rec(ostringstream &oss) { oss << "\\b\\b \\b"; }

template <typename Head, typename... Tail>
void _tostr_rec(ostringstream &oss, Head &&head, Tail &&...tail) {
  oss << head << ", ";
  _tostr_rec(oss, forward<Tail>(tail)...);
}

template <typename... T> string _tostr(T &&...args) {
  ostringstream oss;
  int size = sizeof...(args);
  if (size > 1)
    oss << "{";
  _tostr_rec(oss, forward<T>(args)...);
  if (size > 1)
    oss << "}";
  return oss.str();
}
#endif

#define mod 1000000007              // 1e9+7(prime number)
#define INF 1000000000              // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 200010

// GCC __gcd(long long A, long long B)

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

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll power(ll k, ll n, int M) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * k % M;
    k = k * k % M;
    n /= 2;
  }
  return res;
}

int main() {
  int N;
  map<pair<ll, ll>, int> counter;
  map<pair<ll, ll>, bool> used;

  scanf("%d", &N);

  for (int i = 0; i < N; i++) {
    ll A, B;
    scanf("%lld%lld", &A, &B);

    ll g = gcd(A, B);
    A /= g;
    B /= g;

    counter[{A, B}]++;
  }

  ll ans = 1;

  for (auto p : counter) {
    ll A = p.first.first;
    ll B = p.first.second;

    if (used[{A, B}])
      continue;

    ll x = counter[{A, B}] + counter[{-A, -B}];
    ll y = counter[{B, -A}] + counter[{-B, A}];

    used[{A, B}] = true;
    used[{-A, -B}] = true;
    used[{B, -A}] = true;
    used[{-B, A}] = true;

    ll z = (power(2, x, mod) + power(2, y, mod) - 1) % mod;
    ans = z * ans % mod;

    debug(x, y, z);
  }

  printf("%lld\\n", ans - 1);

  return 0;
}