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

#include <bits/stdc++.h>

using namespace std;

#define INF 1000000000
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define EPS 10e-9
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define st first
#define nd second
#define sz(v) int(v.size())
#define all(X) (X).begin(), (X).end()
#define FOR(I, A, B) for (int I = A; I < B; I++)
#define RFOR(I, A, B) for (int I = A; I >= B; I--)

typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector<iii> viii;
typedef vector<ll> vll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

ll poww(ll x, ll e) {
  if (e == 0) {
    return 1;
  }
  ll ans = poww(x, e / 2);
  ans *= ans;
  ans %= MOD;
  if (e % 2) {
    ans *= x;
    ans %= MOD;
  }
  return ans;
}

ii norm(ii &x) {
  if (x.st < 0) {
    x.st *= -1;
    x.nd *= -1;
  } else if (x.st == 0) {
    if (x.nd < 0)
      x.nd *= -1;
  }
  ll g = gcd(abs(x.st), abs(x.nd));
  x.st /= g;
  x.nd /= g;
  return x;
}

ii getRival(ii x) {
  ii y = x;
  swap(y.st, y.nd);
  y.st *= -1;
  norm(y);
  return y;
}

bool isZero(ii x) { return x.st == 0 && x.nd == 0; }

ll soma(ll a, ll b) { return (a + b) % MOD; }
ll sub(ll a, ll b) {
  a %= MOD;
  b %= MOD;
  a -= b;
  if (a < 0)
    a += MOD;
  return a % MOD;
}

int main() {
  int n;
  scanf("%d", &n);
  vii sard(n);

  map<ii, ll> qnt;
  int contzeros = 0;
  for (int i = 0; i < n; i++) {
    scanf("%lld %lld", &sard[i].st, &sard[i].nd);
    if (isZero(sard[i])) {
      contzeros++;
    } else {
      norm(sard[i]);
      qnt[sard[i]] = 0;
      qnt[getRival(sard[i])] = 0;
    }
  }
  for (ii x : sard) {
    if (!isZero(x))
      qnt[x]++;
  }

  vii rivs;
  for (auto el : qnt) {
    ii x = el.st;
    ll f = el.nd;
    if (f == 0)
      continue;
    ii rival = getRival(x);
    ii toput;
    toput.st = f;
    toput.nd = qnt[rival];
    qnt[rival] = 0;
    rivs.pb(toput);
  }

  ll ans = 1;
  for (ii x : rivs) {
    ans *= sub(soma(poww(2, x.st), poww(2, x.nd)), 1);
    ans %= MOD;
  }
  printf("%lld\\n", soma(sub(ans, 1), contzeros));

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define INF 1000000000
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define EPS 10e-9
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define st first
#define nd second
#define sz(v) int(v.size())
#define all(X) (X).begin(), (X).end()
#define FOR(I, A, B) for (int I = A; I < B; I++)
#define RFOR(I, A, B) for (int I = A; I >= B; I--)

typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector<iii> viii;
typedef vector<ll> vll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

ll poww(ll x, ll e) {
  if (e == 0) {
    return 1;
  }
  ll ans = poww(x, e / 2);
  ans *= ans;
  ans %= MOD;
  if (e % 2) {
    ans *= x;
    ans %= MOD;
  }
  return ans;
}

ii norm(ii &x) {
  if (x.st < 0) {
    x.st *= -1;
    x.nd *= -1;
  } else if (x.st == 0) {
    if (x.nd < 0)
      x.nd *= -1;
  }
  ll g = gcd(abs(x.st), abs(x.nd));
  x.st /= g;
  x.nd /= g;
  return x;
}

ii getRival(ii x) {
  ii y = x;
  swap(y.st, y.nd);
  y.st *= -1;
  norm(y);
  return y;
}

ll soma(ll a, ll b) { return (a + b) % MOD; }
ll sub(ll a, ll b) {
  a %= MOD;
  b %= MOD;
  a -= b;
  if (a < 0)
    a += MOD;
  return a % MOD;
}

int main() {
  int n;
  scanf("%d", &n);
  vii sard(n);

  map<ii, ll> qnt;
  for (int i = 0; i < n; i++) {
    scanf("%lld %lld", &sard[i].st, &sard[i].nd);
    norm(sard[i]);
    qnt[sard[i]] = 0;
    qnt[getRival(sard[i])] = 0;
  }
  for (ii x : sard) {
    qnt[x]++;
  }

  vii rivs;
  for (auto el : qnt) {
    ii x = el.st;
    ll f = el.nd;
    if (f == 0)
      continue;
    ii rival = getRival(x);
    ii toput;
    toput.st = f;
    toput.nd = qnt[rival];
    qnt[rival] = 0;
    rivs.pb(toput);
  }

  ll ans = 1;
  for (ii x : rivs) {
    ans *= sub(soma(poww(2, x.st), poww(2, x.nd)), 1);
    ans %= MOD;
  }
  printf("%lld\\n", sub(ans, 1));

  return 0;
}