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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll gcd(ll a, ll b) {
  if (!b)
    return a;
  return gcd(b, a % b);
}
int main() {
  ll n, A[200001], B[200001];
  cin >> n;
  rep(i, n) cin >> A[i] >> B[i];
  vector<P> C, D;
  rep(i, n) if (A[i] && B[i]) {
    C.push_back(P(A[i] / gcd(A[i], B[i]), B[i] / gcd(A[i], B[i])));
    D.push_back(P(-B[i] / gcd(A[i], B[i]), A[i] / gcd(A[i], B[i])));
  }
  rep(i, C.size()) if (C[i].second < 0) C[i].first *= (-1), C[i].second *= (-1);
  rep(i, D.size()) if (D[i].second < 0) D[i].first *= (-1), D[i].second *= (-1);
  sort(all(C));
  sort(all(D));
  ll mod = 1e9 + 7, a = 0, z = 0;
  vector<P> E;
  P c;
  rep(i, C.size()) {
    if ((C[i].first > 0) ^ (C[i].second > 0))
      continue;
    z++;
    if (z == 1)
      c = C[i];
    if (c == C[i])
      a++;
    if (c != C[i]) {
      ll b = upper_bound(all(D), c) - lower_bound(all(D), c);
      if (b)
        E.push_back(P(a, b));
      a = 1;
      c = C[i];
    }
  }
  ll b = upper_bound(all(D), c) - lower_bound(all(D), c);
  if (b)
    E.push_back(P(a, b));
  ll X = 0, Y = 0, Z = 0;
  rep(i, n) {
    if (!A[i] && B[i])
      X++;
    if (A[i] && !B[i])
      Y++;
    if (!A[i] && !B[i])
      Z++;
  }
  if (X && Y)
    E.push_back(P(X, Y));
  ll sum = 0;
  for (auto i : E) {
    sum += i.first + i.second;
  }
  vec F(n + 1, 1);
  rep(i, n) F[i + 1] = F[i] * 2 % mod;
  ll ans = F[n - Z - sum];
  for (auto i : E) {
    ans = ans * ((F[i.first] + F[i.second] - 1 + mod) % mod) % mod;
  }
  cout << (ans + Z - 1 + mod) % mod << "\\n";
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main() {
  ll n;
  double A[200001], B[200001];
  cin >> n;
  rep(i, n) cin >> A[i] >> B[i];
  vector<double> C, D;
  rep(i, n) if (A[i] && B[i]) C.push_back(A[i] / B[i]),
      D.push_back(-B[i] / A[i]);
  sort(all(C));
  sort(all(D));
  ll mod = 1e9 + 7, a = 0, z = 0;
  vector<P> E;
  double c;
  if (C.size() > 0)
    c = C[0];
  rep(i, C.size()) {
    if (abs(C[i]) < 1 || C[i] == -1)
      continue;
    if (c == C[i])
      a++;
    if (c != C[i]) {
      ll b = upper_bound(all(D), c) - lower_bound(all(D), c);
      if (b)
        E.push_back(P(a, b));
      a = 1;
      c = C[i];
    }
  }
  ll b = upper_bound(all(D), c) - lower_bound(all(D), c);
  if (b)
    E.push_back(P(a, b));
  ll X = 0, Y = 0, Z = 0;
  rep(i, n) {
    if (!A[i] && B[i])
      X++;
    if (A[i] && !B[i])
      Y++;
    if (!A[i] && !B[i])
      Z++;
  }
  if (X && Y)
    E.push_back(P(X, Y));
  ll sum = 0;
  for (auto i : E) {
    sum += i.first + i.second;
  }
  vec F(n + 1, 1);
  rep(i, n) F[i + 1] = F[i] * 2 % mod;
  ll ans = F[n - Z - sum];
  for (auto i : E) {
    ans = ans * ((F[i.first] + F[i.second] - 1 + mod) % mod) % mod;
  }
  cout << (ans + Z - 1 + mod) % mod << "\\n";
}