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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, s, n) for (int i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()
#define outve(v)                                                               \\
  for (auto i : v)                                                             \\
    cout << i << " ";                                                          \\
  cout << endl
#define outmat(v)                                                              \\
  for (auto i : v) {                                                           \\
    for (auto j : i)                                                           \\
      cout << j << " ";                                                        \\
    cout << endl;                                                              \\
  }
#define in(n, v)                                                               \\
  for (int i = 0; i < (n); i++) {                                              \\
    cin >> v[i];                                                               \\
  }
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vvp = vector<vector<pair<int, int>>>;
template <typename T> using ve = vector<T>;
template <typename T> using pq2 = priority_queue<T>;
template <typename T> using pq1 = priority_queue<T, vector<T>, greater<T>>;
template <typename T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T> T gcd(T a, T b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T extgcd(T a, T b, T &x, T &y) {
  T d = a;
  if (b != 0) {
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else
    x = 1, y = 0;
  return d;
}
template <typename T> T modpow(T x, T n, T m) {
  if (n == 0)
    return 1;
  T resp = modpow(x * x % m, n / 2, m);
  if (n & 1)
    resp = resp * x % m;
  return resp;
}
template <typename T> T modinverse(T a, T m) {
  T x, y;
  extgcd(a, m, x, y);
  return (m + x % m) % m;
}
struct combination {
  ll M = mod;
  vector<ll> fact, ifact;
  combination(ll n) : fact(n + 1), ifact(n + 1) {
    fact[0] = 1;
    ifact[0] = 1;
    for (ll i = 0; i < n; i++) {
      fact[i + 1] = fact[i] * (i + 1) % M;
      ifact[i + 1] = ifact[i] * modpow(i + 1, M - 2, M) % M;
    }
  }
  ll com(ll a, ll b) {
    if (a == 0 && b == 0)
      return 1;
    if (a < b || a < 0)
      return 0;
    ll tmp = ifact[a - b] * ifact[b] % M;
    return tmp * fact[a] % M;
  }
};

int main() {

  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int N;
  cin >> N;

  vl A(N), B(N);
  rep(i, N) cin >> A[i] >> B[i];

  rep(i, N) {
    ll a = A[i], b = B[i];
    if (a > 0 && b > 0) {
      ll c = gcd(a, b);
      a /= c, b /= c;
    } else if (a > 0 && b < 0) {
      ll c = gcd(a, -b);
      a /= c, b /= c;
    } else if (a < 0 && b > 0) {
      ll c = gcd(-a, b);
      a /= c, b /= c;
      a = -a;
      b = -b;
    } else if (a < 0 && b < 0) {
      ll c = gcd(-a, -b);
      a /= c, b /= c;
      a = -a, b = -b;
    } else if (a == 0 && b != 0) {
      a = 0;
      b = 1;
    } else if (a != 0 && b == 0) {
      a = 1;
      b = 0;
    } else {
      continue;
    }

    A[i] = a, B[i] = b;
  }

  map<pll, ll> D;
  rep(i, N) D[{A[i], B[i]}]++;

  ve<pll> E;
  set<pll> F;

  for (auto p : D) {
    if (p.fi.fi == 0 && p.fi.se == 0) {
      E.pb({p.se, -1});
      continue;
    }
    // cout << "{" << p.fi.fi csp p.fi.se <<  "} " <<  p.se << endl;

    if (F.count(p.fi))
      continue;

    ll a1 = p.se;
    ll a2 = 0;
    if (D.count({p.fi.se, -p.fi.fi})) {
      a2 = D[{p.fi.se, -p.fi.fi}];
      F.insert({p.fi.se, -p.fi.fi});
    } else if (D.count({-p.fi.se, p.fi.fi})) {
      a2 = D[{-p.fi.se, p.fi.fi}];
      F.insert({-p.fi.se, p.fi.fi});
    }
    F.insert(p.fi);
    E.pb({a1, a2});
    // cout << a1 csp a2 << endl;
  }

  ll ans = 1;
  ll ze = 0;

  for (pll p : E) {
    if (p.se < 0) {
      ze += p.fi;
      // cout << ze << endl;
      continue;
    }
    ll aa = modpow((ll)2, p.fi, (ll)mod) + modpow((ll)2, p.se, (ll)mod) - 1;
    // cout << aa << endl;
    aa %= mod;
    ans *= aa;
    ans %= mod;
  }

  cout << (ans + mod - 1 + ze) % mod << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, s, n) for (int i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()
#define outve(v)                                                               \\
  for (auto i : v)                                                             \\
    cout << i << " ";                                                          \\
  cout << endl
#define outmat(v)                                                              \\
  for (auto i : v) {                                                           \\
    for (auto j : i)                                                           \\
      cout << j << " ";                                                        \\
    cout << endl;                                                              \\
  }
#define in(n, v)                                                               \\
  for (int i = 0; i < (n); i++) {                                              \\
    cin >> v[i];                                                               \\
  }
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vvp = vector<vector<pair<int, int>>>;
template <typename T> using ve = vector<T>;
template <typename T> using pq2 = priority_queue<T>;
template <typename T> using pq1 = priority_queue<T, vector<T>, greater<T>>;
template <typename T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T> T gcd(T a, T b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T extgcd(T a, T b, T &x, T &y) {
  T d = a;
  if (b != 0) {
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else
    x = 1, y = 0;
  return d;
}
template <typename T> T modpow(T x, T n, T m) {
  if (n == 0)
    return 1;
  T resp = modpow(x * x % m, n / 2, m);
  if (n & 1)
    resp = resp * x % m;
  return resp;
}
template <typename T> T modinverse(T a, T m) {
  T x, y;
  extgcd(a, m, x, y);
  return (m + x % m) % m;
}
struct combination {
  ll M = mod;
  vector<ll> fact, ifact;
  combination(ll n) : fact(n + 1), ifact(n + 1) {
    fact[0] = 1;
    ifact[0] = 1;
    for (ll i = 0; i < n; i++) {
      fact[i + 1] = fact[i] * (i + 1) % M;
      ifact[i + 1] = ifact[i] * modpow(i + 1, M - 2, M) % M;
    }
  }
  ll com(ll a, ll b) {
    if (a == 0 && b == 0)
      return 1;
    if (a < b || a < 0)
      return 0;
    ll tmp = ifact[a - b] * ifact[b] % M;
    return tmp * fact[a] % M;
  }
};

int main() {

  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int N;
  cin >> N;

  vl A(N), B(N);
  rep(i, N) cin >> A[i] >> B[i];

  rep(i, N) {
    ll a = A[i], b = B[i];
    if (a >= 0 && b >= 0) {
      ll c = gcd(a, b);
      a /= c, b /= c;
    } else if (a >= 0 && b <= 0) {
      ll c = gcd(a, -b);
      a /= c, b /= c;
    } else if (a <= 0 && b >= 0) {
      ll c = gcd(-a, b);
      a /= c, b /= c;
      a = -a;
      b = -b;
    } else {
      ll c = gcd(-a, -b);
      a /= c, b /= c;
      a = -a, b = -b;
    }
    A[i] = a, B[i] = b;
  }

  map<pll, ll> D;
  rep(i, N) D[{A[i], B[i]}]++;

  ve<pll> E;
  set<pll> F;

  for (auto p : D) {
    // cout << "{" << p.fi.fi csp p.fi.se <<  "} " <<  p.se << endl;

    if (F.count(p.fi))
      continue;

    ll a1 = p.se;
    ll a2 = 0;
    if (D.count({p.fi.se, -p.fi.fi})) {
      a2 = D[{p.fi.se, -p.fi.fi}];
      F.insert({p.fi.se, -p.fi.fi});
    } else if (D.count({-p.fi.se, p.fi.fi})) {
      a2 = D[{-p.fi.se, p.fi.fi}];
      F.insert({-p.fi.se, p.fi.fi});
    }
    F.insert(p.fi);
    E.pb({a1, a2});
    // cout << a1 csp a2 << endl;
  }

  ll ans = 1;

  for (pll p : E) {
    ll aa = modpow((ll)2, p.fi, (ll)mod) + modpow((ll)2, p.se, (ll)mod) - 1;
    // cout << aa << endl;
    aa %= mod;
    ans *= aa;
    ans %= mod;
  }

  cout << (ans + mod - 1) % mod << endl;

  return 0;
}