alexjercan/bugnet huggingface dataset:
Problem p02679 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"

#define pb push_back
#define ld long double
#define ll long long
#define f first
#define s second

using namespace std;

const ll MOD = 1e9 + 7;
const ll MOD1 = 2468777687;
const ll MOD2 = 1e9 + 9;

ll n;
vector<ll> t;
map<pair<ll, ll>, ll> v;
ll exp(ll a, ll x, ll MOD3) {
  if (x == 0)
    return 1;
  ll tmp = exp(a, x / 2, MOD3);
  tmp *= tmp;
  tmp %= MOD3;
  if (x % 2)
    tmp *= a;
  tmp %= MOD3;
  return tmp;
}

ll inv(ll x, ll MOD3) { return exp(x, MOD3 - 2, MOD3); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  ll o = 0, e = 0, c = 0;
  for (int i = 0; i < n; ++i) {
    ll a, b;
    cin >> a >> b;
    if (a == 0 && b == 0)
      c++;
    else if (a == 0)
      e++;
    else if (b == 0)
      o++;
    else {
      ll a1 = ((a % MOD1) + MOD1) % MOD1;
      ll b1 = ((b % MOD1) + MOD1) % MOD1;
      ll a2 = ((a % MOD2) + MOD2) % MOD2;
      ll b2 = ((b % MOD2) + MOD2) % MOD2;
      v[{(a1 * inv(b1, MOD1)) % MOD1, (a2 * inv(b2, MOD2)) % MOD2}]++;
    }
  }
  t.assign(2e5 + 5, 1);
  for (int i = 1; i < t.size(); ++i) {
    t[i] = 2 * t[i - 1];
    t[i] %= MOD;
  }
  ll res = 1;
  set<pair<ll, ll>> done;
  for (auto i : v) {
    if (done.find(i.f) != done.end())
      continue;
    ll oth1 = (inv((-i.f.f + MOD1) % MOD1, MOD1) + MOD1) % MOD1;
    ll oth2 = (inv((-i.f.s + MOD2) % MOD2, MOD2) + MOD2) % MOD2;
    ll cur = (t[i.s] + t[v[{oth1, oth2}]]) % MOD;
    cur--;
    res *= cur;
    res %= MOD;
    // cout << i.f << " " << i.s << " " << oth << " " << cur << "\\n";
    // cout << cur << "\\n";
    done.insert(i.f);
    done.insert({oth1, oth2});
  }
  res *= ((t[o] + t[e]) - 1 + MOD) % MOD;
  res %= MOD;
  if (c > 0)
    res += c;
  cout << (res - 1 + MOD) % MOD;
  return 0;
}

Error: WA

Fixed submission:

#include "bits/stdc++.h"

#define pb push_back
#define ld long double
#define ll long long
#define f first
#define s second

using namespace std;

const ll MOD = 1e9 + 7;

ll n;
vector<ll> t;
map<pair<ll, ll>, ll> v;
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    ll a, b;
    cin >> a >> b;
    if (b < 0) {
      b *= -1;
      a *= -1;
    }
    v[{a / __gcd(a, b), b / __gcd(a, b)}]++;
  }
  t.assign(2e5 + 5, 1);
  for (int i = 1; i < t.size(); ++i) {
    t[i] = 2 * t[i - 1];
    t[i] %= MOD;
  }
  ll res = 1;
  set<pair<ll, ll>> done;
  for (auto i : v) {
    if (done.find(i.f) != done.end())
      continue;
    // cout << i.f.f << " " << i.f.s << " " << i.s << ": ";
    ll cur = (t[i.s] + t[v[{i.f.s, -i.f.f}]]) % MOD;
    cur--;
    res *= cur;
    res %= MOD;
    // cout << cur << "\\n";
    done.insert(i.f);
    done.insert({i.f.s, -i.f.f});
  }
  cout << res - 1;
  return 0;
}
Problem p02679 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)

constexpr int MOD = 1e+9 + 7;
template <typename T> T gcd(T a, T b) {
  if (b == 0)
    return a;
  else
    return gcd<T>(b, a % b);
}

