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

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

map<pair<int, int>, int> mm;
const int mod = 1000000007;
int power[400005];
map<pair<int, int>, int> tt;

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);

#ifndef ONLINE_JUDGE
  if (fopen("INPUT.txt", "r")) {
    freopen("INPUT.txt", "r", stdin);
    freopen("OUTPUT.txt", "w", stdout);
  }
#endif

  power[0] = 1;
  for (int i = 1; i <= 400000; i++)
    power[i] = (power[i - 1] * 2) % mod;
  int n;
  cin >> n;
  int x, y;
  int res1 = 0, res2 = 0, res3 = 0;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    if (x == 0)
      res1++;
    if (y == 0)
      res2++;
    if (x == 0 && y == 0)
      res3++;
    if (x != 0 || y != 0) {
      int g = __gcd(x, y);
      x /= g;
      y /= g;
    }
    if (y < 0) {
      y *= -1;
      x *= -1;
    }
    mm[{x, y}]++;
    tt[{x, y}]++;
  }
  int ans = 1;
  for (auto i : tt) {
    if (i.first.first == 0 || i.first.second == 0)
      continue;
    int z = 1;
    if (i.first.first >= 0)
      z = -1;
    if (mm[{z * i.first.second, abs(i.first.first)}] == 0) {
      ans *= power[i.second];
      ans %= mod;
    } else {
      if (i.first.first > 0)
        continue;
      int tot = 0;
      x = 0;
      y = 0;
      x += i.second;
      y += mm[{i.first.second, abs(i.first.first)}];
      if (i.first.first < 0) {
        tot = power[x + y];
        tot += mod - ((power[x] + mod - 1) * (power[y] + mod - 1)) % mod;
        tot %= mod;
        ans *= tot;
        ans %= mod;
      }
    }
  }
  int temp = ans + mod - 1;
  res1 -= res3;
  res2 -= res3;
  int tot = 0;
  tot += power[res1] - 1 + mod;
  tot += power[res2] - 1 + mod;
  tot += res3 + 1;
  tot %= mod;
  ans *= tot;
  ans %= mod;
  ans += mod - 1;
  ans %= mod;
  ans += mod - (temp * (res3)) % mod;
  ans %= mod;
  cout << ans;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

map<pair<int, int>, int> mm;
const int mod = 1000000007;
int power[200005];
map<pair<int, int>, int> tt;

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);

#ifndef ONLINE_JUDGE
  if (fopen("INPUT.txt", "r")) {
    freopen("INPUT.txt", "r", stdin);
    freopen("OUTPUT.txt", "w", stdout);
  }
#endif

  power[0] = 1;
  for (int i = 1; i <= 200000; i++)
    power[i] = (power[i - 1] * 2) % mod;
  int n;
  cin >> n;
  int x, y;
  int res1 = 0, res2 = 0, res3 = 0;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    if (x == 0)
      res1++;
    if (y == 0)
      res2++;
    if (x == 0 && y == 0)
      res3++;
    int g = __gcd(x, y);
    x /= g;
    y /= g;
    if (y < 0) {
      y *= -1;
      x *= -1;
    }
    mm[{x, y}]++;
    tt[{x, y}]++;
  }
  int ans = 1;
  for (auto i : tt) {
    if (i.first.first == 0 || i.first.second == 0)
      continue;
    int z = 1;
    if (i.first.first >= 0)
      z = -1;
    if (mm[{z * i.first.second, abs(i.first.first)}] == 0) {
      ans *= power[i.second];
      ans %= mod;
    } else {
      if (i.first.first > 0)
        continue;
      int tot = 0;
      x = 0;
      y = 0;
      x += i.second;
      y += mm[{i.first.second, abs(i.first.first)}];
      if (i.first.first < 0) {
        tot = power[x + y];
        tot += mod - ((power[x] + mod - 1) * (power[y] + mod - 1)) % mod;
        tot %= mod;
        ans *= tot;
        ans %= mod;
      }
    }
  }
  res1 -= res3;
  res2 -= res3;
  int tot = 0;
  tot += power[res1] - 1 + mod;
  tot += power[res2] - 1 + mod;
  tot += res3 + 1;
  tot %= mod;
  ans *= tot;
  ans %= mod;
  ans += mod - 1;
  ans %= mod;
  cout << ans;
}