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

#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL << 60;
const long long int Mod = 1000000007;
using ll = long long int;
using ci = const int;
using vi = vector<int>;
using Vi = vector<long long int>;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define all(x) (x).begin(), (x).end()
#define rp(i, N) for (ll i = 0; i < (ll)N; i++)
#define repi(i, a, b) for (ll i = ll(a); i < ll(b); ++i)
template <class T> bool chmax(T &former, const T &b) {
  if (former < b) {
    former = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &former, const T &b) {
  if (b < former) {
    former = b;
    return true;
  }
  return false;
}
template <class T> T sqar(T x) { return x * x; } // sqrt(x)は平方根;
#define Sort(v)                                                                \\
  std::sort(v.begin(), v.end(),                                                \\
            std::greater<decltype(v[0])>()) // 降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v>>
template <class T> inline void princ(T x) { cout << x << " "; };
template <class T> inline void print(T x) { cout << x << "\\n"; };
template <class T> inline void Yes(T condition) {
  if (condition)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
template <class T> inline void YES(T condition) {
  if (condition)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
///////////////////////////////////////////////////////////////////////////////////
ll gcd(ll x, ll y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}
ll pow(ll x, ll y, ll mod) {
  if (y == 0)
    return 1ll;
  if (y & 1)
    return x * pow(x, y - 1, mod) % mod;
  ll p = pow(x, y / 2, mod);
  return p * p % mod;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(30);
  int n;
  cin >> n;
  vector<pair<PLL, int>> vt(200050);
  int d_zero = 0;
  int a_zero = 0;
  int b_zero = 0;
  rp(i, n) {
    ll a, b;
    cin >> a >> b;
    if (a == 0 && b == 0) {
      d_zero++;
      continue;
    }
    if (a == 0) {
      a_zero++;
      continue;
    }
    if (b == 0) {
      b_zero++;
      continue;
    }
    bool swapped = false;
    bool minus = false;
    if ((a < 0 && b > 0) || (a > 0 && b < 0))
      minus = true;
    a = abs(a);
    b = abs(b);
    if (a > b) {
      swap(a, b);
      swapped = true;
    }

    int which;
    if (swapped) {
      if (minus)
        which = 3;
      else
        which = 2;
    } else {
      if (minus)
        which = 1;
      else
        which = 0;
    }
    if (a == b) {
      if (minus)
        which = 4;
      else
        which = 5;
    }
    vt[i - d_zero - a_zero - b_zero] =
        (mp(mp(a / gcd(a, b), b / gcd(a, b)), which));
  }
  int cts = n - d_zero - a_zero - b_zero;
  auto it = vt.begin();
  vt.resize(cts);
  sort(it, it + cts);
  /*for(auto pp:vt){
      cout << pp.first.first << " " << pp.first.second << " " << pp.second <<
  endl;
  }*/
  vi c(6, 0);
  ll ans = 1;
  if (cts != 0)
    c[vt[0].second]++;
  repi(i, 1, cts) {
    if (vt[i].first == vt[i - 1].first) {
      c[vt[i].second]++;
      // print(i);
      continue;
    }
    // cout << c[0] << c[1] << c[2] << c[3] << endl;
    ll summ = (pow(2, c[0], Mod) + pow(2, c[3], Mod) - 1 + Mod) % Mod;
    ans *= summ;
    ans %= Mod;
    summ = (pow(2, c[1], Mod) + pow(2, c[2], Mod) - 1 + Mod) % Mod;
    ans *= summ;
    ans %= Mod;
    summ = (pow(2, c[4], Mod) + pow(2, c[5], Mod) - 1 + Mod) % Mod;
    ans *= summ;
    ans %= Mod;
    // print(ans);
    c[0] = c[1] = c[2] = c[3] = c[4] = c[5] = 0;
    c[vt[i].second]++;
  }
  // print(ans);
  ll sum = (pow(2, c[0], Mod) + pow(2, c[3], Mod) - 1 + Mod) % Mod;
  ans *= sum;
  ans %= Mod;
  sum = (pow(2, c[1], Mod) + pow(2, c[2], Mod) - 1 + Mod) % Mod;
  ans *= sum;
  ans %= Mod;
  sum = (pow(2, c[4], Mod) + pow(2, c[5], Mod) - 1 + Mod) % Mod;
  ans *= sum;
  ans %= Mod;
  // print(ans);
  ans *= (pow(2, a_zero, Mod) + pow(2, b_zero, Mod) - 1 + Mod) % Mod;
  ans %= Mod;
  ans += d_zero;
  ans -= 1;
  if (ans < 0)
    ans += Mod;
  ans %= Mod;
  print(ans);
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL << 60;
const long long int Mod = 1000000007;
using ll = long long int;
using ci = const int;
using vi = vector<int>;
using Vi = vector<long long int>;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define all(x) (x).begin(), (x).end()
#define rp(i, N) for (ll i = 0; i < (ll)N; i++)
#define repi(i, a, b) for (ll i = ll(a); i < ll(b); ++i)
template <class T> bool chmax(T &former, const T &b) {
  if (former < b) {
    former = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &former, const T &b) {
  if (b < former) {
    former = b;
    return true;
  }
  return false;
}
template <class T> T sqar(T x) { return x * x; } // sqrt(x)は平方根;
#define Sort(v)                                                                \\
  std::sort(v.begin(), v.end(),                                                \\
            std::greater<decltype(v[0])>()) // 降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v>>
template <class T> inline void princ(T x) { cout << x << " "; };
template <class T> inline void print(T x) { cout << x << "\\n"; };
template <class T> inline void Yes(T condition) {
  if (condition)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
template <class T> inline void YES(T condition) {
  if (condition)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
///////////////////////////////////////////////////////////////////////////////////
ll gcd(ll x, ll y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}
ll pow(ll x, ll y, ll mod) {
  if (y == 0)
    return 1;
  if (y & 1)
    return x * pow(x, y - 1, mod) % mod;
  ll p = pow(x, y / 2, mod);
  return p * p % mod;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(30);
  int n;
  cin >> n;
  vector<pair<PLL, int>> vt;
  int d_zero = 0;
  int a_zero = 0;
  int b_zero = 0;
  rp(i, n) {
    ll a, b;
    cin >> a >> b;
    if (a == 0 && b == 0) {
      d_zero++;
      continue;
    }
    if (a == 0) {
      a_zero++;
      continue;
    }
    if (b == 0) {
      b_zero++;
      continue;
    }
    bool swapped = false;
    bool minus = false;
    if ((a < 0 && b > 0) || (a > 0 && b < 0))
      minus = true;
    a = abs(a);
    b = abs(b);
    if (a > b) {
      swap(a, b);
      swapped = true;
    }

    int which;
    if (swapped) {
      if (minus)
        which = 3;
      else
        which = 2;
    } else {
      if (minus)
        which = 1;
      else
        which = 0;
    }
    if (a == b) {
      if (minus)
        which = 4;
      else
        which = 5;
    }
    vt.pb(mp(mp(a / gcd(a, b), b / gcd(a, b)), which));
  }
  int si = vt.size();
  sort(all(vt));
  /*for(auto pp:vt){
      cout << pp.first.first << " " << pp.first.second << " " << pp.second <<
  endl;
  }*/
  Vi c(6, 0);
  ll ans = 1;
  c[vt[0].second]++;
  repi(i, 1, si) {
    if (vt[i].first == vt[i - 1].first) {
      c[vt[i].second]++;
      // print(i);
      continue;
    }
    // cout << c[0] << c[1] << c[2] << c[3] << endl;
    ll summ = (pow(2, c[0], Mod) + pow(2, c[3], Mod) - 1);
    summ %= Mod;
    summ *= (pow(2, c[1], Mod) + pow(2, c[2], Mod) - 1) % Mod;
    summ %= Mod;
    summ *= (pow(2, c[4], Mod) + pow(2, c[5], Mod) - 1) % Mod;
    summ %= Mod;
    ans *= summ;
    ans %= Mod;
    // print(ans);
    c[0] = c[1] = c[2] = c[3] = c[4] = c[5] = 0;
    c[vt[i].second]++;
  }
  // print(ans);
  ll sum = (pow(2, c[0], Mod) + pow(2, c[3], Mod) - 1);
  sum %= Mod;
  sum *= (pow(2, c[1], Mod) + pow(2, c[2], Mod) - 1) % Mod;
  sum %= Mod;
  sum *= (pow(2, c[4], Mod) + pow(2, c[5], Mod) - 1) % Mod;
  sum %= Mod;
  ans *= sum;
  ans %= Mod;
  // print(ans);
  ans *= (pow(2, a_zero, Mod) + pow(2, b_zero, Mod) - 1) % Mod;
  ans %= Mod;
  print(ans - 1);
  return 0;
}