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

#include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
const int N = 200000 + 5, mod = 1e9 + 7;
long long A[N], B[N];
long long gcd(long long x, long long y) { return !y ? x : gcd(y, x % y); }
int n, pow2[N];
map<pair<long long, long long>, int> K;
int main() {
  scanf("%d", &n);
  pow2[0] = 1;
  for (int i = 1; i <= n; ++i)
    pow2[i] = 1LL * pow2[i - 1] * 2 % mod;
  for (int i = 1; i <= n; ++i) {
    scanf("%lld%lld", &A[i], &B[i]);
    if (B[i] < 0)
      A[i] *= -1, B[i] *= -1;
    if (!A[i] && !B[i])
      K[make_pair(0, 0)] += 1;
    else if (!A[i])
      K[make_pair(0, 1)] += 1;
    else if (!B[i])
      K[make_pair(1, 0)] += 1;
    else {
      long long t = gcd(A[i] > 0 ? A[i] : -A[i], B[i]);
      K[make_pair(A[i] /= t, B[i] /= t)] += 1;
    }
  }
  int ans = 1;
  for (int i = 1; i <= n; ++i) {
    if (!A[i] || !B[i])
      continue;
    long long t1 = K[make_pair(A[i], B[i])];
    long long t2 =
        K[make_pair(B[i] * (A[i] < 0 ? 1 : -1), A[i] * (A[i] < 0 ? -1 : 1))];
    if (!t1)
      continue;
    K[make_pair(A[i], B[i])] =
        K[make_pair(B[i] * (A[i] < 0 ? 1 : -1), A[i] * (A[i] < 0 ? -1 : 1))] =
            0;
    if (t1 && t2)
      ans = 1LL * ans * (pow2[t1] + pow2[t2] - (t1 && t2 ? 1 : 0)) % mod;
    else
      ans = 1LL * ans * pow2[t1] % mod;
  }
  ans = (ans - 1 + mod) % mod;
  if (K[make_pair(0, 1)] || K[make_pair(1, 0)])
    ans = 1LL * ans *
          (pow2[K[make_pair(0, 1)]] + pow2[K[make_pair(1, 0)]] -
           (K[make_pair(0, 1)] && K[make_pair(1, 0)] ? 1 : 0)) %
          mod;
  int ans2 = 0;
  if (K[make_pair(0, 0)] || K[make_pair(1, 0)] || K[make_pair(0, 1)]) {
    ans2 = 0;
    ans2 = (ans2 + K[make_pair(0, 0)]) % mod;
    ans2 = (ans2 + pow2[K[make_pair(1, 0)]] - 1) % mod;
    ans2 = (ans2 + pow2[K[make_pair(0, 1)]] - 1) % mod;
  }
  printf("%d\\n", (ans + ans2) % mod);
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
const int N = 100000 + 5, mod = 1e9 + 7;
long long A[N], B[N];
long long gcd(long long x, long long y) { return !y ? x : gcd(y, x % y); }
int n, pow2[N], sign[N];
map<pair<long long, long long>, int> K;
int main() {
  scanf("%d", &n);
  pow2[0] = 1;
  for (int i = 1; i <= n; ++i)
    pow2[i] = 1LL * pow2[i - 1] * 2 % mod;
  for (int i = 1; i <= n; ++i) {
    scanf("%lld%lld", &A[i], &B[i]);
    if (B[i] < 0)
      A[i] *= -1, B[i] *= -1;
    if (!A[i] && !B[i])
      K[make_pair(0, 0)] += 1;
    else if (!A[i])
      K[make_pair(0, 1)] += 1;
    else if (!B[i])
      K[make_pair(1, 0)] += 1;
    else {
      long long t = gcd(A[i] > 0 ? A[i] : -A[i], B[i]);
      if (!t)
        while (1)
          ;
      K[make_pair(A[i] /= t, B[i] /= t)] += 1;
    }
  }
  int ans = 1;
  for (int i = 1; i <= n; ++i) {
    if (!A[i] || !B[i])
      continue;
    long long t1 = K[make_pair(A[i], B[i])];
    long long t2 =
        K[make_pair(B[i] * (A[i] < 0 ? 1 : -1), A[i] * (A[i] < 0 ? -1 : 1))];
    if (!t1)
      continue;
    K[make_pair(A[i], B[i])] =
        K[make_pair(B[i] * (A[i] < 0 ? 1 : -1), A[i] * (A[i] < 0 ? -1 : 1))] =
            0;
    if (t1 && t2)
      ans = 1LL * ans * (pow2[t1] + pow2[t2] - (t1 && t2 ? 1 : 0)) % mod;
    else
      ans = 1LL * ans * pow2[t1] % mod;
  }
  ans = (ans - 1 + mod) % mod;
  if (K[make_pair(0, 1)] || K[make_pair(1, 0)])
    ans = 1LL * ans *
          (pow2[K[make_pair(0, 1)]] + pow2[K[make_pair(1, 0)]] -
           (K[make_pair(0, 1)] && K[make_pair(1, 0)] ? 1 : 0)) %
          mod;
  int ans2 = 0;
  if (K[make_pair(0, 0)] || K[make_pair(1, 0)] || K[make_pair(0, 1)]) {
    ans2 = 1;
    ans2 = (ans2 + pow2[K[make_pair(0, 0)]] - 1) % mod;
    ans2 = (ans2 + pow2[K[make_pair(1, 0)]] - 1) % mod;
    ans2 = (ans2 + pow2[K[make_pair(0, 1)]] - 1) % mod;
  }
  printf("%d\\n", (ans + ans2) % mod);
  return 0;
}