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

// Hail god Yato

#include <bits/stdc++.h>
using namespace std;

#define hs                                                                     \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX = 200008;
//
//

ll mpow(ll x, ll y) {
  ll res = 1LL;
  x %= MOD;
  while (y) {
    if (y & 1) {
      res = res * x;
      res %= MOD;
    }
    y >>= 1;
    x = x * x;
    x %= MOD;
  }
  return res;
}

ll fst[MAX], snd[MAX];
map<pair<ll, ll>, ll> m;
pair<ll, ll> check(int idx) {
  ll x = fst[idx], y = snd[idx];
  if (x == 0 && y == 0)
    return {0, 0};
  ll g = __gcd(x, y);
  x /= g;
  y /= g;
  if (y < 0)
    x *= -1, y *= -1;
  if (x == 0)
    y = 1;
  if (y == 0)
    x = 1;
  return {x, y};
}
pair<ll, ll> opp(pair<ll, ll> pairs) {
  ll x = pairs.first, y = pairs.second;
  swap(x, y);
  if (x == 0 && y == 0)
    return {0, 0};
  x *= -1;
  if (y < 0)
    x *= -1, y *= -1;
  if (x == 0)
    y = 1;
  if (y == 0)
    x = 1;
  return {x, y};
}
void solve() {
  // cout<<mpow(2, 3);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> fst[i] >> snd[i];
    m[check(i)]++;
  }
  ll ans = 1;
  map<pair<ll, ll>, ll> vis;
  for (auto &itr : m) {
    if (vis[itr.first] == 1)
      continue;
    pair<ll, ll> zero = {0, 0};
    if (itr.first == zero)
      continue;
    vis[itr.first] = 1;
    pair<ll, ll> oppo = opp(itr.first);
    if (m.count(oppo)) {
      ll plus = itr.second;
      vis[oppo] = 1;
      ll minus = m[oppo];
      ans *= (mpow(2, plus) + mpow(2, minus) - 1);
    } else {
      ans *= mpow(2, itr.second);
    }
    ans %= MOD;
  }
  ans -= 1;
  ans += MOD;
  ans += m[{0, 0}];
  ans %= MOD;
  cout << ans;
}
int main() {
  hs;
  ll t;
  t = 1;
  // cin>>t;
  for (int i = 1; i <= t; i++) {
    // cout<<"Case #"<<i<<": ";
    solve();
  }
  return 0;
}

Error: WA

Fixed submission:

// Hail god Yato

#include <bits/stdc++.h>
using namespace std;

#define hs                                                                     \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
//
//

ll mpow(ll x, ll y) {
  ll res = 1LL;
  x %= MOD;
  while (y) {
    if (y & 1) {
      res = res * x;
      res %= MOD;
    }
    y >>= 1;
    x = x * x;
    x %= MOD;
  }
  return res;
}

ll fst[MAX], snd[MAX];
map<pair<ll, ll>, ll> m;
pair<ll, ll> check(int idx) {
  ll x = fst[idx], y = snd[idx];
  if (x == 0 && y == 0)
    return {0, 0};
  ll g = __gcd(x, y);
  x /= g;
  y /= g;
  if (y < 0)
    x *= -1, y *= -1;
  return {x, y};
}
pair<ll, ll> opp(pair<ll, ll> pairs) {
  ll x = pairs.first, y = pairs.second;
  swap(x, y);
  if (x == 0 && y == 0)
    return {0, 0};
  x *= -1;
  if (y < 0)
    x *= -1, y *= -1;
  return {x, y};
}
void solve() {
  // cout<<mpow(2, 3);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> fst[i] >> snd[i];
    m[check(i)]++;
  }
  ll ans = 1;
  map<pair<ll, ll>, ll> vis;
  for (auto &itr : m) {
    if (vis[itr.first] == 1)
      continue;
    vis[itr.first] = 1;
    pair<ll, ll> oppo = opp(itr.first);
    if (m.count(oppo)) {
      ll plus = itr.second;
      vis[oppo] = 1;
      ll minus = m[oppo];
      ans *= (mpow(2, plus) + mpow(2, minus) - 1);
    } else {
      ans *= mpow(2, itr.second);
    }
    ans %= MOD;
  }
  ans -= 1;
  ans += MOD;
  ans %= MOD;
  cout << ans;
}
int main() {
  hs;
  ll t;
  t = 1;
  // cin>>t;
  for (int i = 1; i <= t; i++) {
    // cout<<"Case #"<<i<<": ";
    solve();
  }
  return 0;
}