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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
// #define int long long
#define lint long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define ALL(x) x.begin(), x.end()
#define ll long long
typedef pair<lint, lint> P;
const lint inf = 1e18 + 7;
const int MOD = 1000000007;
struct Nums {
  long long n;
  vector<long long> kaijo;
  Nums(int N) {
    n = N;
    kaijo.push_back(1);
    for (long long i = 1; i <= n; i++) {
      kaijo.push_back((kaijo[i - 1] * i) % MOD);
    }
  }
  long myPow(long x, long n, long m) {
    if (n == 0)
      return 1;
    if (n % 2 == 0)
      return myPow(x * x % m, n / 2, m);
    else
      return x * myPow(x, n - 1, m) % m;
  }
  long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
      long long t = a / b;
      a -= t * b;
      swap(a, b);
      u -= t * v;
      swap(u, v);
    }
    u %= m;
    if (u < 0)
      u += m;
    return u;
  }
  long long comb(long long N, long long K, long long rest) {
    long long res = kaijo[N] * modinv(kaijo[K], rest) % rest;
    res *= modinv(kaijo[N - K], rest);
    res %= rest;
    return res;
  }
};

lint gcd(lint a, lint b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}
signed main() {
  lint n;
  cin >> n;
  vector<lint> a(n);
  vector<lint> b(n);
  map<P, lint> memo;
  Nums lib(n + 5);
  lint cnt0 = 0;
  lint a0 = 0;
  lint b0 = 0;
  rep(i, n) {
    cin >> a[i] >> b[i];
    if (a[i] == 0 && b[i] == 0) {
      cnt0++;
      continue;
    }
    if (a[i] == 0) {
      ++a0;
      continue;
    }
    if (b[i] == 0) {
      ++b0;
      continue;
    }
    lint ba = abs(a[i]);
    lint bb = abs(b[i]);
    lint g = gcd(ba, bb);
    if (a[i] < 0) {
      a[i] *= -1;
      b[i] *= -1;
    }
    P buf = {a[i] / g, b[i] / g};
    memo[buf] += 1;
  }
  lint res = 1;
  for (auto it = memo.begin(); it != memo.end(); ++it) {
    lint buf = 0;
    P mp;
    if (it->second == 0) {
      continue;
    }
    mp.first = (it->first).second;
    mp.second = (it->first).first;

    if (mp.first < 0) {
      mp.first *= -1;
      // mp.second*=1;
    } else {
      mp.second *= -1;
    }
    lint cur = 0;
    auto it2 = memo.find(mp);
    if (it2 != memo.end()) {
      cur += it2->second;
      it2->second = 0;
    }
    /*
    mp.first*=-1;
    mp.second*=-1;
    auto it3=memo.find(mp);
    if(it3!=memo.end()){
        cur+=it3->second;
        it3->second=0;
    }*/
    buf = lib.myPow(2, it->second, MOD);
    buf += lib.myPow(2, cur, MOD) - 1 + MOD;
    buf %= MOD;
    res *= buf;
    res %= MOD;
    it->second = 0;
  }
  res *= lib.myPow(2, a0, MOD) + lib.myPow(2, b0, MOD) - 1;
  res %= MOD;
  res += cnt0 + MOD - 1;
  res %= MOD;
  cout << res << "\\n";
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
#define int long long
#define lint long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define ALL(x) x.begin(), x.end()
#define ll long long
typedef pair<int, int> P;
const lint inf = 1e18 + 7;
const int MOD = 1000000007;
struct Nums {
  long long n;
  vector<long long> kaijo;
  Nums(int N) {
    n = N;
    kaijo.push_back(1);
    for (long long i = 1; i <= n; i++) {
      kaijo.push_back((kaijo[i - 1] * i) % MOD);
    }
  }
  long myPow(long x, long n, long m) {
    if (n == 0)
      return 1;
    if (n % 2 == 0)
      return myPow(x * x % m, n / 2, m);
    else
      return x * myPow(x, n - 1, m) % m;
  }
  long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
      long long t = a / b;
      a -= t * b;
      swap(a, b);
      u -= t * v;
      swap(u, v);
    }
    u %= m;
    if (u < 0)
      u += m;
    return u;
  }
  long long comb(long long N, long long K, long long rest) {
    long long res = kaijo[N] * modinv(kaijo[K], rest) % rest;
    res *= modinv(kaijo[N - K], rest);
    res %= rest;
    return res;
  }
};

int gcd(int a, int b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}
signed main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  map<P, int> memo;
  Nums lib(n + 5);
  rep(i, n) {
    cin >> a[i] >> b[i];
    int ba = abs(a[i]);
    int bb = abs(b[i]);
    int g = gcd(ba, bb);
    P buf = {a[i] / g, b[i] / g};
    memo[buf] += 1;
  }
  int res = 0;
  int sum = n;
  for (auto it = memo.begin(); it != memo.end(); ++it) {
    int buf = 0;

    sum -= it->second;
    P mp = it->first;
    swap(mp.first, mp.second);
    mp.first *= -1;
    int cur = sum;
    auto it2 = memo.find(mp);
    if (it2 != memo.end()) {
      cur -= it2->second;
    }
    mp.first *= -1;
    mp.second *= -1;
    auto it3 = memo.find(mp);
    if (it3 != memo.end()) {
      cur -= it3->second;
    }
    buf = lib.myPow(2, it->second, MOD) - 1;
    buf *= lib.myPow(2, cur, MOD);
    buf %= MOD;
    res += buf;
    res %= MOD;
  }
  cout << res << "\\n";
  return 0;
}