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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> vi;
#define endl '\\n'
#define fo(i, a, b) for (int i = a; i <= b; i++)
#define rf(i, a, b) for (int i = a; i >= b; i--)
#define fast_io ios_base::sync_with_stdio(0);
#define show(x) cout << x << endl;
#define pret(x)                                                                \\
  cout << x << endl;                                                           \\
  return 0;
#define disp(x) cout << x << " ";
#define let(x, y) cout << x << " " << y << endl;
ll MOD = 1e9 + 7;
const int maxn = 2e5 + 5;

int sign(int x) {
  if (x == 0)
    return 0;
  return x / abs(x);
}

pair<int, int> f(int x, int y) {
  if (x == 0 or y == 0)
    return {y, x};
  if (x < 0) {
    return {y, -x};
  } else
    return {-y, x};
}

int p[maxn];

int32_t main() {
  fast_io;
  int n;
  p[0] = 1;
  fo(i, 1, maxn - 1) { p[i] = (p[i - 1] * 2ll) % MOD; }
  cin >> n;
  vector<pair<int, int>> v;
  map<pair<int, int>, int> m;
  map<pair<int, int>, int> visited;
  int temp = 0;
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    if (x == 0 and y == 0) {
      temp++;
      continue;
    }
    int g = __gcd(abs(x), abs(y));
    x /= g;
    y /= g;
    if (sign(x) == 0 or sign(y) == 0) {
      x = abs(x);
      y = abs(y);
    } else if (sign(x) != sign(y)) {
      x = -abs(x);
      y = abs(y);
    } else {
      x = abs(x);
      y = abs(y);
    }
    m[{x, y}]++;
  }
  for (auto it : m) {
    if (visited[it.first])
      continue;
    int x = it.first.first;
    int y = it.first.second;
    visited[it.first] = 1;
    auto inverse = f(x, y);
    // cout<<x<<" "<<y<<" "<<inverse.first<<" "<<inverse.second<<endl;
    // cout<<m[it.first]<<" "<<m[inverse]<<endl;
    visited[inverse] = 1;
    v.emplace_back(m[it.first], m[inverse]);
  }
  int ans = 1;
  for (const auto &it : v) {
    ans = (ans * (p[it.first] + p[it.second] - 1ll)) % MOD;
  }
  ans--;
  if (temp)
    ans += temp;
  ans = (ans + MOD) % MOD;
  show(ans);
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> vi;
#define endl '\\n'
#define fo(i, a, b) for (int i = a; i <= b; i++)
#define rf(i, a, b) for (int i = a; i >= b; i--)
#define fast_io ios_base::sync_with_stdio(0);
#define show(x) cout << x << endl;
#define pret(x)                                                                \\
  cout << x << endl;                                                           \\
  return 0;
#define disp(x) cout << x << " ";
#define let(x, y) cout << x << " " << y << endl;
ll MOD = 1e9 + 7;
const int maxn = 2e5 + 5;

int sign(int x) {
  if (x == 0)
    return 0;
  return x / abs(x);
}

pair<int, int> f(int x, int y) {
  if (x == 0 or y == 0)
    return {y, x};
  if (x < 0) {
    return {y, -x};
  } else
    return {-y, x};
}

int p[maxn];

int32_t main() {
  fast_io;
  int n;
  p[0] = 1;
  fo(i, 1, maxn - 1) { p[i] = (p[i - 1] * 2ll) % MOD; }
  cin >> n;
  vector<pair<int, int>> v;
  map<pair<int, int>, int> m;
  map<pair<int, int>, int> visited;
  int temp = 0;
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    if (x == 0 and y == 0)
      temp++;
    int g = __gcd(abs(x), abs(y));
    x /= g;
    y /= g;
    if (sign(x) == 0 or sign(y) == 0) {
      x = abs(x);
      y = abs(y);
    }
    if (sign(x) != sign(y)) {
      x = -abs(x);
      y = abs(y);
    } else {
      x = abs(x);
      y = abs(y);
    }
    m[{x, y}]++;
  }
  for (auto it : m) {
    if (visited[it.first])
      continue;
    int x = it.first.first;
    int y = it.first.second;
    visited[it.first] = 1;
    auto inverse = f(x, y);
    // cout<<x<<" "<<y<<" "<<inverse.first<<" "<<inverse.second<<endl;
    // cout<<m[it.first]<<" "<<m[inverse]<<endl;
    visited[inverse] = 1;
    v.emplace_back(m[it.first], m[inverse]);
  }
  int ans = max(1ll, temp);
  for (const auto &it : v) {
    ans = (ans * (p[it.first] + p[it.second] - 1ll)) % MOD;
  }
  ans--;
  ans = (ans + MOD) % MOD;
  show(ans);
  return 0;
}