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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = (ll)1e9 + 7;
// const ll MOD=(ll)998244353;
const ll INF = (ll)1e18 + 10;
const double PI = 2.0 * acos(0);

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;
}
int dy[] = {-1, 1, 0, 0};
int dx[] = {0, 0, -1, 1};

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

// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

void solve(int ca) {
  int N;
  cin >> N;
  ll a, b, c;
  map<pair<ll, ll>, int> mp;
  int a0 = 0, b0 = 0;
  int ab0 = 0;
  for (int i = 0; i < N; ++i) {
    cin >> a >> b;
    if (a < 0 && b < 0) {
      a *= -1;
      b *= -1;
    }
    if (a == 0 && b == 0) {
      ab0++;
      continue;
    } else if (a == 0) {
      a0++;
      continue;
    } else if (b == 0) {
      b0++;
      continue;
    }
    c = gcd(abs(a), abs(b));
    a /= c;
    b /= c;
    mp[make_pair(a, b)]++;
  }
  vector<pair<ll, ll>> vec;
  vec.push_back(make_pair(a0, b0));
  for (auto i : mp) {
    auto val = i.first;
    if ((val.first > 0) ^ (val.second > 0)) {
      if (mp.find(make_pair(val.second, -val.first)) != mp.end() ||
          mp.find(make_pair(-val.second, val.first)) != mp.end())
        continue;
      vec.push_back(make_pair(i.second, 0));
      continue;
    }
    int tui = 0;
    tui += mp[make_pair(-val.second, val.first)];
    tui += mp[make_pair(val.second, -val.first)];
    vec.push_back(make_pair(i.second, tui));
  }

  ll ans = 1ll;

  for (auto i : vec) {
    // cout<<ans<<endl;
    if (i.second != 0) {
      (ans *=
       (modpow(2ll, i.first, MOD) + modpow(2ll, i.second, MOD) + MOD - 1) %
       MOD) %= MOD;
    } else {
      (ans *= modpow(2ll, i.first, MOD)) %= MOD;
    }
  }

  (ans += ab0 - 1 + MOD) %= MOD;

  cout << ans << endl;
}

// #define MULTI
int main() {
#ifdef MULTI
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    solve(i + 1);
  }
#else
  solve(0);
#endif
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = (ll)1e9 + 7;
// const ll MOD=(ll)998244353;
const ll INF = (ll)1e18 + 10;
const double PI = 2.0 * acos(0);

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;
}
int dy[] = {-1, 1, 0, 0};
int dx[] = {0, 0, -1, 1};

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

// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

void solve(int ca) {
  int N;
  cin >> N;
  ll a, b, c;
  map<pair<int, int>, int> mp;
  int a0 = 0, b0 = 0;
  int ab0 = 0;
  for (int i = 0; i < N; ++i) {
    cin >> a >> b;
    if (a < 0 && b < 0) {
      a *= -1;
      b *= -1;
    }
    if (a == 0 && b == 0)
      ab0++;
    else if (a == 0)
      a0++;
    else if (b == 0)
      b0++;
    c = gcd(abs(a), abs(b));
    a /= c;
    b /= c;
    mp[make_pair(a, b)]++;
  }
  vector<pair<int, int>> vec;
  vec.push_back(make_pair(a0, b0));
  for (auto i : mp) {
    auto val = i.first;
    if ((val.first > 0) ^ (val.second > 0)) {
      if (mp.find(make_pair(val.second, -val.first)) != mp.end() ||
          mp.find(make_pair(-val.second, val.first)) != mp.end())
        continue;
      vec.push_back(make_pair(i.second, 0));
      continue;
    }
    int tui = 0;
    tui += mp[make_pair(-val.second, val.first)];
    tui += mp[make_pair(val.second, -val.first)];
    vec.push_back(make_pair(i.second, tui));
  }

  ll ans = 1ll;

  for (auto i : vec) {
    // cout<<ans<<endl;
    if (i.second != 0) {
      (ans *= (modpow(2, i.first, MOD) + modpow(2, i.second, MOD) + MOD - 1) %
              MOD) %= MOD;
    } else {
      (ans *= modpow(2, i.first, MOD)) %= MOD;
    }
  }

  ans += ab0 - 1;

  cout << ans << endl;
}

// #define MULTI
int main() {
#ifdef MULTI
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    solve(i + 1);
  }
#else
  solve(0);
#endif
  return 0;
}