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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(), (v).end())
typedef int64_t lint;
lint mod = 1000000007;
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

lint gcd(lint a, lint b) {
  if (a < b)
    swap(a, b);
  if (b == 0)
    return a;
  if (a % b == 0)
    return b;
  return gcd(a % b, b);
}

lint app() {
  int n;
  cin >> n;

  map<lint, map<lint, pair<int, int>>> m;
  rep(i, n) {
    lint a, b;
    cin >> a >> b;
    if (a == 0 && b == 0) {
      m[a][b].first++;
      continue;
    }
    if (a < 0 || (a == 0 && b < 0)) {
      a = -a;
      b = -b;
    }
    if (b > 0) {
      lint g = gcd(a, b);
      a = a / g;
      b = b / g;
      m[a][b].first++;
    } else {
      b = -b;
      swap(a, b);
      lint g = gcd(a, b);
      a = a / g;
      b = b / g;
      m[a][b].second++;
    }
  }

  lint ans = 1;
  for (auto ma : m) {
    for (auto mb : ma.second) {
      auto p = mb.second;
      if (ma.first == 0 && mb.first == 0) {
        continue;
      } else {
        lint k2 = 0;
        lint k = 1;
        rep(i, p.first) {
          k *= 2;
          k %= mod;
        }
        k2 += k;
        k = 1;
        rep(i, p.second) {
          k *= 2;
          k %= mod;
        }
        k2 += k;
        k2--; // duplicated 0,0

        k2 %= mod;
        ans *= k2;
        ans %= mod;
      }
    }
  }
  ans += m[0][0].first;

  ans--;
  ans += mod;
  ans %= mod;
  return ans;
}

int main() {
  cout << app() << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(), (v).end())
typedef int64_t lint;
lint mod = 1000000007;
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

lint gcd(lint a, lint b) {
  if (a < b)
    swap(a, b);
  if (a % b == 0)
    return b;
  return gcd(a % b, b);
}

lint app() {
  int n;
  cin >> n;

  map<lint, map<lint, pair<int, int>>> m;
  rep(i, n) {
    lint a, b;
    cin >> a >> b;
    if (a < 0) {
      a = -a;
      b = -b;
    }
    if (b >= 0) {
      lint g = gcd(a, b);
      a = a / g;
      b = b / g;
      m[a][b].first++;
    } else {
      b = -b;
      swap(a, b);
      lint g = gcd(a, b);
      a = a / g;
      b = b / g;
      m[a][b].second++;
    }
  }

  lint ans = 1;
  for (auto ma : m) {
    for (auto mb : ma.second) {
      auto p = mb.second;
      if (ma.first == 0 && mb.first == 0) {
        ans *= (p.first + 1);
        ans %= mod;
      } else {
        lint k2 = 0;
        lint k = 1;
        rep(i, p.first) {
          k *= 2;
          k %= mod;
        }
        k2 += k;
        k = 1;
        rep(i, p.second) {
          k *= 2;
          k %= mod;
        }
        k2 += k;
        k2--; // duplicated 0,0

        ans *= k2;
        ans %= mod;
      }
    }
  }

  ans--;
  ans %= mod;
  return ans;
}

int main() {
  cout << app() << endl;
  return 0;
}