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

#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
LL gcd(LL a, LL b) { return b == 0 ? a : gcd(b, a % b); }
pair<LL, LL> normalize(pair<LL, LL> u) // quadrants 1 and 2 always
{
  LL x = u.first, y = u.second;

  if (x == 0 && y == 0)
    return {0, 0};
  if (x == 0)
    return {0, 1};
  else if (y == 0)
    return {1, 0};

  LL d = gcd(x, y);
  if (d < 0)
    d *= -1;

  x /= d;
  y /= d;
  if (y < 0) {
    x *= -1;
    y *= -1;
  }
  return {x, y};
}
pair<LL, LL> ortho(pair<LL, LL> u) { return {-u.second, u.first}; }
LL mod_pow(LL base, LL exp) {
  if (exp == 0)
    return 1;
  if (exp & 1)
    return (base * mod_pow(base, exp - 1)) % MOD;
  else
    return mod_pow((base * base) % MOD, exp >> 1);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int n;
  cin >> n;
  map<pair<LL, LL>, LL> slopes;
  LL total_losers = 0;
  for (int i = 0; i < n; i++) {
    LL x, y;
    cin >> x >> y;
    if (x == 0 && y == 0)
      total_losers++;
    else {
      slopes[normalize({x, y})]++;
      slopes[normalize(ortho({x, y}))] += 0;
    }
  }
  set<pair<LL, LL>> done;
  LL ans = 1;
  for (const auto &p : slopes) {
    pair<LL, LL> u = p.first;
    pair<LL, LL> v = normalize(ortho(u));
    // cout<<u.first<<","<<u.second<<" and "<<v.first<<","<<v.second<<endl;
    if (!done.count(u) && !done.count(v)) {
      // cout<<slopes[u]<<" and "<<slopes[v]<<endl;
      ans = (ans * (mod_pow(2, slopes[u]) + mod_pow(2, slopes[v]) - 1)) % MOD;
      done.insert(u);
      done.insert(v);
    }
  }
  ans = ((ans + total_losers - 1) % MOD + MOD) % MOD;
  cout << ans << '\\n';

  cout << flush;
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
LL gcd(LL a, LL b) { return b == 0 ? a : gcd(b, a % b); }
pair<LL, LL> normalize(pair<LL, LL> u) // quadrants 1 and 2 always
{
  LL x = u.first, y = u.second;

  LL d = gcd(x, y);
  if (d < 0)
    d *= -1;

  x /= d;
  y /= d;
  if (y < 0) {
    x *= -1;
    y *= -1;
  }
  return {x, y};
}
pair<LL, LL> ortho(pair<LL, LL> u) { return {-u.second, u.first}; }
LL mod_pow(LL base, LL exp) {
  if (exp == 0)
    return 1;
  if (exp & 1)
    return (base * mod_pow(base, exp - 1)) % MOD;
  else
    return mod_pow((base * base) % MOD, exp >> 1);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int n;
  cin >> n;
  map<pair<LL, LL>, LL> slopes;
  for (int i = 0; i < n; i++) {
    LL x, y;
    cin >> x >> y;
    slopes[normalize({x, y})]++;
    slopes[normalize(ortho({x, y}))] += 0;
  }
  set<pair<LL, LL>> done;
  LL ans = 1;
  for (const auto &p : slopes) {
    pair<LL, LL> u = p.first;
    pair<LL, LL> v = normalize(ortho(u));
    // cout<<u.first<<","<<u.second<<" and "<<v.first<<","<<v.second<<endl;
    if (!done.count(u) && !done.count(v)) {
      // cout<<slopes[u]<<" and "<<slopes[v]<<endl;
      ans = (ans * (mod_pow(2, slopes[u]) + mod_pow(2, slopes[v]) - 1)) % MOD;
      done.insert(u);
      done.insert(v);
    }
  }
  ans = ((ans - 1) % MOD + MOD) % MOD;
  cout << ans << '\\n';

  cout << flush;
  return 0;
}