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

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#define IOS                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0)

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

const int MAXN = 234567;
const LL MOD = (LL)1e9 + 7;
LL pw2[MAXN];

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

LL mul(LL a, LL b) { return (a * b) % MOD; }

int main() {
  pw2[0] = 1;
  for (int i = 1; i < MAXN; i++)
    pw2[i] = (pw2[i - 1] * 2) % MOD;
  int N;
  scanf("%d", &N);
  map<pll, LL> mp;
  LL a0b0 = 0, a0 = 0, b0 = 0;
  for (int i = 0; i < N; i++) {
    LL a, b;
    scanf("%lld %lld", &a, &b);
    if (a == 0 && b == 0)
      a0b0++;
    else if (a == 0)
      a0++;
    else if (b == 0)
      b0++;
    else {
      LL coef = 1;
      if ((a < 0 && b > 0) || (a > 0 && b < 0))
        coef = -1;
      a = abs(a), b = abs(b);
      assert(a > 0);
      assert(b > 0);
      LL g = gcd(a, b);
      a /= g, b /= g;
      pll tmp = make_pair(coef * a, b);
      mp[tmp]++;
    }
  }
  LL ans = 1;
  set<pll> used;
  for (auto it : mp) {
    pll p = it.first;
    LL a = p.first, b = p.second;
    LL x = it.second;
    if (used.count(p))
      continue;
    pll rv = make_pair(-b, a);
    if (a < 0) {
      rv.first *= -1;
      rv.second *= -1;
    }
    assert(rv.second > 0);
    if (mp.count(rv)) {
      LL y = mp[rv];
      LL tmp = (pw2[x] + pw2[y] - 1) % MOD;
      used.insert(rv);
      ans = (ans * tmp) % MOD;
    } else {
      ans = (ans * pw2[x]) % MOD;
    }
  }
  ans = mul(ans, (pw2[a0] + pw2[b0] - 1) % MOD) % MOD;
  printf("%lld\\n", (ans + a0b0 - 1 + MOD) % MOD);
  return 0;
}
/* stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
by Benq;
*/


Error: 0

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#define IOS                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0)

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

const int MAXN = 234567;
const LL MOD = (LL)1e9 + 7;
LL pw2[MAXN];

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

int main() {
  pw2[0] = 1;
  for (int i = 1; i < MAXN; i++)
    pw2[i] = (pw2[i - 1] * 2) % MOD;
  int N;
  scanf("%d", &N);
  map<pll, int> mp;
  for (int i = 0; i < N; i++) {
    LL a, b;
    scanf("%lld %lld", &a, &b);
    int coef = 1;
    if (a * b < 0)
      coef = -1;
    a = abs(a), b = abs(b);
    LL g = gcd(a, b);
    a /= g, b /= g;
    mp[make_pair(coef * a, b)]++;
  }
  LL ans = 1;
  for (auto it = mp.begin(); it != mp.end(); it++) {
    if (it->second == 0)
      continue;
    LL a = it->first.first, b = it->first.second;
    int coef = -1;
    if (a < 0) {
      coef = 1;
      a *= -1;
    }
    auto rv = make_pair(coef * b, a);
    if (!mp.count(rv)) {
      ans = (ans * pw2[it->second]) % MOD;
      continue;
    }
    LL tmp = (pw2[it->second] + pw2[mp[rv]] - 1) % MOD;
    if (tmp < 0)
      assert(false);
    ans = (ans * tmp) % MOD;
    if (ans < 0)
      assert(false);
    mp[rv] = 0;
  }
  printf("%lld\\n", (ans - 1 + MOD) % MOD);
  return 0;
}
/* stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
by Benq;
*/