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

#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <tuple>
#include <vector>
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define CST(x) cout << fixed << setprecision(x) // 小数点以下の桁数指定
#define ct(a) cout << a << endl
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 7;
const ll mod = 1e9 + 7;

ll N, ans = 1;
ll A[200001], B[200001];
map<pair<ll, ll>, ll> mp1;
map<pair<ll, ll>, ll> mp2;

ll mod_pow(ll x, ll n) {
  if (n == 0)
    return 1;
  ll res = mod_pow(x * x % mod, n / 2);
  if (n & 1)
    res = res * x % mod;
  return (res + mod) % mod;
}

ll Gcd(ll x, ll y) {
  if (y > x)
    swap(x, y);
  while (x % y != 0) {
    ll m = x % y;
    x = y;
    y = m;
  }
  return y;
}

ll cnt;
ll mz, az;

int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);

  cin >> N;
  FOR(i, 0, N) {
    ll a, b;
    cin >> a >> b;

    if (a == 0 && b == 0)
      cnt++;
    else if (a == 0)
      mz++;
    else if (b == 0)
      az++;
    else {
      ll m = Gcd(a, b);
      a /= m;
      b /= m;
      A[i] = a;
      B[i] = b;
      mp1[make_pair(a, b)]++;
      mp2[make_pair(b, a)]++;
    }
  }
  FOR(i, 0, N) {
    ll a, b;
    a = A[i];
    b = B[i];

    if (a == 0 || b == 0)
      continue;

    if (mp1[make_pair(a, b)] > 0) {

      ans =
          (ans * ((mod_pow(2, mp1[make_pair(a, b)] + mp1[make_pair(-a, -b)]) +
                   mod_pow(2, mp2[make_pair(-a, b)] + mp2[make_pair(a, -b)])) %
                      mod -
                  1) +
           mod) %
          mod;
      mp1[make_pair(a, b)] = -1;
      mp1[make_pair(-a, -b)] = -1;
      mp1[make_pair(-b, a)] = -1;
      mp1[make_pair(b, -a)] = -1;
    }
  }
  ans = (ans * ((mod_pow(2, mz) + mod_pow(2, az)) % mod - 1) + mod) % mod;

  cout << (ans - 1 + cnt + 100 * mod) % mod << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <tuple>
#include <vector>
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define CST(x) cout << fixed << setprecision(x) // 小数点以下の桁数指定
#define ct(a) cout << a << endl
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 7;
const ll mod = 1e9 + 7;

ll N, ans = 1;
ll A[200001], B[200001];
map<pair<ll, ll>, ll> mp1;
map<pair<ll, ll>, ll> mp2;

ll mod_pow(ll x, ll n) {
  if (n == 0)
    return 1;
  ll res = mod_pow(x * x % mod, n / 2);
  if (n & 1)
    res = res * x % mod;
  return (res + mod) % mod;
}

ll Gcd(ll x, ll y) {
  if (y > x)
    swap(x, y);
  while (x % y != 0) {
    ll m = x % y;
    x = y;
    y = m;
  }
  return y;
}

ll cnt;
ll mz, az;

int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);

  cin >> N;
  FOR(i, 0, N) {
    ll a, b;
    cin >> a >> b;

    ll m = Gcd(a, b);
    a /= m;
    b /= m;

    A[i] = a;
    B[i] = b;
    if (a == 0 && b == 0)
      cnt++;
    else if (a == 0)
      mz++;
    else if (b == 0)
      az++;
    else {
      mp1[make_pair(a, b)]++;
      mp2[make_pair(b, a)]++;
    }
  }
  FOR(i, 0, N) {
    ll a, b;
    a = A[i];
    b = B[i];

    if (a == 0 || b == 0)
      continue;

    if (mp1[make_pair(a, b)] > 0) {

      ans =
          (ans * ((mod_pow(2, mp1[make_pair(a, b)] + mp1[make_pair(-a, -b)]) +
                   mod_pow(2, mp2[make_pair(-a, b)] + mp2[make_pair(a, -b)])) %
                      mod -
                  1) +
           mod) %
          mod;
      mp1[make_pair(a, b)] = -1;
      mp1[make_pair(-a, -b)] = -1;
      mp1[make_pair(-b, a)] = -1;
      mp1[make_pair(b, -a)] = -1;
    }
  }
  ans = (ans * ((mod_pow(2, mz) + mod_pow(2, az)) % mod - 1) + mod) % mod;

  cout << (ans - 1 + cnt + 100 * mod) % mod << endl;

  return 0;
}