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

#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

long long mod = 1000000007;

long long gcd(long long a, long long b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}

long long binpow(long long x, long long k) {
  if (k == 0) {
    return 1LL;
  }
  long long temp = binpow(x, k / 2);
  if (k % 2 == 1) {
    return (((temp * temp) % mod) * x) % mod;
  } else {
    return (temp * temp) % mod;
  }
}

int main() {
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  cin.tie();
  cout.tie();
  // ifstream cin("in.txt");
  // ofstream cout("out.txt");

  // int t;
  // cin >> t;
  // for (int qwe = 0; qwe < t; qwe++)
  // {
  //     cout << "Case #" << qwe + 1 << ": ";
  // }

  int n;
  cin >> n;
  vector<pair<long long, long long>> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i].first >> v[i].second;
    if (v[i].first == 0 && v[i].second == 0) {
      continue;
    }
    long long x = gcd(max(abs(v[i].first), abs(v[i].second)),
                      min(abs(v[i].first), abs(v[i].second)));
    if (x != 0) {
      v[i].first /= x;
      v[i].second /= x;
    }
    if (v[i].first < 0 || (v[i].first == 0 && v[i].second < 0)) {
      v[i].first *= -1;
      v[i].second *= -1;
    }
  }
  map<pair<long long, long long>, int> mp;
  set<pair<long long, long long>> st;
  for (int i = 0; i < n; i++) {
    mp[v[i]]++;
    st.insert(v[i]);
  }
  long long rez = 1;
  set<pair<long long, long long>> done;
  for (set<pair<long long, long long>>::iterator it = st.begin();
       it != st.end(); it++) {
    if (it->first == 0 && it->second == 0) {
      continue;
    }
    if (done.find(*it) != done.end()) {
      continue;
    }
    pair<long long, long long> val = *it;
    if (val.second < 0) {
      val = {-val.second, val.first};
    }
    // cout << val.first << " " << val.second << " " << (binpow(2, mp[val]) +
    // binpow(2, mp[{ val.second, -val.first }]) - 1) << '\\n';
    rez *= (binpow(2, mp[val]) + binpow(2, mp[{val.second, -val.first}]) - 1) %
           mod;
    rez %= mod;
    done.insert(val);
    done.insert({val.second, -val.first});
  }
  cout << (rez + mp[{0, 0}] + mod - 1) % mod << '\\n';

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

long long mod = 1000000007;

long long gcd(long long a, long long b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}

long long binpow(long long x, long long k) {
  if (k == 0) {
    return 1LL;
  }
  long long temp = binpow(x, k / 2);
  if (k % 2 == 1) {
    return (((temp * temp) % mod) * x) % mod;
  } else {
    return (temp * temp) % mod;
  }
}

int main() {
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  cin.tie();
  cout.tie();
  // ifstream cin("in.txt");
  // ofstream cout("out.txt");

  // int t;
  // cin >> t;
  // for (int qwe = 0; qwe < t; qwe++)
  // {
  //     cout << "Case #" << qwe + 1 << ": ";
  // }

  int n;
  cin >> n;
  vector<pair<long long, long long>> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i].first >> v[i].second;
    long long x = gcd(abs(v[i].first), abs(v[i].second));
    v[i].first /= x;
    v[i].second /= x;
    if (v[i].first < 0 || (v[i].first == 0 && v[i].second < 0)) {
      v[i].first *= -1;
      v[i].second *= -1;
    }
  }
  map<pair<long long, long long>, int> mp;
  set<pair<long long, long long>> st;
  for (int i = 0; i < n; i++) {
    mp[v[i]]++;
    st.insert(v[i]);
  }
  long long rez = 1;
  set<pair<long long, long long>> done;
  for (set<pair<long long, long long>>::iterator it = st.begin();
       it != st.end(); it++) {
    if (it->first == 0 && it->second == 0) {
      continue;
    }
    if (done.find(*it) != done.end()) {
      continue;
    }
    pair<long long, long long> val = *it;
    if (val.second < 0) {
      val = {-val.second, val.first};
    }
    // cout << val.first << " " << val.second << " " << (binpow(2, mp[val]) +
    // binpow(2, mp[{ val.second, -val.first }]) - 1) << '\\n';
    rez *= (binpow(2, mp[val]) + binpow(2, mp[{val.second, -val.first}]) - 1) %
           mod;
    rez %= mod;
    done.insert(val);
    done.insert({val.second, -val.first});
  }
  if (done.empty()) {
    cout << "1\\n";
    return 0;
  } else {
    cout << (rez + mod - 1) % mod << '\\n';
  }

  return 0;
}