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

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define mod 1000000007
#define MOD 998244353
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
pair<int, int> solve(pair<int, int> p) {
  int a = p.first, b = p.second;
  if (b > 0) {
    return make_pair(b, -a);
  }
  return make_pair(-b, a);
}
int mod_pow(int x, int n, int mm) {
  int res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * x % mm;
    x = x * x % mm;
    n >>= 1;
  }
  return res;
}
signed main() {
  int N;
  cin >> N;
  map<pair<int, int>, int> M;
  int count = 0; //(a,b)=(0,0)の個数
  rep(i, N) {
    int a, b;
    cin >> a >> b;
    if (a == 0 && b == 0) {
      count++;
      continue;
    }
    int g = abs(gcd(a, b));
    a /= g;
    b /= g;
    if (a == 0)
      b = abs(b);
    if (a < 0) {
      a = -a;
      b = -b;
    }
    M[make_pair(a, b)]++;
  }
  int ans = 1;
  for (auto x : M) {
    pair<int, int> p = x.first;
    int n = x.second;
    if (n == 0)
      continue;
    int m = M[solve(p)];
    // cout << p.first << ':' << p.second << ' ' << n << ' ' << m << endl;
    int s = mod_pow(2, n, mod);
    if (m > 0) {
      s += mod_pow(2, m, mod);
      s -= 1;
    }
    ans = (ans * s) % mod;
    M[p] = 0;
    M[solve(p)] = 0;
  }
  cout << (ans + count + mod - 1) % mod << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define mod 1000000007
#define MOD 998244353
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
pair<int, int> solve(pair<int, int> p) {
  int a = p.first, b = p.second;
  if (b > 0) {
    return make_pair(b, -a);
  }
  return make_pair(-b, a);
}
int mod_pow(int x, int n, int mm) {
  int res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * x % mm;
    x = x * x % mm;
    n >>= 1;
  }
  return res;
}
signed main() {
  int N;
  cin >> N;
  map<pair<int, int>, int> M;
  rep(i, N) {
    int a, b;
    cin >> a >> b;
    int g = abs(gcd(a, b));
    a /= g;
    b /= g;
    if (a == 0)
      b = abs(b);
    if (a < 0) {
      a = -a;
      b = -b;
    }
    M[make_pair(a, b)]++;
  }
  int ans = 1;
  for (auto x : M) {
    pair<int, int> p = x.first;
    int n = x.second;
    if (n == 0)
      continue;
    int m = M[solve(p)];
    // cout << p.first << ':' << p.second << ' ' << n << ' ' << m << endl;
    int s = mod_pow(2, n, mod);
    if (m > 0) {
      s += mod_pow(2, m, mod);
      s -= 1;
    }
    ans = (ans * s) % mod;
    M[p] = 0;
    M[solve(p)] = 0;
  }
  cout << (ans + mod - 1) % mod << endl;
}