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

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()

#define READ(x) (cin >> (x))

#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))

#define DIVIDER 1000000007

ll gcd(ll a, ll b) {
  a = abs(a);
  b = abs(b);

  if (a < b) {
    return gcd(b, a);
  }
  ll r = a % b;

  if (r != 0) {
    return gcd(b, r);
  } else {
    return b;
  }
}

// string show_ratio(ll a, ll b) {
//   return to_string(a) + "/" + to_string(b);
// }

ll binary_power_divided(ll x, ll y, ll divider) {
  if (x == 1) {
    return 1;
  }

  ll retv = 1;
  ll x_pow_2i = x;
  ll temp_y = y;

  while (temp_y > 0) {
    if (temp_y % 2 == 1) {
      retv = (retv * x_pow_2i) % divider;
    }
    x_pow_2i = (x_pow_2i * x_pow_2i) % divider;
    temp_y /= 2;
  }

  return retv;
}

int main() {
  // get values from input
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N;
  cin >> N;

  vector<ll> A(N), B(N);
  for (auto i = 0; i < N; ++i) {
    cin >> A[i] >> B[i];
  }

  // main procedure
  map<pair<ll, ll>, pair<ll, ll>> ratio_num;
  ll zero_count = 0;

  for (auto i = 0; i < N; ++i) {
    if (A[i] == 0 || B[i] == 0) {
      if ((A[i] == 0 && B[i] == 0)) {
        zero_count++;
      } else {
        if (ratio_num.count(make_pair(0, 1)) == 0) {
          ratio_num[make_pair(0, 1)] = make_pair(0, 0);
        }

        if (A[i] == 0) {
          ratio_num[make_pair(0, 1)].first++;
        } else {
          ratio_num[make_pair(0, 1)].second++;
        }
      }
      continue;
    }

    ll g = gcd(A[i], B[i]);

    ll a_r = A[i] / g;
    ll b_r = B[i] / g;

    if ((a_r > 0 && b_r > 0) || (a_r < 0 && b_r < 0)) {
      if (ratio_num.count(make_pair(abs(a_r), abs(b_r))) == 0) {
        ratio_num[make_pair(abs(a_r), abs(b_r))] = make_pair(0, 0);
      }
      ratio_num[make_pair(abs(a_r), abs(b_r))].first++;
    } else {
      if (ratio_num.count(make_pair(abs(b_r), abs(a_r))) == 0) {
        ratio_num[make_pair(abs(b_r), abs(a_r))] = make_pair(0, 0);
      }
      ratio_num[make_pair(abs(b_r), abs(a_r))].second++;
    }
  }

  ll ans = 1;

  for (const auto &[k, p] : ratio_num) {
    // cout << "(" << k.first << ", " << k.second << ")" << ": (" << p.first <<
    // ", " << p.second << ")" << endl;
    ans = (ans * ((1 + (binary_power_divided(2, p.first, DIVIDER) - 1) +
                   (binary_power_divided(2, p.second, DIVIDER) - 1)) %
                  DIVIDER)) %
          DIVIDER;
  }

  ans = (ans + DIVIDER + zero_count - 1) % DIVIDER;

  // output
  WRITE_N(ans);

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()

#define READ(x) (cin >> (x))

#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))

#define DIVIDER 1000000007

ll gcd(ll a, ll b) {
  a = abs(a);
  b = abs(b);

  if (a < b) {
    return gcd(b, a);
  }
  ll r = a % b;

  if (r != 0) {
    return gcd(b, r);
  } else {
    return b;
  }
}

// string show_ratio(ll a, ll b) {
//   return to_string(a) + "/" + to_string(b);
// }

ll binary_power_divided(ll x, ll y, ll divider) {
  if (x == 1) {
    return 1;
  }

  ll retv = 1;
  ll x_pow_2i = x;
  ll temp_y = y;

  while (temp_y > 0) {
    if (temp_y % 2 == 1) {
      retv = (retv * x_pow_2i) % divider;
    }
    x_pow_2i = (x_pow_2i * x_pow_2i) % divider;
    temp_y /= 2;
  }

  return retv;
}

int main() {
  // get values from input
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N;
  cin >> N;

  vector<ll> A(N), B(N);
  for (auto i = 0; i < N; ++i) {
    cin >> A[i] >> B[i];
  }

  // main procedure
  map<pair<ll, ll>, pair<ll, ll>> ratio_num;

  for (auto i = 0; i < N; ++i) {
    ll g = gcd(A[i], B[i]);
    if (g == 0) {
      if (A[i] != 0 || B[i] != 0) {
        if (ratio_num.count(make_pair(0, 1)) == 0) {
          ratio_num[make_pair(0, 1)] = make_pair(0, 0);
        }

        if (A[i] == 0) {
          ratio_num[make_pair(0, 1)].first++;
        } else {
          ratio_num[make_pair(0, 1)].second++;
        }
      }
      continue;
    }

    ll a_r = A[i] / g;
    ll b_r = B[i] / g;

    if ((a_r > 0 && b_r > 0) || (a_r < 0 && b_r < 0)) {
      if (ratio_num.count(make_pair(abs(a_r), abs(b_r))) == 0) {
        ratio_num[make_pair(abs(a_r), abs(b_r))] = make_pair(0, 0);
      }
      ratio_num[make_pair(abs(a_r), abs(b_r))].first++;
    } else {
      if (ratio_num.count(make_pair(abs(b_r), abs(a_r))) == 0) {
        ratio_num[make_pair(abs(b_r), abs(a_r))] = make_pair(0, 0);
      }
      ratio_num[make_pair(abs(b_r), abs(a_r))].second++;
    }
  }

  ll ans = 1;

  for (const auto &[k, p] : ratio_num) {
    // cout << "(" << k.first << ", " << k.second << ")" << ": (" << p.first <<
    // ", " << p.second << ")" << endl;
    ans = (ans * (1 + (binary_power_divided(2, p.first, DIVIDER) - 1) +
                  (binary_power_divided(2, p.second, DIVIDER) - 1))) %
          DIVIDER;
  }

  ans--;

  // output
  WRITE_N(ans);

  return 0;
}