template <typename T> T pow_mod(T n, T p, T m) {
  if (p == 0)
    return 1;
  if (p % 2 == 1)
    return pow_mod<T>(n, p - 1, m) * n % m;
  else {
    T tmp = pow_mod<T>(n, p / 2, m) % m;
    return tmp * tmp % m;
  }
}

int main() {
  int N;
  cin >> N;
  map<pair<long long, long long>, pair<int, int>> P;
  int num_zeros = 0;
  for (int i = 1; i <= N; i++) {
    long long A, B;
    cin >> A >> B;
    if (A == 0 and B == 0) {
      ++num_zeros;
      continue;
    }
    long long GCD = gcd<long long>(A, B);
    A /= GCD;
    B /= GCD;
    if (B < 0) {
      A = -A;
      B = -B;
    }
    if (A > 0)
      P[make_pair(A, B)].first++;
    else
      P[make_pair(B, -A)].second++;
  }

  long long ans = 1;
  for (auto p : P) {
    int num_i = p.second.first;
    int num_j = p.second.second;
    long long num_pairs = pow_mod<long long>(2, num_i, MOD) +
                          pow_mod<long long>(2, num_j, MOD) - 1;
    ans *= num_pairs % MOD;
    ans %= MOD;
  }
  cout << (ans + num_zeros - 1 + MOD) % MOD << endl;

  return 0;
}

Error: -8

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int n, zero;
long long a, b, ans = 1;
map<pair<long long, long long>, pair<int, int>> table;
const long long MOD = 1e9 + 7;
long long gcd(long long a, long long b) {
  if (a == 0)
    return b;
  if (b == 0)
    return a;
  long long c = a % b;
  while (c) {
    c = a % b;
    a = b;
    b = c;
  }
  return b;
}
long long quickpow(long long x, long long y, long long mod) {
  long long ans = 1;
  while (y) {
    if (y % 2 == 1)
      ans = (ans * x) % mod;
    y /= 2;
    x = (x * x) % mod;
  }
  return ans;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a >> b;
    if (a == 0 && b == 0) {
      zero++;
      continue;
    }
    if (a < 0 && b < 0) {
      a = -a, b = -b;
    }
    long long temp = gcd(a, b);
    a /= temp;
    b /= temp;
    if (b < 0) {
      a = -a;
      b = -b;
    }
    if (a < 0)
      table[make_pair(b, -a)].first++;
    else
      table[make_pair(a, b)].second++;
  }
  for (auto p : table) {
    int i = p.second.first;
    int j = p.second.second;
    long long temp = quickpow(2, i, MOD) + quickpow(2, j, MOD) - 1;
    ans = (ans * temp) % MOD;
    ans %= MOD;
  }
  cout << (ans + zero - 1 + MOD) % MOD;
  return 0;
}
Problem p02679 (C++) — buggy submission, verdict: Runtime Error

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

long long gcd(long long x, long long y) { return (y) ? gcd(y, x % y) : x; }

const long long MOD = 1000000007;

int main() {
  int N;
  cin >> N;

  vector<long long> pw(200010);

  pw[0] = 1;
  for (int i = 1; i < 200010; ++i)
    pw[i] = (pw[i - 1] * 2) % MOD;

  map<pair<long long, long long>, pair<int, int>> x;

  long long zz = 0;
  for (int i = 0; i < N; ++i) {
    long long a, b;
    cin >> a >> b;
    if (a == 0 && b == 0) {
      zz++;
      continue;
    }
    if (make_pair(a, b) < make_pair(0LL, 0LL)) {
      a = -a;
      b = -b;
    }
    long long g = gcd(abs(a), abs(b));
    a /= g;
    b /= g;
    if (b > 0) {
      x[make_pair(a, b)].first++;
    } else {
      x[make_pair(-b, a)].second++;
    }
  }

  long long ans = 1;
  for (auto &p : x) {
    ans = ans * (pw[p.second.first] + pw[p.second.second] - 1) % MOD;
  }

  cout << (ans + zz + MOD - 1) % MOD << endl;

  return 0;
}


Error: 0

Fixed submission:

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

long long gcd(long long x, long long y) { return (x % y) ? gcd(y, x % y) : y; }

