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

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <utility>
#include <vector>

using namespace std;

#define int long long
#define INF (long long)1000000007

int gcd(int a, int b) {
  if (a == 0 && b == 0)
    return 1;
  if (a == 0)
    return b;
  if (b == 0)
    return a;
  if (a % b == 0)
    return b;
  return gcd(b, a % b);
}

void set_two_pow(vector<int> &v, int n) {
  v[0] = 1;
  for (int i = 1; i < n + 1; i++) {
    v[i] = v[i - 1] * 2;
    v[i] %= INF;
  }
}

signed main() {
  int N;
  cin >> N;

  vector<int> two_pow(N + 1, 0);
  set_two_pow(two_pow, N);

  map<pair<int, int>, pair<int, int>> m;
  m[pair<int, int>(0, 1)] = pair<int, int>(0, 0);
  int nO = 0;

  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;

    if (a == 0 && b == 0) {
      nO++;
      continue;
    } else if (a == 0) {
      m[pair<int, int>(0, 1)].first++;
      continue;
    } else if (b == 0) {
      m[pair<int, int>(0, 1)].second++;
      continue;
    }

    int d = gcd(abs(a), abs(b));
    a /= d;
    b /= d;

    if (a * b > 0) {
      pair<int, int> p;
      p.first = abs(a);
      p.second = abs(b);
      if (m.find(p) == m.end()) {
        m[p] = pair<int, int>(1, 0);
      } else {
        m[p].first++;
      }
    } else {
      pair<int, int> p;
      p.first = abs(b);
      p.second = abs(a);
      if (m.find(p) == m.end()) {
        m[p] = pair<int, int>(0, 1);
      } else {
        m[p].second++;
      }
    }
  }

  int ans = 1;

  for (const auto &[key, value] : m) {
    // cout << key.first << " " << key.second << " " << value.first << " " <<
    // value.second << endl;
    int tmp = two_pow[value.first] + two_pow[value.second] - 1;
    tmp %= INF;
    ans *= tmp;
    ans %= INF;
  }

  ans--;
  ans += nO;
  ans %= INF;
  ans = (ans + INF) % INF;

  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <utility>
#include <vector>

using namespace std;

#define int long long
#define INF 1000000007

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

void set_two_pow(vector<int> &v, int n) {
  v[0] = 1;
  for (int i = 1; i < n + 1; i++) {
    v[i] = v[i - 1] * 2;
    v[i] %= INF;
  }
}

signed main() {
  int N;
  cin >> N;

  vector<int> two_pow(N + 1, 0);
  set_two_pow(two_pow, N);

  map<pair<int, int>, pair<int, int>> m;
  int nO = 0;

  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    if (a == 0 && b == 0) {
      nO++;
      continue;
    }

    int d = gcd(abs(a), abs(b));
    a /= d;
    b /= d;

    if (a * b >= 0) {
      pair<int, int> p;
      p.first = a;
      p.second = b;
      if (m.find(p) == m.end()) {
        m[p] = pair<int, int>(1, 0);
      } else {
        m[p].first++;
      }
    } else {
      pair<int, int> p;
      p.first = abs(b);
      p.second = abs(a);
      if (m.find(p) == m.end()) {
        m[p] = pair<int, int>(0, 1);
      } else {
        m[p].second++;
      }
    }
  }

  int ans = 1;

  for (const auto &[key, value] : m) {
    // cout << key.first << " " << key.second << " " << value.first << " " <<
    // value.second << endl;
    int tmp = two_pow[value.first] + two_pow[value.second] - 1;
    tmp %= INF;
    ans *= tmp;
    ans %= INF;
  }

  ans--;
  ans += two_pow[nO] - 1;

  cout << ans << endl;
}