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

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end)                                                     \\
  for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end)                                                    \\
  for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
const lint mod = 1000000007;

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

lint pow_two(lint n) {
  lint tmp = 1;
  REP(i, n) tmp = (tmp * 2) % mod;
  return tmp;
}

int main() {
  lint n;
  cin >> n;
  vector<lint> a(n), b(n);
  map<plint, lint> m;
  lint zerozero = 0;
  REP(i, n) {
    cin >> a[i] >> b[i];
    if (a[i] == 0 && b[i] == 0) {
      zerozero++;
      continue;
    }
    if (a[i] == 0) {
      b[i] = -1;
    } else if (b[i] == 0) {
      a[i] = 1;
    } else {
      lint x = gcd(abs(a[i]), abs(b[i]));
      a[i] /= x;
      b[i] /= x;
      if (a[i] < 0 && b[i] < 0) {
        a[i] = -a[i];
        b[i] = -b[i];
      }
      if (a[i] < 0 && b[i] > 0) {
        a[i] = -a[i];
        b[i] = -b[i];
      }
    }
    plint p = make_pair(a[i], b[i]);
    if (!m.count(p)) {
      m[p] = 1;
    } else {
      m[p] = m[p] + 1;
    }
  }
  lint ans = 1;
  for (auto pp : m) {
    plint p = pp.first;
    plint p1 = make_pair(p.second, -p.first);
    plint p2 = make_pair(-p.second, p.first);
    lint z = 0;
    if (m.count(p1)) {
      z = z + m.at(p1);
      m[p1] = 0;
    }
    if (m.count(p2)) {
      z = z + m.at(p2);
      m[p2] = 0;
    }
    lint now = pow_two(z) + pow_two(pp.second) - 1;
    ans = ((ans * now) % mod) + mod;
    // ans *= tmp;
    plint p3 = make_pair(-p.first, -p.second);
    if (m.count(p3)) {
      m[p3] = 0;
    }
    m[p] = 0;
  }
  cout << (((ans + mod + zerozero) - 1) % mod) << "\\n";
  // cout << ans-1 << "\\n";

  return 0;
}

Error: 0

Fixed submission:

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end)                                                     \\
  for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end)                                                    \\
  for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

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

int main() {
  lint mod = 1000000007;
  lint n;
  cin >> n;
  vector<int> a(n), b(n);
  map<pint, int> m;
  REP(i, n) {
    cin >> a[i] >> b[i];
    int x = gcd(abs(a[i]), abs(b[i]));
    a[i] /= x;
    b[i] /= x;
    pint p = make_pair(a[i], b[i]);
    if (!m.count(p)) {
      m[p] = 1;
    } else {
      m[p] = m[p] + 1;
    }
  }
  lint ans = 1;
  for (auto pp : m) {
    pint p = pp.first;
    pint p1 = make_pair(p.second, -p.first);
    pint p2 = make_pair(-p.second, p.first);
    lint z = 0;
    if (m.count(p1)) {
      z = z + m.at(p1);
      m[p1] = 0;
    }
    if (m.count(p2)) {
      z = z + m.at(p2);
      m[p2] = 0;
    }
    lint tmp = pow(2, z) + pow(2, pp.second) - 1;
    ans = (ans * tmp) % mod;
    m[p] = 0;
  }
  cout << (((ans + mod) - 1) % mod) << "\\n";

  return 0;
}