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

#include <bits/stdc++.h>
using namespace std;
typedef int int__;
#define int long long
#define pb push_back
#define pi pair<int, int>
#define vpi vector<pi>
#define vi vector<int>
#define vvi vector<vi>
#define fi first
#define se second
#define forn(i, n) for (int i = 0; i < int__(n); i++)
#define sz(a) int__(a.size())
template <class A, class B>
ostream &operator<<(ostream &out, const pair<A, B> &a) {
  return out << "(" << a.first << ", " << a.second << ")";
}
template <class A> ostream &operator<<(ostream &out, const vector<A> &v) {
  out << "[";
  forn(i, sz(v)) {
    if (i)
      out << ", ";
    out << v[i];
  }
  return out << "]";
}
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
int Mod(int x) {
  const int mm = 1000000007;
  x %= mm;
  if (x < 0)
    x += mm;
  return x;
}
int Pow(int x, int n) {
  if (n == 0)
    return 1;
  int t = Pow(x, n / 2);
  t = Mod(t * t);
  if (n & 1)
    t = Mod(t * x);
  return t;
}
#define watch(x) cout << #x << " : " << x << endl;
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
#define all(x) x.begin(), x.end()

pi comp(pi x) {
  int a = x.fi, b = x.se;
  int s = (a / abs(a)) * (b / abs(b));
  int g = gcd(abs(a), abs(b));
  a = abs(a);
  b = abs(b);
  a /= g, b /= g;
  pi t;
  t.fi = -s * b;
  t.se = a;
  return t;
}

int__ main() {
  fast;

  int n;
  cin >> n;
  int mod = 1000000007;
  map<pi, int> mp;

  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    if (a == 0 and b == 0) {
      mp[{0, 0}]++;
      continue;
    }

    if (a == 0) {
      mp[{0, 1}]++;
      continue;
    }
    if (b == 0) {
      mp[{1, 0}]++;
      continue;
    }

    int s = (a / abs(a)) * (b / abs(b));
    int g = gcd(abs(a), abs(b));
    a = abs(a);
    b = abs(b);
    a /= g, b /= g;
    mp[{s * a, b}]++;
  }

  int ans = 1;
  map<pi, int> vis;
  for (auto y : mp) {
    pi x = y.fi;
    if (x.fi == 0 or x.se == 0)
      continue;
    if (vis[x] or vis[comp(x)])
      continue;
    pi cmp = comp(x);
    vis[x]++;
    vis[cmp]++;

    int t = Pow(2, mp[x]);
    t += Pow(2, mp[cmp]);

    t %= mod;

    t = Mod(t - 1);

    ans = Mod(ans * t);
  }

  // 1,0 cases
  int t = Pow(2, mp[{1, 0}]);
  t += Pow(2, mp[{0, 1}]);

  t %= mod;

  t = Mod(t - 1);

  ans = Mod(ans * t);

  cout << Mod((ans - 1) + mp[{0, 0}]) << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef int int__;
#define int long long
#define pb push_back
#define pi pair<int, int>
#define vpi vector<pi>
#define vi vector<int>
#define vvi vector<vi>
#define fi first
#define se second
#define forn(i, n) for (int i = 0; i < int__(n); i++)
#define sz(a) int__(a.size())
template <class A, class B>
ostream &operator<<(ostream &out, const pair<A, B> &a) {
  return out << "(" << a.first << ", " << a.second << ")";
}
template <class A> ostream &operator<<(ostream &out, const vector<A> &v) {
  out << "[";
  forn(i, sz(v)) {
    if (i)
      out << ", ";
    out << v[i];
  }
  return out << "]";
}
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
int Mod(int x) {
  const int mm = 1000000007;
  x %= mm;
  if (x < 0)
    x += mm;
  return x;
}
int Pow(int x, int n) {
  if (n == 0)
    return 1;
  int t = Pow(x, n / 2);
  t = Mod(t * t);
  if (n & 1)
    t = Mod(t * x);
  return t;
}
#define watch(x) cout << #x << " : " << x << endl;
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
#define all(x) x.begin(), x.end()

pi comp(pi x) {
  int a = x.fi, b = x.se;
  int s = (a / abs(a)) * (b / abs(b));
  int g = gcd(abs(a), abs(b));
  a = abs(a);
  b = abs(b);
  a /= g, b /= g;
  pi t;
  t.fi = -s * b;
  t.se = a;
  return t;
}

int__ main() {
  fast;

  int n;
  cin >> n;
  int mod = 1000000007;
  map<pi, int> mp;

  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    if (a == 0 and b == 0) {
      mp[{0, 0}]++;
      continue;
    }

    if (a == 0) {
      mp[{0, 1}]++;
      continue;
    }
    if (b == 0) {
      mp[{1, 0}]++;
    }

    int s = (a / abs(a)) * (b / abs(b));
    int g = gcd(abs(a), abs(b));
    a = abs(a);
    b = abs(b);
    a /= g, b /= g;
    mp[{s * a, b}]++;
  }

  int ans = 1;
  map<pi, int> vis;
  for (auto y : mp) {
    pi x = y.fi;
    if (vis[x] or vis[comp(x)])
      continue;
    pi cmp = comp(x);
    vis[x]++;
    vis[cmp]++;

    int t = Pow(2, mp[x]);
    t += Pow(2, mp[cmp]);

    t %= mod;

    t = Mod(t - 1);

    ans = Mod(ans * t);
  }

  cout << (ans - 1) + mp[{0, 0}] << endl;
}