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

#include <bits/stdc++.h>
using namespace std;
#define endl '\\n'
typedef long long ll;
// const ll Mod = 1e9 + 7;
const ll Mod = 1000000007;
const int mxN = 2e5 + 5;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll power[mxN];
int main() {
  // ios::sync_with_stdio(false);
  // cin.tie(0);
  power[0] = 1;
  for (int i = 1; i < mxN; i++) {
    power[i] = power[i - 1] * 2 % Mod;
  }
  int n;
  // cin >> n;
  scanf("%d", &n);
  // map<double, pair<int, int>> mp;
  ll special = Mod - 1;
  map<pair<ll, ll>, pair<int, int>> mp;
  for (int i = 0; i < n; i++) {
    // double a, b;
    ll a, b;
    // cin >> a >> b;
    scanf("%lld%lld", &a, &b);
    if (a == 0LL && b == 0LL) {
      special++;
      continue;
    }
    if (make_pair(a, b) < make_pair(0ll, 0ll))
      a = -a, b = -b;
    ll g = gcd(abs(a), abs(b));
    a = a / g, b = b / g;
    // pair<ll, ll> ang = make_pair(a, b);
    // pair<ll, ll> bad = a >= 0 ? make_pair(-b, a) : make_pair(b, -a);
    if (b > 0)
      mp[{a, b}].first++;
    else
      mp[{-b, a}].second++;
    // if (mp.find(bad) != mp.end()) {
    //     mp[bad].second++;
    // } else {
    //     mp[ang].first++;
    // }
  }

  ll ans = 1;
  for (auto &p : mp) {
    // if (p.second.second == 0) {
    //     ans = ans * power[p.second.first] % Mod;
    // } else {
    //     ans = ans * (power[p.second.first] + power[p.second.second] - 1)
    //     %
    //           Mod;
    // }
    ans = ans * (power[p.second.first] + power[p.second.second] - 1) % Mod;
  }
  // cout << (ans - 1LL + special) % Mod << '\\n';
  // cout << ans << " " << special << endl;
  printf("%lld\\n", (ans + special) % Mod);
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define endl '\\n'
typedef long long ll;
const ll Mod = 1e9 + 7;
ll power(ll y) {
  ll res = 1LL;
  ll x = 2LL;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % Mod;
    y = y >> 1; // y = y/2
    x = (x * x) % Mod;
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(9);
  int n;
  cin >> n;
  // map<double, pair<int, int>> mp;
  int special = 0;
  map<pair<int, int>, pair<int, int>> mp;
  for (int i = 0; i < n; i++) {
    // double a, b;
    int a, b;
    cin >> a >> b;
    if (a == 0 && b == 0) {
      special++;
      continue;
    } else if (a == 0) {
      b = 1;
    } else if (b == 0) {
      a = -1;
    } else {
      int g = __gcd(a, b);
      a = a / g, b = b / g;
      if (b < 0)
        a = -a, b = -b;
    }
    pair<int, int> ang = make_pair(a, b);
    pair<int, int> bad = a >= 0 ? make_pair(-b, a) : make_pair(b, -a);
    if (mp.find(bad) != mp.end()) {
      mp[bad].second++;
    } else {
      mp[ang].first++;
    }
  }

  ll ans = 1;
  for (auto &p : mp) {
    // cout << p.first.first << ", " << p.first.second << " : "
    //      << p.second.first << " " << p.second.second << endl;
    if (p.second.second == 0) {
      ans = ans * power(p.second.first) % Mod;
    } else {
      ll c1 = (power(p.second.first) + power(p.second.second) - 1) % Mod;
      // ll c2 = power(p.second.second);
      ans = ans * c1 % Mod;
      // ans = (ans * (c1 + c2 - 1)) % Mod;
    }
  }
  cout << ans - 1 + special << '\\n';
}