const long long MOD = 1000000007;

int main() {
  int N;
  cin >> N;

  vector<long long> pw(200010);

  pw[0] = 1;
  for (int i = 1; i < 200010; ++i)
    pw[i] = (pw[i - 1] * 2) % MOD;

  map<pair<long long, long long>, pair<int, int>> x;

  long long zz = 0;
  for (int i = 0; i < N; ++i) {
    long long a, b;
    cin >> a >> b;
    if (a == 0 && b == 0) {
      zz++;
      continue;
    }
    if (make_pair(a, b) < make_pair(0LL, 0LL)) {
      a = -a;
      b = -b;
    }
    long long g = gcd(abs(a), abs(b));
    a /= g;
    b /= g;
    if (b > 0) {
      x[make_pair(a, b)].first++;
    } else {
      x[make_pair(-b, a)].second++;
    }
  }

  long long ans = 1;
  for (auto &p : x) {
    ans = ans * (pw[p.second.first] + pw[p.second.second] - 1) % MOD;
  }

  cout << (ans + zz + MOD - 1) % MOD << endl;

  return 0;
}
Problem p02679 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, N = 200005;
long long a[N], b[N], pwr[N], ans, g, k, n, f1, f2;
map<pair<long long, long long>, int> fix;
int main() {
  cin >> n;
  pwr[0] = 1;
  for (k = 1; k <= n; k++) {
    cin >> a[k] >> b[k];
    pwr[k] = (pwr[k - 1] * 2) % mod;
    if (a[k] != 0 && b[k] != 0) {
      g = __gcd(abs(a[k]), abs(b[k]));
      a[k] /= g;
      b[k] /= g;
    }
    if (a[k] == 0 && b[k] != 0)
      f1++;
    else if (a[k] != 0 && b[k] == 0)
      f2++;
    else {
      if (a[k] < 0) {
        a[k] *= -1;
        b[k] *= -1;
      }
      fix[{a[k], b[k]}]++;
    }
  }
  ans = 1;
  for (k = 1; k <= n; k++) {

    if (fix[{a[k], b[k]}] != 0) {
      if (a[k] == 0 || b[k] == 0) {
      } else {
        long long cura = b[k], curb = a[k];
        if (cura < 0)
          cura = -cura;
        else
          curb = -curb;
        ans *=
            (pwr[fix[{a[k], b[k]}]] - 1ll + pwr[fix[{cura, curb}]] % mod) % mod;
        ans %= mod;
        fix[{a[k], b[k]}] = fix[{cura, curb}] = 0;
      }
    }
  }
  ans *= (pwr[f1] + pwr[f2] - 1ll) % mod;
  ans %= mod;
  ans += fix[{0, 0}];
  ans %= mod;
  cout << (ans + mod - 1ll) % mod << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, N = 200005;
long long a[N], b[N], pwr[N], ans, g, k, n;
map<pair<long long, long long>, int> fix;
int main() {
  cin >> n;
  pwr[0] = 1;
  for (k = 1; k <= n; k++) {
    cin >> a[k] >> b[k];
    pwr[k] = pwr[k - 1] * 2 % mod;
    g = __gcd(abs(a[k]), abs(b[k]));
    a[k] /= g;
    b[k] /= g;
    fix[{a[k], b[k]}]++;
  }
  ans = 1;
  for (k = 1; k <= n; k++) {

    if (fix[{a[k], b[k]}] != 0) {
      if (a[k] == b[k] && b[k] == 0)
        ans *= 2;
      else
        ans *= (pwr[fix[{a[k], b[k]}]] - 1 + pwr[fix[{b[k], -a[k]}]] +
                pwr[fix[{-b[k], a[k]}]] - 2) +
               1;
      ans %= mod;
      fix[{a[k], b[k]}] = fix[{-b[k], a[k]}] = fix[{b[k], -a[k]}] = 0;
    }
  }
  ans += mod;
  ans--;
  ans %= mod;
  cout << ans << endl;
}
Problem p02679 (C++) — buggy submission, verdict: Runtime Error

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

#define int long long

inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-')
      f = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar())
    x = (x << 1) + (x << 3) + ch - '0';
  return x * f;
}

