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

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define gc                                                                     \\
  getchar() //(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define lc (x << 1)
#define rc (x << 1 | 1)
#define fi first
#define se second
#define mk make_pair
#define pb push_back
#define ll long long
#define pi pair<ll, ll>
using namespace std;
const int N = 2e5 + 10, size = 1 << 20, mod = 1000000007;

// char buf[size],*p1=buf,*p2=buf;
template <class o> void qr(o &x) {
  x = 0;
  int f = 1;
  char c = gc;
  while (!isdigit(c)) {
    if (c == '-')
      f = -1;
    c = gc;
  }
  while (isdigit(c))
    x = x * 10 + c - '0', c = gc;
  x *= f;
}
template <class o> void qw(o x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    qw(x / 10);
  putchar(x % 10 + '0');
}
template <class o> void pr1(o x) {
  qw(x);
  putchar(' ');
}
template <class o> void pr2(o x) {
  qw(x);
  puts("");
}

// math
ll gcd(ll x, ll y) { return !x ? y : gcd(y % x, x); }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll power(ll a, ll b = mod - 2) {
  ll c = 1;
  while (b) {
    if (b & 1)
      c = c * a % mod;
    b /= 2;
    a = a * a % mod;
  }
  return c;
}

map<pi, int> s;
int n;
ll ans, a, b, p[N], x, y, z, cnt;

int main() {
  qr(n);
  p[0] = 1;
  for (int i = 1; i <= n; i++)
    p[i] = p[i - 1] * 2LL % mod;
  for (int i = 1; i <= n; i++) {
    qr(x);
    qr(y);
    if (!x && !y) {
      cnt++;
      continue;
    }
    if (!x)
      a++;
    else if (!y)
      b++;
    else {
      z = gcd(abs(x), abs(y));
      if ((x < 0) == (y < 0))
        x = abs(x) / z, y = abs(y) / z;
      else
        x = -abs(x) / z, y = abs(y) / z;
      s[mk(x, y)]++;
    }
  }
  ans = (p[a] + p[b] - 1) % mod;
  for (auto i : s) {
    pi u = i.fi, t = u;
    swap(t.fi, t.se);
    if (t.se < 0)
      t.se = -t.se;
    else
      t.fi = -t.fi;
    ll v = i.second;
    if (s.count(t)) {
      if (u.fi < 0)
        ans = ans * (p[v] + p[s[t]] - 1) % mod;
    } else
      ans = ans * p[v] % mod;
  }
  pr2((ans - 1 + mod + cnt) % mod);
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define gc                                                                     \\
  getchar() //(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define lc (x << 1)
#define rc (x << 1 | 1)
#define fi first
#define se second
#define mk make_pair
#define pb push_back
#define ll long long
#define pi pair<ll, ll>
using namespace std;
const int N = 1e5 + 10, size = 1 << 20, mod = 1000000007;

// char buf[size],*p1=buf,*p2=buf;
template <class o> void qr(o &x) {
  x = 0;
  int f = 1;
  char c = gc;
  while (!isdigit(c)) {
    if (c == '-')
      f = -1;
    c = gc;
  }
  while (isdigit(c))
    x = x * 10 + c - '0', c = gc;
  x *= f;
}
template <class o> void qw(o x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    qw(x / 10);
  putchar(x % 10 + '0');
}
template <class o> void pr1(o x) {
  qw(x);
  putchar(' ');
}
template <class o> void pr2(o x) {
  qw(x);
  puts("");
}

// math
ll gcd(ll x, ll y) { return !x ? y : gcd(y % x, x); }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll power(ll a, ll b = mod - 2) {
  ll c = 1;
  while (b) {
    if (b & 1)
      c = c * a % mod;
    b /= 2;
    a = a * a % mod;
  }
  return c;
}

map<pi, int> s;
int n;
ll ans, a, b, p[N], x, y, z, cnt;

int main() {
  qr(n);
  p[0] = 1;
  for (int i = 1; i <= n; i++)
    p[i] = p[i - 1] * 2LL % mod;
  for (int i = 1; i <= n; i++) {
    qr(x);
    qr(y);
    if (!x && !y) {
      cnt++;
      continue;
    }
    if (!x)
      a++;
    else if (!y)
      b++;
    else {
      z = gcd(abs(x), abs(y));
      if ((x < 0) == (y < 0))
        x = abs(x) / z, y = abs(y) / z;
      else
        x = -abs(x) / z, y = abs(y) / z;
      s[mk(x, y)]++;
    }
  }
  ans = (p[a] + p[b] - 1) % mod;
  for (auto i : s) {
    auto u = i.first, t = u;
    swap(t.fi, t.se);
    if (t.se < 0)
      t.se = -t.se;
    else
      t.fi = -t.fi;
    ll v = i.second;
    if (s.count(t)) {
      if (u.fi < 0)
        ans = ans * (p[v] + p[s[t]] - 1) % mod;
    } else
      ans = ans * p[v] % mod;
  }
  pr2((ans - 1 + mod + cnt) % mod);
  return 0;
}