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

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

using ll = long long;
using pll = pair<ll, ll>;

template <typename T> T gcd(T a, T b) {
  if (b == 0)
    return abs(a);
  T r;
  while ((r = a % b) != 0)
    a = b, b = r;
  return abs(b);
}

ll modpow(ll b, ll x, ll mod) {
  if (x == 0)
    return 1;
  if (x & 1) {
    return modpow(b * b % mod, x / 2, mod) * b % mod;
  } else {
    return modpow(b * b % mod, x / 2, mod);
  }
}

#define MOD 1000000007

#define D1(a) cerr << #a << ":" << a << endl
#define D2(a, b) cerr << #a << ":" << a << "," << #b << ":" << b << endl
#define D3(a, b, c)                                                            \\
  cerr << #a << ":" << a << "," << #b << ":" << b << "," << #c << ":" << c     \\
       << endl
#define D4(a, b, c, d)                                                         \\
  cerr << #a << ":" << a << "," << #b << ":" << b << "," << #c << ":" << c     \\
       << "," << #d << ":" << d << endl
#define DH(c)                                                                  \\
  do {                                                                         \\
    rep(__i, c.size()) cerr << c[__i] << (__i == c.size() - 1 ? '\\n' : ' ');   \\
  } while (0)

// ifstream ifs("sub1_17.txt");
// #define cin ifs

int main() {
  int N;
  cin >> N;
  vector<pll> AB(N);
  map<pll, int> cnt;
  for (auto &ab : AB) {
    cin >> ab.first >> ab.second;
    if (ab.first == 0 && ab.second == 0) {
      // そのまま
    } else if (ab.first == 0) {
      ab.second = -1;
    } else if (ab.second == 0) {
      ab.first = 1;
    } else {
      ll g = gcd(ab.first, ab.second);
      ab.first /= g;
      ab.second /= g;
      if (ab.first < 0) {
        ab.first = -ab.first;
        ab.second = -ab.second;
      }
    }
    cnt[ab]++;
  }

  ll ans = 1;

  map<pll, bool> done;

  for (const auto &kv : cnt) {
    const auto &ab = kv.first;
    const auto &c = kv.second;
    if (done[ab] || (ab.first == 0 && ab.second == 0))
      continue;

    ll a = 1;
    pll abr = make_pair(abs(ab.second), ab.first);
    if (ab.second >= 0)
      abr.second = -abr.second;
    if (cnt.count(abr) > 0) {
      ll c_abr = cnt[abr];
      a = (modpow(2, c, MOD) + modpow(2, c_abr, MOD) - 1) % MOD;
      done[abr] = true;
    } else {
      a = modpow(2, c, MOD);
    }
    ans = ans * a % MOD;
    done[ab] = true;
  }
  ans--;
  ans = (ans + cnt[make_pair(0LL, 0LL)]) % MOD;
  if (ans < 0)
    ans += MOD;

  cout << ans << endl;
}

Error: 0

Fixed submission:

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

using ll = long long;
using pll = pair<ll, ll>;

template <typename T> T gcd(T a, T b) {
  if (b == 0)
    return abs(a);
  T r;
  while ((r = a % b) != 0)
    a = b, b = r;
  return abs(b);
}

ll modpow(ll b, ll x, ll mod) {
  if (x == 0)
    return 1;
  if (x & 1) {
    return modpow(b * b % mod, x / 2, mod) * b % mod;
  } else {
    return modpow(b * b % mod, x / 2, mod);
  }
}

#define MOD 1000000007
#define D1(a) cerr << #a << ":" << a << endl
#define D2(a, b) cerr << #a << ":" << a << "," << #b << ":" << b << endl
#define D3(a, b, c)                                                            \\
  cerr << #a << ":" << a << "," << #b << ":" << b << "," << #c << ":" << c     \\
       << endl
#define D4(a, b, c, d)                                                         \\
  cerr << #a << ":" << a << "," << #b << ":" << b << "," << #c << ":" << c     \\
       << "," << #d << ":" << d << endl
#define DH(c)                                                                  \\
  do {                                                                         \\
    rep(__i, c.size()) cerr << c[__i] << (__i == c.size() - 1 ? '\\n' : ' ');   \\
  } while (0)

int main() {
  int N;
  cin >> N;
  vector<pll> AB(N);
  map<pll, int> cnt;
  for (auto &ab : AB) {
    cin >> ab.first >> ab.second;
    ll g = gcd(ab.first, ab.second);
    ab.first /= g;
    ab.second /= g;
    if (ab.first < 0) {
      ab.first = -ab.first;
      ab.second = -ab.second;
    }
    cnt[ab]++;
  }

  ll ans = 1;

  map<pll, bool> done;

  for (const auto &kv : cnt) {
    const auto &ab = kv.first;
    const auto &c = kv.second;
    if (done[ab])
      continue;

    ll a = 1;
    pll abr = make_pair(abs(ab.second), ab.first);
    if (ab.second > 0)
      abr.second = -abr.second;
    if (cnt.count(abr) > 0) {
      a = (modpow(2, c, MOD) + modpow(2, cnt[abr], MOD) - 1) % MOD;
      done[abr] = true;
    } else {
      a = modpow(2, c, MOD);
    }
    ans = ans * a % MOD;
    done[ab] = true;
  }
  if (ans != 1)
    ans--;

  cout << ans << endl;
}