const int N = 2e5 + 5;
const int P = 1e9 + 7;
map<pair<int, int>, pair<int, int>> cnt;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int Pow(int x, int t) {
  int res = 1;
  for (; t; t >>= 1, x = x * x % P)
    if (t & 1)
      res = res * x % P;
  return res;
}

signed main() {
  int n = read(), tot = P - 1;
  for (int i = 1; i <= n; ++i) {
    int a = read(), b = read();
    if (!a && !b) {
      ++tot;
      continue;
    }
    int g = gcd(a, b);
    a /= g;
    b /= g;
    if (b < 0)
      a = -a, b = -b;

    if (a > 0)
      ++cnt[{a, b}].first;
    else
      ++cnt[{b, -a}].second;
  }

  int ans = 1;
  for (auto i : cnt)
    ans = ans * (Pow(2, i.second.first) + Pow(2, i.second.second) - 1) % P;
  printf("%lld\\n", (ans + tot) % P);
  return 0;
}


Error: 0

Fixed submission:

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

#define int long long

inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-')
      f = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar())
    x = (x << 1) + (x << 3) + ch - '0';
  return x * f;
}

const int N = 2e5 + 5;
const int P = 1e9 + 7;
map<pair<int, int>, pair<int, int>> cnt;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int Pow(int x, int t) {
  int res = 1;
  for (; t; t >>= 1, x = x * x % P)
    if (t & 1)
      res = res * x % P;
  return res;
}

signed main() {
  int n = read(), tot = P - 1;
  for (int i = 1; i <= n; ++i) {
    int a = read(), b = read();
    if (!a && !b)
      ++tot;
    int g = gcd(a, b);
    a /= g;
    b /= g;
    if (b < 0)
      a = -a, b = -b;

    if (a > 0)
      ++cnt[{a, b}].first;
    else
      ++cnt[{b, -a}].second;
  }

  int ans = 1;
  for (auto i : cnt)
    ans = ans * (Pow(2, i.second.first) + Pow(2, i.second.second) - 1) % P;
  printf("%lld\\n", (ans + tot) % P);
  return 0;
}
Problem p02679 (C++) — buggy submission, verdict: Runtime Error

#pragma GCC optimize("Ofast")
#include <algorithm>
#include <map>
#include <stdio.h>
#include <utility>
#include <vector>
using namespace std;
long long a[200005], b[200005], mod = 1000000007;
map<pair<long long, long long>, pair<long long, long long>> m;
vector<pair<long long, long long>> vec;
long long power(long long n, long long m) {
  if (!m)
    return 1;
  long long v = power(n, m >> 1);
  if (m & 1)
    return v * v % mod * n % mod;
  return v * v % mod;
}
long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }
int main() {
  long long i, n, ans = 1, zero = 0, cnt = 0, zero2 = 0, zero3 = 0;
  scanf("%lld", &n);
  for (i = 1; i <= n; i++)
    scanf("%lld%lld", &a[i], &b[i]);
  for (i = 1; i <= n; i++) {
    if (!a[i] && !b[i])
      zero++;
    else if (!a[i])
      zero2++;
    else if (!b[i])
      zero3++;
    else {
      long long v = abs(GCD(a[i], b[i]));
      a[i] /= v;
      b[i] /= v;
      if (a[i] < 0) {
        if (b[i] < 0)
          m[{-a[i], -b[i]}].first++;
        else
          m[{b[i], -a[i]}].second++;
      } else {
        if (b[i] < 0)
          m[{-b[i], a[i]}].second++;
        else
          m[{a[i], b[i]}].first++;
      }
    }
  }
  for (auto x : m) {
    auto y = x.second;
    if (y.first && y.second) {
      vec.emplace_back(y.first, y.second);
      cnt += y.first + y.second;
    }
  }
  ans = power(2, n - cnt - zero - zero2 - zero3);
  vec.emplace_back(zero2, zero3);
  for (auto x : vec) {
    long long v =
        ((power(2, x.first) + power(2, x.second)) % mod - 1 + mod) % mod;
    ans = ans * v % mod;
  }
  printf("%lld\\n", (ans - 1 + mod + zero) % mod);
}

