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

#include <bits/stdc++.h>
#define MOD 1000000007
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define pii pair<long long, long long>
using namespace std;

int N;
map<pii, long long> slope;
set<pii> vis;
long long cntzer1, cntzer2;

long long GCD(long long A, long long B) { return B == 0 ? A : GCD(B, A % B); }

long long POW(long long X, long long Y) {
  long long res = 1;
  while (Y) {
    if (Y & 1)
      res = res * X % MOD;
    X = X * X % MOD;
    Y >>= 1;
  }
  return res;
}

void frac(long long A, long long B) {
  long long gcd = GCD(ABS(A), ABS(B));
  slope[make_pair(A / gcd, B / gcd)]++;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin >> N;
  long long tam = 0;
  long long A, B;
  for (int i = 1; i <= N; i++) {
    cin >> A >> B;
    if ((A == 0) && (B == 0))
      tam++;
    else if (A == 0) {
      cntzer1++;
    } else if (B == 0) {
      cntzer2++;
    } else
      frac(A, B);
  }
  long long ans = 1;
  while (!slope.empty()) {
    long long x = slope.begin()->first.first, y = slope.begin()->first.second;
    long long val1 = 0, val2 = 0;
    val1 += slope.begin()->second;
    slope.erase(slope.begin());
    if (slope.count(make_pair(y, -x))) {
      val2 += slope[make_pair(y, -x)];
      slope.erase(make_pair(y, -x));
    }
    if (slope.count(make_pair(-y, x))) {
      val2 += slope[make_pair(-y, x)];
      slope.erase(make_pair(-y, x));
    }
    if (slope.count(make_pair(-x, -y))) {
      val1 += slope[make_pair(-x, -y)];
      slope.erase(make_pair(-x, -y));
    }
    ans = ans * (POW(2, val1) + POW(2, val2) - 1 + MOD) % MOD;
  }
  ans = ans * (POW(2, cntzer1) + POW(2, cntzer2) - 1 + MOD) % MOD;
  cout << (ans - 1 + tam + MOD) % MOD << "\\n";
}

Error: 127
/tmp/51de57e6-dbb7-4b14-8079-dcd6ef36fe51.out: error while loading shared libraries: libc.so.6: failed to map segment from shared object


Fixed submission:

#include <bits/stdc++.h>
#define MOD 1000000007
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define pii pair<long long, long long>
using namespace std;

int N;
map<pii, int> slope;
set<pii> vis;
int memo[5005][5005];

long long GCD(long long A, long long B) { return B == 0 ? A : GCD(B, A % B); }

long long POW(long long X, long long Y) {
  long long res = 1;
  while (Y) {
    if (Y & 1)
      res = res * X % MOD;
    X = X * X % MOD;
    Y >>= 1;
  }
  return res;
}

void frac(long long A, long long B) {
  long long gcd = GCD(ABS(A), ABS(B));
  slope[make_pair(A / gcd, B / gcd)]++;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin >> N;
  long long A, B;
  for (int i = 1; i <= N; i++) {
    cin >> A >> B;
    frac(A, B);
  }
  long long ans = 1;
  while (!slope.empty()) {
    long long x = slope.begin()->first.first, y = slope.begin()->first.second;
    long long val1 = 0, val2 = 0;
    val1 += slope.begin()->second;
    slope.erase(slope.begin());
    if (slope.count(make_pair(y, -x))) {
      val2 += slope[make_pair(y, -x)];
      slope.erase(make_pair(y, -x));
    }
    if (slope.count(make_pair(-y, x))) {
      val2 += slope[make_pair(-y, x)];
      slope.erase(make_pair(-y, x));
    }
    if (slope.count(make_pair(-x, -y))) {
      val1 += slope[make_pair(-x, -y)];
      slope.erase(make_pair(-x, -y));
    }
    ans = ans * (POW(2, val1) + POW(2, val2) - 1) % MOD;
  }
  cout << ans - 1 << "\\n";
}