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

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
int n;
struct uzi {
  LL a, b;
} p[N];
const LL mod = 1e9 + 7;
map<pair<LL, LL>, int> m;
LL pm(LL x, LL y) {
  LL z = 1;
  while (y) {
    if (y & 1)
      z = z * x % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return z;
}
LL fac[N];
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  fac[0] = 1;
  for (int i = 1; i <= n; i++)
    fac[i] = fac[i - 1] * 2 % mod;
  for (int i = 1; i <= n; i++) {
    cin >> p[i].a >> p[i].b;
    LL z = __gcd(labs(p[i].a), labs(p[i].b));
    if (z)
      p[i].a /= z, p[i].b /= z;
    if (p[i].b < 0)
      p[i].b = -p[i].b, p[i].a = -p[i].a;
    // cout<<p[i].a<<' '<<p[i].b<<endl;
  }
  // cout<<"----------\\n";
  LL ans = 0, tot = 1;
  int npb = 0, npa = 0, gc = 0, typ = 0, dx = 0, dy = 0;
  for (int i = 1; i <= n; i++) {
    if (!p[i].a && !p[i].b)
      ans++;
    else if (!p[i].a) {
      ans += fac[npa] * tot % mod;
      ans %= mod;
      npa++;
    } else if (!p[i].b) {
      ans += fac[npb] * tot % mod;
      ans %= mod;
      npb++;
    } else {
      int x = m[{p[i].a, p[i].b}];
      if (p[i].a < 0)
        p[i].a = -p[i].a, p[i].b = -p[i].b;
      int y = m[{-p[i].b, p[i].a}];
      tot *= pm((fac[x] + fac[y] - 1 + mod) % mod, mod - 2);
      tot %= mod; // cout<<tot<<endl;
      ans += tot * fac[y] % mod * ((fac[npa] + fac[npb] - 1 + mod) % mod) % mod;
      ans %= mod;
      m[{-p[i].b, p[i].a}]++;
      tot *= (fac[x] + fac[y + 1] - 1 + mod) % mod;
      tot %= mod;
    }
    // cout<<i<<' '<<ans<<endl;
  }
  cout << ans << '\\n';
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
int n;
struct uzi {
  LL a, b;
} p[N];
const LL mod = 1e9 + 7;
map<pair<LL, LL>, int> m;
LL pm(LL x, LL y) {
  LL z = 1;
  while (y) {
    if (y & 1)
      z = z * x % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return z;
}
LL fac[N];
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  fac[0] = 1;
  for (int i = 1; i <= n; i++)
    fac[i] = fac[i - 1] * 2 % mod;
  for (int i = 1; i <= n; i++) {
    cin >> p[i].a >> p[i].b;
    LL z = __gcd(labs(p[i].a), labs(p[i].b));
    if (z)
      p[i].a /= z;
    p[i].b /= z;
    if (p[i].b < 0)
      p[i].b = -p[i].b, p[i].a = -p[i].a;
    // cout<<p[i].a<<' '<<p[i].b<<endl;
  }
  // cout<<"----------\\n";
  LL ans = 0, tot = 1;
  int npb = 0, npa = 0, gc = 0, typ = 0, dx = 0, dy = 0;
  for (int i = 1; i <= n; i++) {
    if (!p[i].a && !p[i].b)
      ans++;
    else if (!p[i].a) {
      ans += fac[npa] * tot % mod;
      npa++;
    } else if (!p[i].b) {
      ans += fac[npb] * tot % mod;
      npb++;
    } else {
      int x = m[{p[i].a, p[i].b}];
      if (p[i].a < 0)
        p[i].a = -p[i].a, p[i].b = -p[i].b;
      int y = m[{-p[i].b, p[i].a}];
      // cout<<x<<' '<<y<<' '<<tot<<' ';
      tot *= pm((fac[x] + fac[y] - 1 + mod) % mod, mod - 2);
      tot %= mod; // cout<<tot<<endl;
      ans += tot * fac[y] % mod * ((fac[npa] + fac[npb] - 1 + mod) % mod) % mod;
      ans %= mod;
      m[{-p[i].b, p[i].a}]++;
      tot *= (fac[x] + fac[y + 1] - 1 + mod) % mod;
      tot %= mod;
    }
    // cout<<i<<' '<<ans<<endl;
  }
  cout << ans << '\\n';
  return 0;
}