Error: 0

Fixed submission:

#pragma GCC optimize("Ofast")
#include <algorithm>
#include <map>
#include <stdio.h>
#include <utility>
#include <vector>
using namespace std;
long long a[200005], b[200005], mod = 1000000007;
map<double, long long> m, used;
vector<pair<long long, long long>> vec;
long long power(long long n, long long m) {
  if (!m)
    return 1;
  long long v = power(n, m >> 1);
  if (m & 1)
    return v * v % mod * n % mod;
  return v * v % mod;
}
int main() {
  long long i, n, ans = 1, zero = 0, cnt = 0, zero2 = 0, zero3 = 0;
  scanf("%lld", &n);
  for (i = 1; i <= n; i++)
    scanf("%lld%lld", &a[i], &b[i]);
  for (i = 1; i <= n; i++) {
    if (!a[i] && !b[i])
      zero++;
    else if (!a[i])
      zero2++;
    else if (!b[i])
      zero3++;
    else
      m[(double)a[i] / b[i]]++;
  }
  for (auto it = m.begin(); it != m.end(); it++) {
    if (used[(double)-1 / (*it).first])
      continue;
    auto x = m.find((double)-1 / (*it).first);
    if (x != m.end()) {
      used[(*it).first] = 1;
      vec.emplace_back((*it).second, (*x).second);
      cnt += (*it).second + (*x).second;
    }
  }
  ans = power(2, n - cnt - zero - zero2 - zero3);
  vec.emplace_back(zero2, zero3);
  for (auto x : vec) {
    long long v =
        ((power(2, x.first) + power(2, x.second)) % mod - 1 + mod) % mod;
    ans = ans * v % mod;
  }
  printf("%lld\\n", (ans - 1 + mod + zero) % mod);
}
Problem p02679 (C++) — buggy submission, verdict: Runtime Error

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

typedef long long ll;
typedef pair<ll, ll> pi;
typedef vector<ll> vi;
typedef vector<pi> vpi;
#define f first
#define s second
#define FOR(i, s, e) for (ll i = s; i <= ll(e); ++i)
#define DEC(i, s, e) for (ll i = s; i >= ll(e); --i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i, x) for (auto i : x)
#define mem(x, i) memset(x, i, sizeof x)
#define fast ios_base::sync_with_stdio(false), cin.tie(0)
#define MOD 1000000007
#define int ll
int N;
#define maxn 200001

map<pi, int64_t> num;

ll pow2[maxn];

pi simp(pi x) {
  if (x.s < 0)
    x.f = -x.f, x.s = -x.s;

  int a = __gcd(abs(x.f), abs(x.s));
  return pi(x.f / a, x.s / a);
}

int num00 = 0;
int numA0 = 0, numB0 = 0;

int32_t main() {
  fast;

  cin >> N;

  set<pi> S;

  FOR(i, 1, N) {
    ll a, b;
    cin >> a >> b;
    if (a == 0 && b == 0) {
      num00++;
      continue;
    }
    if (a == 0) {
      numA0++;
      continue;
    }
    if (b == 0) {
      numB0++;
      continue;
    }
    pi res = simp(pi(a, b));
    num[res]++;
    if (res.f < 0)
      S.insert(pi(res.s, -res.f));
    else
      S.insert(res);
  }

  pow2[0] = 1;
  FOR(i, 1, N) pow2[i] = (pow2[i - 1] * 2) % MOD;

  ll ans = 1;
  aFOR(i, S) {
    pi cur = i;

    pi x = pi(-cur.s, cur.f);
    if (x.s < 0)
      x.f = -x.f, x.s = -x.s;

    ans *= (pow2[num[i]] + pow2[num[x]] - 1 + MOD) % MOD;
    ans %= MOD;
  }

  ans *= (pow2[numA0] + pow2[numB0] - 1 + MOD) % MOD;
  ans %= MOD;
  cout << (ans + num00 - 1 + MOD) % MOD;
}


Error: WA

Fixed submission:

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

