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

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

const ll MAX_N = 212345;
ll MOD = ll(1000000000 + 7);
ll fac2[MAX_N];

void init() {
  fac2[0] = 1ll;
  for (int i = 1; i < MAX_N; i++) {
    fac2[i] = (fac2[i - 1] * 2ll) % MOD;
  }
}

int main(void) {
  init();
  ll N;
  cin >> N;
  map<pair<ll, ll>, pair<int, int>> umap;
  // pair<int, int> zpair = {0, 0};
  ll zero = MOD - 1;
  for (int i = 0; i < N; i++) {
    ll a, b;
    cin >> a >> b;
    if (a == 0 && b == 0) {
      zero++;
      continue;
    }
    // if(a==0){
    //     zpair.first++;
    //     continue;
    // }
    // if (b==0){
    //     zpair.second++;
    //     continue;
    // }
    if (make_pair(a, b) < make_pair(0ll, 0ll)) {
      a = -a;
      b = -b;
    }
    ll d = gcd(abs(a), abs(b));
    a /= d;
    b /= d;
    if (b > 0) {
      umap[{a, b}].first += 1;
    } else {
      umap[{-b, a}].second += 1;
    }
  }
  // ll answer = (fac2[zpair.first] + fac2[zpair.second] - 1ll) % MOD;
  ll answer = 1ll;
  for (auto &item : umap) {
    answer *= (fac2[item.second.first] + fac2[item.second.second] - 1ll) % MOD;
    answer %= MOD;
  }
  cout << (answer + zero) % MOD << endl;

  return 0;
}

Error: 0

Fixed submission:

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

const ll MAX_N = 222222;
ll MOD = ll(1000000000 + 7);
ll fac2[MAX_N];
ll gcd(ll a, ll b) {
  if (a < b) {
    swap(a, b);
  }
  ll r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

void init() {
  fac2[0] = 1ll;
  for (int i = 1; i < MAX_N; i++) {
    fac2[i] = fac2[i - 1] * 2ll % MOD;
  }
}

int main(void) {
  init();
  ll N;
  cin >> N;
  unordered_map<ll, int> umap;
  for (int i = 0; i < N; i++) {
    ll a, b;
    cin >> a >> b;
    if (a == 0 && b == 0) {
      ll p = 0;
      if (umap.count(p) == 0) {
        umap[p] = 1;
      } else {
        umap[p] += 1;
      }
      continue;
    }
    if (a == 0) {
      b = 1;
    }
    if (b == 0) {
      a = 1;
    }
    if (a == 0 || b == 0) {
      ll p = a * MAX_N + b;
      if (umap.count(p) == 0) {
        umap[p] = 1;
      } else {
        umap[p] += 1;
      }
      continue;
    }
    ll d = gcd(abs(a), abs(b));
    a /= d;
    b /= d;
    if (a < 0) {
      a *= -1;
      b *= -1;
    }
    ll p = a * MAX_N + b;
    if (b < 0) {
      p = 1 * MAX_N * MAX_N + a * MAX_N + b * -1;
    }
    if (umap.count(p) == 0) {
      umap[p] = 1;
    } else {
      umap[p] += 1;
    }
  }
  ll answer = 1;
  ll zero = 0;
  set<ll> searached;
  for (auto item : umap) {
    int n = item.second;
    ll f = item.first;
    int t = f / (MAX_N * MAX_N);
    ll a = (f % (MAX_N * MAX_N)) / MAX_N;
    ll b = f % MAX_N;
    if (t)
      b *= -1;
    if (searached.count(item.first) != 0)
      continue;
    searached.insert(item.first);
    ll a2 = 1;
    if (a == 0 && b == 0) {
      zero = n;
      return -1;
      // continue;
    } else if (a == 0) {
      ll p = 1 * MAX_N;
      if (umap.count(p) != 0) {
        a2 = fac2[umap[p]];
      }
      searached.insert(p);
    } else if (b == 0) {
      ll p = 1;
      if (umap.count(p) != 0) {
        a2 = fac2[umap[p]];
      }
      searached.insert(p);
    } else {
      ll p = abs(b) * MAX_N + a;
      if (t == 0)
        p += 1 * MAX_N * MAX_N;
      if (umap.count(p) != 0) {
        a2 = fac2[umap[p]];
      }
      searached.insert(p);
    }
    answer *= (fac2[n] + a2 - 1);
    answer %= MOD;
  }
  cout << answer - 1 + zero << endl;

  return 0;
}