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

#include <algorithm>
#include <cmath>
#include <iostream>
#include <set>
#include <vector>
using namespace std;

typedef pair<long long, long long> pairll;

const int MOD = 1000000007;
vector<long long> Power2;

void initPower2(int expmax) {
  long long power2buf = 1;
  for (int i = 0; i < expmax; i++) {
    Power2.push_back(power2buf);
    power2buf *= 2;
    power2buf %= MOD;
  }
}

long long GCD(long long former, long long latter) {
  if (former % latter == 0)
    return latter;
  if (latter % former == 0)
    return former;
  return GCD(latter, former % latter);
}

pairll WhoItHates(pairll anchovy) {
  if (anchovy.second > 0)
    return pairll(anchovy.second, -anchovy.first);
  if (anchovy.second < 0)
    return pairll(-anchovy.second, anchovy.first);
  return pairll(0, 1);
}

int main(void) {

  int N;
  long long Abuf, Bbuf;
  vector<pairll> Sociability;
  vector<int> Hatred;
  vector<int> Friendship;
  int Gloomy = 0;
  initPower2(200001);

  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> Abuf >> Bbuf;
    if ((Abuf != 0LL) || (Bbuf != 0LL)) {
      if (Abuf < 0) {
        Abuf = -Abuf;
        Bbuf = -Bbuf;
      }
      if (Abuf == 0LL) {
        Sociability.push_back(pairll(0LL, 1LL));
      } else if (Bbuf == 0LL) {
        Sociability.push_back(pairll(1LL, 0LL));
      } else {
        long long gcdAB = GCD(abs(Abuf), abs(Bbuf));
        Sociability.push_back(pairll(Abuf / gcdAB, Bbuf / gcdAB));
      }
    } else {
      Gloomy++;
    }
  }

  sort(Sociability.begin(), Sociability.end());
  set<pairll> setSociability;

  for (size_t i = 0; i < Sociability.size(); i++) {
    pairll Hated = WhoItHates(Sociability[i]);
    if (setSociability.find(Sociability[i]) != setSociability.end())
      continue;
    setSociability.insert(Sociability[i]);
    setSociability.insert(Hated);
    int Hbuf = upper_bound(Sociability.begin(), Sociability.end(), Hated) -
               lower_bound(Sociability.begin(), Sociability.end(), Hated);
    Hatred.push_back(Hbuf);
    int Fbuf =
        upper_bound(Sociability.begin(), Sociability.end(), Sociability[i]) -
        lower_bound(Sociability.begin(), Sociability.end(), Sociability[i]);
    Friendship.push_back(Fbuf);
  }
  long long res = 1;
  for (size_t i = 0; i < Friendship.size(); i++) {
    long long casebuf = Power2[Hatred[i]] + Power2[Friendship[i]] - 1;
    casebuf %= MOD;
    res *= casebuf;
    res %= MOD;
  }

  cout << ((res + Gloomy) % MOD + MOD - 1) % MOD << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <set>
#include <vector>
using namespace std;

typedef pair<long long, long long> pairll;

const int MOD = 1000000007;
vector<long long> Power2;

void initPower2(int expmax) {
  long long power2buf = 1;
  for (int i = 0; i < expmax; i++) {
    Power2.push_back(power2buf);
    power2buf *= 2;
    power2buf %= MOD;
  }
}

long long GCD(long long former, long long latter) {
  if (former % latter == 0)
    return latter;
  if (latter % former == 0)
    return former;
  return GCD(latter, former % latter);
}

int main(void) {

  int N;
  long long Abuf, Bbuf;
  vector<pairll> Sociability;
  vector<int> Hatred;
  vector<int> Friendship;
  int Gloomy = 0;
  initPower2(200001);

  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> Abuf >> Bbuf;
    if ((Abuf != 0LL) || (Bbuf != 0LL)) {
      if (Abuf < 0) {
        Abuf = -Abuf;
        Bbuf = -Bbuf;
      }
      long long gcdAB = GCD(abs(Abuf), abs(Bbuf));
      Sociability.push_back(pairll(Abuf / gcdAB, Bbuf / gcdAB));
    } else {
      Gloomy++;
    }
  }

  sort(Sociability.begin(), Sociability.end());

  for (int i = 0; i < Sociability.size(); i++) {
    pairll Hated = (Sociability[i].second >= 0
                        ? pairll(Sociability[i].second, -Sociability[i].first)
                        : pairll(-Sociability[i].second, Sociability[i].first));
    int Hbuf = upper_bound(Sociability.begin(), Sociability.end(), Hated) -
               lower_bound(Sociability.begin(), Sociability.end(), Hated);
    Hatred.push_back(Hbuf);
    int Fbuf =
        upper_bound(Sociability.begin(), Sociability.end(), Sociability[i]) -
        lower_bound(Sociability.begin(), Sociability.end(), Sociability[i]);
    Friendship.push_back(Fbuf);
  }

  set<pairll> setSociability;
  long long res = 1;
  for (int i = 0; i < Sociability.size(); i++) {
    if (setSociability.find(Sociability[i]) != setSociability.end())
      continue;
    pairll Hated = (Sociability[i].second >= 0
                        ? pairll(Sociability[i].second, -Sociability[i].first)
                        : pairll(-Sociability[i].second, Sociability[i].first));
    if (setSociability.find(Hated) != setSociability.end())
      continue;
    setSociability.insert(Sociability[i]);
    long long casebuf = Power2[Hatred[i]] + Power2[Friendship[i]] - 1;
    casebuf %= MOD;
    res *= casebuf;
    res %= MOD;
  }

  cout << res + Gloomy - 1 << endl;

  return 0;
}