typedef long long ll;
typedef pair<ll, ll> pi;
typedef vector<ll> vi;
typedef vector<pi> vpi;
#define f first
#define s second
#define FOR(i, s, e) for (ll i = s; i <= ll(e); ++i)
#define DEC(i, s, e) for (ll i = s; i >= ll(e); --i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i, x) for (auto i : x)
#define mem(x, i) memset(x, i, sizeof x)
#define fast ios_base::sync_with_stdio(false), cin.tie(0)
typedef long double ld;
#define MOD 1000000007
#define int ll
int N;
#define maxn 200001

map<pi, int> num;

ll pow2[maxn];

int gcd(int a, int b) {
  if (a == 0)
    return b;
  if (b == 0)
    return a;

  if (a > b)
    return gcd(a - b, b);
  else
    return gcd(a, b - a);
}

pi simp(pi x) {
  if (x.s < 0)
    x.f = -x.f, x.s = -x.s;

  int a = gcd(abs(x.f), abs(x.s));
  return pi(x.f / a, x.s / a);
}

int32_t main() {
  fast;

  cin >> N;

  FOR(i, 1, N) {
    ld a, b;
    cin >> a >> b;
    num[simp(pi(a, b))]++;
  }

  pow2[0] = 1;
  FOR(i, 1, N) pow2[i] = (pow2[i - 1] * 2) % MOD;

  ll ans = 1;
  aFOR(i, num) {
    pi cur = i.f;
    pi x = simp(pi(-cur.s, cur.f));

    // cout<<i.f<<' '<<x<
    // cout<<i.f<<' '<<i.s<<' '<<num[x]<<'\\n';
    ans *= (pow2[num[i.f]] + pow2[num[x]] - 1) % MOD;
    ans %= MOD;
    if (num.find(x) != num.end())
      num[x] = 0;
    num[i.f] = 0;
  }

  cout << ans - 1;
}
Problem p02679 (C++) — buggy submission, verdict: Runtime Error

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

const ll mod = 1000000007;

// 2^t
ll pow(ll t) {
  if (!t)
    return 1LL;
  ll a = pow(t >> 1);
  a *= a;
  a %= mod;
  if (t & 1)
    a *= 2LL;
  return a % mod;
}

ll gcd(ll a, ll b) {
  if (a < b)
    swap(a, b);
  if (a % b == 0)
    return b;
  return gcd(b, a % b);
}

int main() {
  ll n;
  cin >> n;

  ll zz = 0;

  map<pair<ll, ll>, ll> mem;
  set<pair<ll, ll>> MM;

  for (int i = 0; i < n; i++) {
    ll a, b;
    cin >> a >> b;

    if (a == 0 && b == 0)
      zz++;
    else if (a == 0)
      mem[make_pair(0, 1)]++;
    else if (b == 0)
      mem[make_pair(1, 0)]++;
    else {
      bool neg = false;
      if ((a < 0 && b > 0) || (a > 0 && b < 0)) {
        neg = true;
      }
      a = abs(a);
      b = abs(b);
      ll g = gcd(a, b);
      if (neg)
        mem[make_pair(a / g, -b / g)]++;
      else
        mem[make_pair(a / g, b / g)]++;
    }
  }

  ll ans = 1LL;
  ll cnt = zz;
  for (auto x : mem) {
    ll a, b;
    tie(a, b) = x.first;
    if (b > 0LL) {
      if (mem.count(make_pair(b, -a))) {
        ll i = x.second, j = mem[make_pair(b, -a)];
        ans *= (pow(i) + pow(j) - 1LL + mod) % mod;
        ans %= mod;
        cnt += i + j;
      }
    }
  }

  ans *= pow(n - cnt);
  ans = (ans % mod + zz - 1LL + mod) % mod;

  cout << ans << endl;

  return 0;
}

Error: 0

Fixed submission:

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

const ll mod = 1000000007;

// 2^t
ll pow(ll t) {
  if (!t)
    return 1;
  ll a = pow(t >> 1);
  a *= a;
  a %= mod;
  if (t & 1)
    a *= 2LL;
  return a % mod;
}

ll gcd(ll a, ll b) {
  if (a < b)
    swap(a, b);
  if (a % b == 0)
    return b;
  return gcd(b, a % b);
}

