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

#include <bits/stdc++.h>
#define _                                                                      \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl '\\n'
#define INF 0x3f3f3f3f
#define MAX (1 << 20)
#define MOD 1000000007
#define i64 long long
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define ii pair<i64, i64>
#define fs first
#define sc second
#define eb emplace_back
#define vi vector<i64>
#define vvi vector<vi>
#define vii vector<ii>
#define vvii vector<vii>
#define lsb(x) ((x) & (-x))
#define gcd(x, y) __gcd((x), (y))

using namespace std;

map<ii, i64> f;
vii dir;
vi pot2;
i64 n, xz, yz, zz, a, b, ans, fator;

int main() {
  _ cin >> n;

  pot2.eb(1);
  for (int i = n; i--;) {
    pot2.eb((2 * pot2.back()) % MOD);
  }

  dir = vii(n);
  for (auto &[x, y] : dir) {
    cin >> x >> y;

    if (!x) {
      if (!y) {
        ++zz;
        continue;
      } else {
        ++xz;
      }
    } else if (!y) {
      ++yz;
    }

    if (x < 0) {
      x = -x;
      y = -y;
    }

    i64 mdc = abs(gcd(x, y));
    x /= mdc;
    y /= mdc;

    ++f[{x, y}];
  }

  ans = 1LL;

  fator = (pot2[xz] + pot2[yz] - 1LL + MOD) % MOD;
  ans = (ans * fator) % MOD;

  for (auto [p, c] : f) {
    i64 x = p.fs, y = p.sc;

    // cout << x << " " << y << " >> " << c << endl;

    if (!x || !y || !c)
      continue;

    a = (y > 0 ? y : -y);
    b = (y > 0 ? -x : x);

    fator = (pot2[c] + pot2[f[{a, b}]] - 1LL + MOD) % MOD;
    ans = (ans * fator) % MOD;

    f[{a, b}] *= !(f[{a, b}]);
  }

  cout << (ans - 1LL + zz + MOD) % MOD << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define _                                                                      \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define endl '\\n'
#define INF 0x3f3f3f3f
#define MAX (1 << 20)
#define MOD 1000000007
#define i64 long long
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define ii pair<i64, i64>
#define fs first
#define sc second
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vi>
#define vii vector<ii>
#define vvii vector<vii>
#define lsb(x) ((x) & (-x))
#define gcd(x, y) __gcd((x), (y))

using namespace std;

map<ii, int> dir, liv;
i64 a, b;

i64 mdc(i64 a, i64 b) { return b ? mdc(b, a % b) : a; }

i64 fastpow(i64 b, i64 e) {
  i64 ans = 1LL;
  for (; e; b = (b * b) % MOD, e >>= 1)
    if (e & 1LL)
      ans = (ans * b) % MOD;
  return ans;
}

i64 ans, m, n, z, fator;

int main() {
  _ cin >> n;
  for (int i = n; i--;) {
    cin >> a >> b;
    if (a < 0) {
      a = -a;
      b = -b;
    }
    if (!(a || b)) {
      ++z;
      continue;
    }
    a *= (b != 0);
    b *= (a != 0);
    m = mdc(abs(a), abs(b));
    a /= m;
    b /= m;
    dir[ii(a, b)]++;
  }
  for (auto p : dir) {
    int u = p.fs.fs, v = p.fs.sc;
    if (dir.find(ii(v, -u)) == dir.end() && dir.find(ii(-v, u)) == dir.end()) {
      ++ans;
    } else {
      liv[ii(u, v)] = dir[ii(u, v)];
    }
  }
  dir.clear();
  ans = fastpow(2, ans);
  for (auto p : liv) {
    int u = p.fs.fs, v = p.fs.sc;

    if (!p.sc)
      continue;

    fator = (fastpow(2, p.sc) - 1 + MOD) % MOD;

    if (v > 0) {
      fator = (fator + fastpow(2, liv[ii(v, -u)]) + MOD) % MOD;
      liv[ii(v, -u)] = 0;
    } else {
      fator = (fator + fastpow(2, liv[ii(-v, u)]) + MOD) % MOD;
      liv[ii(-v, u)] = 0;
    }

    ans = (ans * fator) % MOD;
  }
  cout << (ans - 1 + z + MOD) % MOD << endl;
  return 0;
}