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

#include <iostream>
using namespace std;
#define ll long long int
#define modm 1000000007
#include <algorithm>
#include <map>
#include <vector>

ll pow(ll a, ll b) {

  if (b == 0)
    return 1;

  ll c = pow(a, b / 2);
  c = (c * c) % modm;

  if (b % 2 == 1) {

    c = (c * a) % modm;
  }

  return c;
}

ll gdc(ll a, ll b) {

  if (a == 0)
    return b;
  return gdc(b % a, a);
}
pair<ll, ll> fract(ll a, ll b) {

  ll d = 1;
  if ((a < 0 && b > 0) || (a > 0 && b < 0)) {
    d = -1;
  }
  a = abs(a);
  b = abs(b);

  ll c = gdc(a, b);

  return make_pair(d * (a / c), b / c);
}
int main() {

  ll n;
  cin >> n;
  map<pair<ll, ll>, ll> count;
  ll zer = 0;

  for (ll i = 0; i < n; i++) {

    ll a, b;
    cin >> a >> b;

    if (a == 0 && b == 0) {

      zer = (zer + 1) % modm;
      continue;
    }

    pair<ll, ll> inp = fract(a, b);

    count[inp]++;
  }

  ll ans = 1;
  for (auto brr : count) {

    pair<ll, ll> arr, i;
    i = brr.first;

    if (i.first == 0 && i.second != 0) {

      arr = make_pair(1, 0);
    } else if (i.second == 0 && i.first != 0)
      arr = make_pair(0, 1);
    else {

      ll sig = 1;
      if (i.first < 0)
        sig = -1;

      arr = make_pair(-1 * sig * abs(i.second), abs(i.first));
    }

    ll cnt =
        (((pow(2, brr.second)) % modm + (pow(2, count[arr])) % modm) % modm -
         1 + modm) %
        modm;

    ans = (ans * cnt) % modm;

    if (count.find(arr) != count.end())
      count.erase(arr);
    count.erase(i);
  }
  ans = (ans + (zer) % modm) % modm;
  ans = (ans + modm - 1) % modm;
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;
#define ll long long int
#define modm 1000000007
#include <algorithm>
#include <map>
#include <vector>

ll pow(ll a, ll b) {

  if (b == 0)
    return 1;

  ll c = pow(a, b / 2);
  c = (c * c) % modm;

  if (b % 2 == 1) {

    c = (c * a) % modm;
  }

  return c;
}

ll gdc(ll a, ll b) {

  if (a == 0)
    return b;
  return gdc(b % a, a);
}
pair<ll, ll> fract(ll a, ll b) {

  // a/b

  ll d = 1;
  if (a * b < 0) {
    d = -1;
  }
  a = abs(a);
  b = abs(b);

  ll c = gdc(a, b);

  return make_pair(d * a / c, b / c);
}
int main() {

  ll n;
  cin >> n;
  map<pair<ll, ll>, ll> count;

  for (ll i = 0; i < n; i++) {

    ll a, b;
    cin >> a >> b;

    pair<ll, ll> inp = fract(a, b);

    count[inp]++;
  }

  ll ans = 1;
  for (auto brr : count) {

    pair<ll, ll> arr, i;
    i = brr.first;
    if (i.first == 0 && i.second != 0) {

      arr = make_pair(1, 0);
    } else if (i.second == 0 && i.first != 0)
      arr = make_pair(0, 1);
    else {

      ll sig = 1;
      if (i.first < 0)
        sig = -1;

      arr = make_pair(-1 * sig * abs(i.second), abs(i.first));
    }

    if (i.first == 0 && i.second == 0) {

      continue;
    }
    ll cnt =
        (((pow(2, brr.second)) % modm + (pow(2, count[arr])) % modm) % modm -
         1 + modm) %
        modm;

    ans = (ans * cnt) % modm;

    if (count.find(arr) != count.end())
      count.erase(arr);
  }
  ans = (ans + (count[make_pair(0, 0)]) % modm) % modm;
  ans = (ans + modm - 1) % modm;
  cout << ans << endl;
}