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

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using st = string;
using ch = char;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vst = vector<st>;
using vch = vector<char>;
using vbl = vector<bl>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for (auto &i : vec)
#define vin(vec)                                                               \\
  for (auto &i : vec)                                                          \\
  cin >> i
#define all(v) v.begin(), v.end()
#define mkp(a, b) make_pair(a, b)
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const ll mod = 1000000007;
const ll inf = 1LL << 60;
const db pi = acos(-1.0L);

ll modpow(ll a, ll n) {
  ll ans = 1;
  while (n > 0) {
    if (n & 1)
      ans = ans * a % mod;
    n >>= 1;
    a = a * a % mod;
  }
  return ans;
}

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

int main() {
  ll n;
  cin >> n;
  map<pll, pll> slope;
  ll all0 = 0;
  rep(i, 0, n) {
    ll a, b;
    cin >> a >> b;
    if (a == 0 && b == 0) {
      all0++;
      continue;
    }
    if (mkp(a, b) < mkp(0ll, 0ll))
      a = -a, b = -b;
    ll g = gcd(abs(a), abs(b));
    a /= g, b /= g;
    if (b <= 0)
      slope[mkp(-b, a)].second++;
    else
      slope[mkp(a, b)].first++;
  }

  ll ans = 1;
  vrep(i, slope) {
    ll num1 = i.second.first, num2 = i.second.second;
    ans = ans * (modpow(2, num1) + modpow(2, num2) - 1) % mod;
  }
  cout << (ans + all0 - 1 + mod) % mod << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using st = string;
using ch = char;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vst = vector<st>;
using vch = vector<char>;
using vbl = vector<bl>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for (auto &i : vec)
#define vin(vec)                                                               \\
  for (auto &i : vec)                                                          \\
  cin >> i
#define all(v) v.begin(), v.end()
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const ll mod = 1000000007;
const ll inf = 1LL << 60;
const db pi = acos(-1.0L);

ll modpow(ll a, ll n) {
  ll ans = 1;
  while (n > 0) {
    if (n & 1)
      ans = ans * a % mod;
    n >>= 1;
    a = a * a % mod;
  }
  return ans;
}

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

int main() {
  ll n;
  cin >> n;
  ll all0 = 0;
  map<pll, ll> slope;
  rep(i, 0, n) {
    ll a, b;
    cin >> a >> b;
    if (a == 0 && b == 0) {
      all0++;
    } else if (a == 0)
      slope[make_pair(0, 1)]++;
    else if (b == 0)
      slope[make_pair(1, 0)]++;
    ll aa = ((a > 0) - (a < 0)) * ((b > 0) - (b < 0)) * abs(a) /
            gcd(abs(a), abs(b));
    ll bb = abs(b) / gcd(abs(a), abs(b));
    slope[make_pair(aa, bb)]++;
  }

  ll ans = 1;
  vrep(i, slope) {
    ll a = i.first.first, b = i.first.second, kind1 = i.second, kind2 = 0;
    if (a == 0 && slope.count(make_pair(1, 0))) {
      kind2 = slope[make_pair(1, 0)];
      slope.erase(make_pair(1, 0));
    } else if (b == 0 && slope.count(make_pair(0, 1))) {
      kind2 = slope[make_pair(0, 1)];
      slope.erase(make_pair(0, 1));
    } else if (slope.count(make_pair(((a < 0) - (a > 0)) * b, abs(a)))) {
      kind2 = slope[make_pair(((a < 0) - (a > 0)) * b, abs(a))];
      slope.erase(make_pair(((a < 0) - (a > 0)) * b, abs(a)));
    }
    // cout << (modpow(2, kind1) + modpow(2, kind2) - 1) << endl;
    ans = ans * (modpow(2, kind1) + modpow(2, kind2) - 1) % mod;
  }
  ans = ans + all0 - 1;
  cout << ans << endl;
}