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

#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, l, r) for (int i = (l), i##_len = (r); i < i##_len; ++i)
#define all(x) begin(x), end(x)
using namespace std;
typedef long long ll;
const ll INF = 1e9;
template <class T = ll> using V = vector<T>;
template <class T = ll> using PQ = priority_queue<T>;
template <class T = ll> using PQG = priority_queue<T, V<T>, greater<T>>;
const ll MOD = 1000000007LL;
void in() {}
template <class Head, class... Tail> void in(Head &&head, Tail &&...tail) {
  cin >> head;
  in(move(tail)...);
}
#define IN(...)                                                                \\
  ll __VA_ARGS__;                                                              \\
  in(__VA_ARGS__)
#define INS(T, ...)                                                            \\
  T __VA_ARGS__;                                                               \\
  in(__VA_ARGS__)
#define VIN(T, v, n)                                                           \\
  V<T> v(n);                                                                   \\
  for (auto &_elem : v)                                                        \\
  cin >> _elem
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#define YN(e) cout << ((e) ? "YES" : "NO") << endl
#define yn(e) cout << ((e) ? "Yes" : "No") << endl
#pragma endregion RegionDefs

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

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

ll get(map<pair<ll, ll>, ll> &m, ll a, ll b) {
  auto p = make_pair(a, b);
  if (m.find(p) == m.end())
    return 0;
  ll c = m[p];
  m[p] = 0;
  return c;
}

void solve() {
  IN(n);
  map<pair<ll, ll>, ll> m;
  ll temp = 0;
  rep(i, n) {
    IN(a, b);
    if (a == 0 || b == 0) {
      if (a != 0) {
        m[make_pair(1, 0)] += 1;
        continue;
      } else if (b != 0) {
        m[make_pair(0, 1)] += 1;
        continue;
      }
      temp++;
      continue;
    }
    ll g = gcd(a, b);
    m[make_pair(a / g, b / g)] += 1;
  }
  vector<pair<ll, ll>> keys;
  for (auto &&t : m) {
    keys.emplace_back(t.first.first, t.first.second);
  }
  vector<pair<ll, ll>> v;
  rep(j, keys.size()) {
    auto &t = m[keys[j]];
    if (t == 0)
      continue;
    ll n1 = get(m, keys[j].second, -keys[j].first);
    ll n2 = get(m, -keys[j].second, keys[j].first);
    v.emplace_back(t, n1 + n2);
  }
  ll s = 1;
  rep(i, v.size()) {
    if (v[i].second == 0) {
      s = (s * modpow(2, v[i].first, MOD)) % MOD;
    } else {
      s = (s * ((modpow(2, v[i].first, MOD) + modpow(2, v[i].second, MOD) +
                 MOD - 1) %
                MOD)) %
          MOD;
    }
  }
  cout << (s + MOD + temp - 1) % MOD << endl;
}

int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(numeric_limits<double>::max_digits10);

  solve();

  return 0;
}

Error: 0

Fixed submission:

#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, l, r) for (int i = (l), i##_len = (r); i < i##_len; ++i)
#define all(x) begin(x), end(x)
using namespace std;
typedef long long ll;
const ll INF = 1e9;
template <class T = ll> using V = vector<T>;
template <class T = ll> using PQ = priority_queue<T>;
template <class T = ll> using PQG = priority_queue<T, V<T>, greater<T>>;
const ll MOD = 1000000007LL;
void in() {}
template <class Head, class... Tail> void in(Head &&head, Tail &&...tail) {
  cin >> head;
  in(move(tail)...);
}
#define IN(...)                                                                \\
  ll __VA_ARGS__;                                                              \\
  in(__VA_ARGS__)
#define INS(T, ...)                                                            \\
  T __VA_ARGS__;                                                               \\
  in(__VA_ARGS__)
#define VIN(T, v, n)                                                           \\
  V<T> v(n);                                                                   \\
  for (auto &_elem : v)                                                        \\
  cin >> _elem
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#define YN(e) cout << ((e) ? "YES" : "NO") << endl
#define yn(e) cout << ((e) ? "Yes" : "No") << endl
#pragma endregion RegionDefs

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

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

ll get(map<pair<ll, ll>, ll> &m, ll a, ll b) {
  auto p = make_pair(a, b);
  if (m.find(p) == m.end())
    return 0;
  ll c = m[p];
  m[p] = 0;
  return c;
}

void solve() {
  IN(n);
  map<pair<ll, ll>, ll> m;
  rep(i, n) {
    IN(a, b);
    ll g = gcd(a, b);
    m[make_pair(a / g, b / g)] += 1;
  }
  vector<pair<ll, ll>> keys;
  for (auto &&t : m) {
    keys.push_back(t.first);
  }
  vector<pair<ll, ll>> v;
  rep(j, keys.size()) {
    auto &t = m[keys[j]];
    if (t == 0)
      continue;
    ll n1 = get(m, keys[j].second, -keys[j].first);
    ll n2 = get(m, -keys[j].second, keys[j].first);
    v.emplace_back(t, n1 + n2);
  }
  ll s = 1;
  rep(i, v.size()) {
    if (v[i].second == 0) {
      s = (s * modpow(2, v[i].first, MOD)) % MOD;
    } else {
      s = (s * ((modpow(2, v[i].first, MOD) + modpow(2, v[i].second, MOD) +
                 MOD - 1) %
                MOD)) %
          MOD;
    }
  }
  cout << (s + MOD - 1) % MOD << endl;
}

int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(numeric_limits<double>::max_digits10);

  solve();

  return 0;
}