int main() {
  ll n;
  cin >> n;

  ll zz = 0;

  map<pair<int, int>, int> mem;

  for (int i = 0; i < n; i++) {
    ll a, b;
    cin >> a >> b;

    if (a == 0 && b == 0)
      zz++;
    else if (a == 0)
      mem[make_pair(0, 1)]++;
    else if (b == 0)
      mem[make_pair(1, 0)]++;
    else {
      bool neg = false;
      if (a * b < 0) {
        neg = true;
      }
      a = abs(a);
      b = abs(b);
      ll g = gcd(a, b);
      if (neg)
        mem[make_pair(a / g, -b / g)]++;
      else
        mem[make_pair(a / g, b / g)]++;
    }
  }

  ll ans = 1;
  ll cnt = zz;
  for (auto x : mem) {
    ll a, b;
    tie(a, b) = x.first;
    if (b > 0) {
      if (mem.count(make_pair(b, -a))) {
        ll i = x.second, j = mem[make_pair(b, -a)];
        ans *= (pow(i) + pow(j) - 1LL + mod) % mod;
        ans %= mod;
        cnt += i + j;
      }
    }
  }
  ans *= pow(n - cnt - zz);
  ans = (ans + zz - 1 + mod) % mod;

  cout << ans << endl;

  return 0;
}
Problem p02679 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll N;
map<P, P> AA;
ll ans = 1;
ll gcd(ll a, ll b) {
  while (1) {
    if (a < b)
      swap(a, b);
    if (!b)
      break;
    a %= b;
  }
  return a;
}
ll M = 1000000007;
ll mpow(ll x,
        ll n) { // x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
  ll anss = 1;
  while (n != 0) {
    if (n & 1)
      anss = anss * x % M;
    x = x * x % M;
    n = n >> 1;
  }
  return anss;
}

int main() {
  cin >> N;
  ll k;
  ll zeros = 0;
  for (int i = 0; i < N; i++) {
    ll A, B;
    cin >> A >> B;
    if (A == 0 && B == 0) {
      zeros++;
      continue;
    }
    k = gcd(abs(A), abs(B));
    A = A / k;
    B = B / k;
    if (B < 0) {
      B = -B;
      A = -A;
    } else if (B == 0) {
      A = 1;
    }
    if (A == 0) {
      B = 1;
    }
    if (A > 0) {
      AA[P(A, B)].first += 1;
    } else {
      AA[P(B, -A)].second += 1;
    }
  }
  for (auto p : AA) {
    ans = (ans *
           (mpow(2, AA[p.first].first) + mpow(2, AA[p.first].second) - 1) % M) %
          M;
  }
  ans = (ans + M + zeros - 1) % M;
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll N;
map<P, P> AA;
ll ans = 1;
ll INF = 10000000000000009;
ll gcd(ll a, ll b) {
  while (1) {
    if (a < b)
      swap(a, b);
    if (!b)
      break;
    a %= b;
  }
  return a;
}
ll M = 1000000007;
ll mpow(ll x,
        ll n) { // x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
  ll anss = 1;
  while (n != 0) {
    if (n & 1)
      anss = anss * x % M;
    x = x * x % M;
    n = n >> 1;
  }
  return anss;
}

int main() {
  cin >> N;
  ll zeros = 0;
  for (int i = 0; i < N; i++) {
    ll A, B;
    cin >> A >> B;
    ll n = gcd(abs(A), abs(B));
    A = A / n;
    B = B / n;
    if (A == 0 && B == 0) {
      zeros++;
    } else {
      if (B < 0) {
        B = -B;
        A = -A;
      } else if (B == 0) {
        A = 1;
      }
      if (A == 0) {
        B = 1;
      }
      if (A > 0) {
        AA[P(A, B)].first += 1;
      } else {
        AA[P(B, -A)].second += 1;
      }
    }
  }
  for (auto p : AA) {
    ans = (ans *
           (mpow(2, AA[p.first].first) + mpow(2, AA[p.first].second) - 1) % M) %
          M;
  }
  cout << (ans + zeros - 1) % M << endl;
}