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

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mem(a, b) memset(a, b, sizeof(a))
#define all(x) (x).begin(), (x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) {
  a %= MOD;
  (a < 0) && (a += MOD);
}
inline ll modMul(ll a, ll b) {
  a %= MOD, b %= MOD;
  normal(a), normal(b);
  return (a * b) % MOD;
}
inline ll modAdd(ll a, ll b) {
  a %= MOD, b %= MOD;
  normal(a), normal(b);
  return (a + b) % MOD;
}
inline ll modSub(ll a, ll b) {
  a %= MOD, b %= MOD;
  normal(a), normal(b);
  a -= b;
  normal(a);
  return a;
}
inline ll modPow(ll b, ll p) {
  ll r = 1;
  while (p) {
    if (p & 1)
      r = modMul(r, b);
    b = modMul(b, b);
    p >>= 1;
  }
  return r;
}
inline ll modInverse(ll a) { return modPow(a, MOD - 2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
  int n;
  cin >> n;
  map<pll, ll> c, f;
  set<pll> e;
  int cnt = 0;
  rep(i, n) {
    ll a, b;
    cin >> a >> b;
    if (a != 0 && b != 0) {
      ll GCD = gcd(abs(a), abs(b));
      a /= GCD;
      b /= GCD;
    }
    if (a * b > 0) {
      c[MP(abs(a), abs(b))]++;
      f[MP(abs(a), abs(b))] = 1;
      f[MP(-abs(b), abs(a))] = 1;
      e.insert(MP(abs(a), abs(b)));
    } else if (a * b < 0) {
      c[MP(-abs(a), abs(b))]++;
      f[MP(-abs(a), abs(b))] = 1;
      f[MP(abs(b), abs(a))] = 1;
      e.insert(MP(-abs(a), abs(b)));
    } else if (a == 0 && b != 0) {
      c[MP(0, 1)]++;
      f[MP(0, 1)] = 1;
      f[MP(1, 0)] = 1;
      e.insert(MP(0, 1));
    } else if (a != 0 && b == 0) {
      c[MP(1, 0)]++;
      f[MP(1, 0)] = 1;
      f[MP(0, 1)] = 1;
      e.insert(MP(1, 0));
    } else
      cnt++;
  }
  vl d(n + 1);
  d[0] = 1;
  rep(i, n) {
    d[i + 1] = d[i] * 2;
    d[i + 1] %= MOD;
  }
  ll ans = 1;
  for (auto x : e) {
    if (f[x] == 1 && f[MP(-x.S, x.F)] == 1 && x.F > 0 && x.S > 0) {
      ans *= (d[c[x]] + d[c[MP(-x.S, x.F)]] - 1);
      f[x] = 0;
      f[MP(-x.S, x.F)] = 0;
    } else if (f[x] == 1 && f[MP(x.S, -x.F)] == 1 && x.F < 0 && x.S > 0) {
      ans *= (d[c[x]] + d[c[MP(x.S, -x.F)]] - 1);
      f[x] = 0;
      f[MP(x.S, -x.F)] = 0;
    } else if ((x.F == 0 || x.S == 0) && f[x] == 1 && f[MP(x.S, x.F)] == 1) {
      ans *= (d[c[x]] + d[c[MP(x.S, x.F)]] - 1);
      f[x] = 0;
      f[MP(x.S, x.F)] = 0;
    }
    ans %= MOD;
    while (ans < 0)
      ans += MOD;
  }
  ans += cnt;
  ans--;
  while (ans < 0)
    ans += MOD;
  cout << ans << endl;
}


Error: 0

Fixed submission:

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mem(a, b) memset(a, b, sizeof(a))
#define all(x) (x).begin(), (x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) {
  a %= MOD;
  (a < 0) && (a += MOD);
}
inline ll modMul(ll a, ll b) {
  a %= MOD, b %= MOD;
  normal(a), normal(b);
  return (a * b) % MOD;
}
inline ll modAdd(ll a, ll b) {
  a %= MOD, b %= MOD;
  normal(a), normal(b);
  return (a + b) % MOD;
}
inline ll modSub(ll a, ll b) {
  a %= MOD, b %= MOD;
  normal(a), normal(b);
  a -= b;
  normal(a);
  return a;
}
inline ll modPow(ll b, ll p) {
  ll r = 1;
  while (p) {
    if (p & 1)
      r = modMul(r, b);
    b = modMul(b, b);
    p >>= 1;
  }
  return r;
}
inline ll modInverse(ll a) { return modPow(a, MOD - 2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
  int n;
  cin >> n;
  map<pll, ll> c, f;
  set<pll> e;
  rep(i, n) {
    ll a, b;
    cin >> a >> b;
    ll GCD = gcd(abs(a), abs(b));
    a /= GCD;
    b /= GCD;
    if (a >= 0 && b >= 0) {
      c[MP(abs(a), abs(b))]++;
      f[MP(abs(a), abs(b))] = 1;
      f[MP(-abs(b), abs(a))] = 1;
      e.insert(MP(abs(a), abs(b)));
    } else {
      c[MP(-abs(a), abs(b))]++;
      f[MP(-abs(a), abs(b))] = 1;
      f[MP(abs(b), abs(a))] = 1;
      e.insert(MP(-abs(a), abs(b)));
    }
  }
  vl d(n + 1);
  d[0] = 1;
  rep(i, n) {
    d[i + 1] = d[i] * 2;
    d[i + 1] %= MOD;
  }
  ll ans = 1;
  for (auto x : e) {

    if (f[x] == 1 && f[MP(-x.S, x.F)] == 1 && x.F >= 0) {
      ans *= (d[c[x]] + d[c[MP(-x.S, x.F)]] - 1);
      f[x] = 0;
      f[MP(-x.S, x.F)] = 0;
    } else if (f[x] == 1 && f[MP(x.S, -x.F)] == 1 && x.F < 0) {
      ans *= (d[c[x]] + d[c[MP(x.S, -x.F)]] - 1);
      f[x] = 0;
      f[MP(x.S, -x.F)] = 0;
    }
    ans %= MOD;
    while (ans < 0)
      ans += MOD;
  }
  ans--;
  while (ans < 0)
    ans += MOD;
  cout << ans << endl;
}