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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
const ll MOD = 1000000007, MAXN = 2e5 + 10;
map<pii, int> Cnt;
map<pii, bool> Vis;
pii Vec[MAXN], NVec[MAXN];
int N;
inline ll fpow(ll a, ll x) {
  ll ans = 1;
  for (; x; x >>= 1, a = a * a % MOD)
    if (x & 1)
      ans = ans * a % MOD;
  return ans;
}
pii operator/(const pii &vec, ll n) {
  return pii(vec.first / n, vec.second / n);
}
inline pii simplfy(const pii &Vec) {
  if (Vec == pii(0, 0))
    return Vec;
  pii newVec = Vec / __gcd(abs(Vec.first), abs(Vec.second));
  if (newVec.first < 0 || (newVec.first == 0 && newVec.second < 0))
    newVec = newVec / (-1);
  return newVec;
}
inline void pre() {
  Cnt[pii(0, 0)] = 0;
  Vis[pii(0, 0)] = 1;
  cin >> N;
  for (int i = 1; i <= N; i++) {
    ll X, Y;
    cin >> X >> Y;
    Vec[i] = simplfy(pii(X, Y)), NVec[i] = simplfy(pii(Y, -X));
    if (Cnt.find(Vec[i]) == Cnt.end())
      Cnt[Vec[i]] = 0;
    if (Cnt.find(NVec[i]) == Cnt.end())
      Cnt[NVec[i]] = 0;
    Cnt[Vec[i]]++;
  }
}
int main() {
  pre();
  ll Sum = 1;
  for (int i = 1; i <= N; i++) {
    if (Vis[Vec[i]])
      continue;
    Vis[Vec[i]] = Vis[NVec[i]] = 1;
    Sum *= fpow(2, Cnt[Vec[i]]) + fpow(2, Cnt[NVec[i]]) - 1;
    Sum %= MOD;
  }
  Sum = (Sum - 1 + Cnt[pii(0, 0)] + MOD) % MOD;
  cout << Sum;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

namespace HABIT {
#define f(a, b, c, d) for (register int a = b, c = d; a <= c; a++)
#define g(a, b, c, d) for (register int a = b, c = d; a >= c; a--)
#define LOCAL
typedef int i32;
typedef unsigned int u32;
typedef long long int i64;
typedef unsigned long long int u64;
typedef pair<i64, i64> pii;
const i32 MAXN = 2e5 + 10;
typedef i32 ar[MAXN];

template <typename T> inline T Max(T a) { return a; }
template <typename T, typename... Args> inline T Max(T a, Args... args) {
  T b = Max(args...);
  return (a > b) ? a : b;
}
template <typename T> inline T Min(T a) { return a; }
template <typename T, typename... Args> inline T Min(T a, Args... args) {
  T b = Min(args...);
  return (a < b) ? a : b;
}

#ifdef LOCAL
inline char gc() { return getchar(); }
#else
inline char gc() {
  static char s[1 << 20 | 1] = {0}, *p1 = s, *p2 = s;
  return (p1 == p2) && (p2 = (p1 = s) + fread(s, 1, 1 << 20, stdin), p1 == p2)
             ? EOF
             : *(p1++);
}
#endif
inline i64 read() {
  register i64 ans = 0;
  register char c = gc();
  register bool neg = 0;
  while (c < 48 || c > 57)
    neg ^= !(c ^ '-'), c = gc();
  while (c >= 48 && c <= 57)
    ans = (ans << 3) + (ans << 1) + (c ^ 48), c = gc();
  return neg ? -ans : ans;
}

char Output_Ans[1 << 20 | 1], *Output_Cur = Output_Ans;
inline void output() {
  Output_Cur -= fwrite(Output_Ans, 1, Output_Cur - Output_Ans, stdout);
}
inline void print(char c) {
  if (Output_Cur - Output_Ans + 1 >> 20)
    output();
  *(Output_Cur++) = c;
}
inline void print(char *s) {
  while (*s)
    print(*(s++));
}
inline void print(u64 x) {
  if (!x) {
    print('0');
    return;
  }
  char buf[30] = {0}, *p = buf + 28;
  while (x)
    *(p--) = x % 10 + 48, x /= 10;
  print(p + 1);
}
inline void print(u32 x) { print((u64)x); }
inline void print(i64 x) {
  if (x < 0)
    print('-'), x = -x;
  print((u64)x);
}
inline void print(i32 x) {
  if (x < 0)
    print('-'), x = -x;
  print((u64)x);
}
} // namespace HABIT
using namespace HABIT;

map<pii, i32> M;
i32 N;
pii Pnt[MAXN];
i32 PVec[MAXN], VVec[MAXN];
bool Vis[MAXN];
const i64 MOD = 1000000007;

i64 gcd(i64 x, i64 y) {
  if (x < 0)
    return gcd(-x, y);
  if (y < 0)
    return gcd(x, -y);
  if (!y)
    return x;
  return gcd(y, x % y);
}

inline i32 findit(i64 x, i64 y) {
  i64 g = gcd(x, y);
  if ((x < 0) ^ (y < 0))
    g = -g;
  x /= g;
  y /= g;
  if (M.find(pii(x, y)) != M.end())
    return M[pii(x, y)];
  return -1;
}

inline void addToMap(i64 x, i64 y, i32 i) {
  i64 g = gcd(x, y);
  x /= g;
  y /= g;
  M[pii(x, y)] = M[pii(-x, -y)] = i;
}

inline void pre() {
  N = read();
  f(i, 1, I, N) {
    Pnt[i].first = read();
    Pnt[i].second = read();
    PVec[i] = findit(Pnt[i].first, Pnt[i].second);
    addToMap(Pnt[i].first, Pnt[i].second, i);
    VVec[i] = findit(-Pnt[i].second, Pnt[i].first);
  }
}

inline i64 fpow(i64 a, i64 x) {
  i64 Ans = 1;
  for (; x; x >>= 1, a = a * a % MOD)
    if (x & 1)
      Ans = Ans * a % MOD;
  return Ans;
}

inline i32 findP(i32 n) {
  i32 Cnt = 0;
  while (n != -1) {
    Vis[n] = 1;
    n = PVec[n];
    Cnt++;
  }
  return Cnt;
}

int main() {
  pre();
  i64 Ans = 1;
  g(i, N, I, 1) if (!Vis[i]) {
    i32 N1 = findP(i), N2 = findP(VVec[i]);
    Ans = (fpow(2, N1) + fpow(2, N2) - 1) % MOD * Ans % MOD;
  }
  Ans = (Ans - 1) % MOD;
  print(Ans);
  output();
  return 0;
}