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

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

const ll mod = 1e9 + 7;
const ll mask = 1e9;

using node = tuple<ll, ll, ll>;

ll p2[300000];

void init_p2() {
  p2[0] = 1;
  for (int i = 1; i < 300000; ++i) {
    p2[i] = (p2[i - 1] * 2) % mod;
  }
}

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

int main(void) {
  init_p2();
  map<node, int> m;
  int n;
  cin >> n;
  auto fish = vector<node>(n);
  for (int i = 0; i < n; ++i) {
    ll a, b;
    cin >> a >> b;

    node f;
    if (a == 0 && b == 0) {
      f = node{0, 0, 0};
    } else if (a == 0) {
      f = node{1, 0, 0};
    } else if (b == 0) {
      f = node{0, 1, 0};
    } else {
      ll abs_a = (ll)abs(a), abs_b = (ll)abs(b);
      ll g = gcd(abs_a, abs_b);
      ll s = (a / abs_a) * (b / abs_b);
      f = node{abs_a / g, abs_b / g, s};
    }
    fish[i] = f;
    m[f]++;
  }

  ll res = 1LL;
  for (int i = 0; i < n; ++i) {
    ll a, b, s;
    tie(a, b, s) = fish[i];
    if (a == 0 && b == 0) {
      continue;
    }
    node inv = node{b, a, -s};
    if (m.find(inv) == m.end()) {
      res = (res * 2) % mod;
    }
  }

  for (auto kv : m) {
    ll a, b, s;
    tie(a, b, s) = kv.first;
    if (a == 0 && b == 0) {
      continue;
    }

    node inv = node{b, a, -s};
    if (m.find(inv) == m.end()) {
      continue;
    }
    if (s == 0 && a == 0) {
      continue;
    }
    if (s < 0) {
      continue;
    }

    int n_pos = kv.second;
    int n_neg = m[inv];
    ll mult = (p2[n_pos] - 1LL + p2[n_neg] - 1LL + 1LL) % mod;
    res = (res * mult) % mod;
  }

  res = (res + m[node{0, 0, 0}]) % mod;

  cout << (res + mod - 1LL) % mod << endl;
  return 0;
}


Error: 0

Fixed submission:

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

const ll mod = 1e9 + 7;
const ll mask = 1e9;

using node = tuple<ll, ll, ll>;

ll p2[300000];

void init_p2() {
  p2[0] = 1;
  for (int i = 1; i < 300000; ++i) {
    p2[i] = (p2[i - 1] * 2) % mod;
  }
}

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

int main(void) {
  init_p2();
  map<node, int> m;
  int n;
  cin >> n;
  auto fish = vector<node>(n);
  for (int i = 0; i < n; ++i) {
    ll a, b;
    cin >> a >> b;
    ll abs_a = (ll)abs(a), abs_b = (ll)abs(b);
    ll g = gcd(abs_a, abs_b);
    ll s = (a / abs_a) * (b / abs_b);
    node f = node{abs_a / g, abs_b / g, s};
    fish[i] = f;
    m[f]++;
  }

  ll res = 1LL;
  for (int i = 0; i < n; ++i) {
    ll a, b, s;
    tie(a, b, s) = fish[i];
    node inv = node{b, a, -s};
    if (m.find(inv) == m.end()) {
      res = (res * 2) % mod;
    }
  }

  for (auto kv : m) {
    ll a, b, s;
    tie(a, b, s) = kv.first;
    node inv = node{b, a, -s};
    if (m.find(inv) == m.end() || s < 0) {
      continue;
    }
    int n_pos = kv.second;
    int n_neg = m[inv];
    ll mult = (p2[n_pos] - 1LL + p2[n_neg] - 1LL + 1LL) % mod;
    res = (res * mult) % mod;
  }

  cout << res - 1LL << endl;
  return 0;
}
Problem p02679 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
ll kai[200005];

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll mkai(int n) {
  if (n == 0)
    return kai[0] = 1;
  if (n % 2)
    return kai[n] = mkai(n / 2) * mkai(n / 2) * 2 % MOD;
  else
    return kai[n] = mkai(n / 2) * mkai(n / 2) % MOD;
}

int main() {
  int n;
  cin >> n;
  map<P, int> mp;
  ll mp00 = 0;
  for (int i = 0; i < n; ++i) {
    ll a, b;
    cin >> a >> b;
    if (a < 0) {
      a *= -1;
      b *= -1;
    }
    if (a == 0 && b == 0)
      ++mp00;
    else if (b == 0)
      ++mp[make_pair(1, 0)];
    else if (a == 0)
      ++mp[make_pair(0, -1)];
    else if (b < 0) {
      b *= -1;
      ++mp[make_pair(a / gcd(a, b), b / gcd(a, b) * (-1))];
    } else
      ++mp[make_pair(a / gcd(a, b), b / gcd(a, b))];
  }
  ll ans = 1;
  for (auto [ab, value] : mp) {
    ll a = ab.first, b = ab.second;
    P np;
    if (b < 0)
      np = make_pair(b * (-1), a);
    else
      np = make_pair(b, a * (-1));
    // cout << a << " " << b << " " << value << endl;
    // cout << mkai(value) << " " << mkai(mp[np]) << endl;
    ans *= (mkai(value) + mkai(mp[np]) - 1) % MOD;
    mp.erase(np);
    ans %= MOD;
    // cout << ans << endl;
  }
  ans += mp00 % MOD;
  ans -= 1;
  if (ans < 0)
    ans += MOD;
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
int kai[20005];

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll mkai(int n) {
  if (n == 0)
    return kai[0] = 1;
  if (n % 2)
    return kai[n] = mkai(n / 2) * mkai(n / 2) * 2 % MOD;
  else
    return kai[n] = mkai(n / 2) * mkai(n / 2) % MOD;
}

int main() {
  int n;
  cin >> n;
  map<P, int> mp;
  ll mp00 = 0;
  for (int i = 0; i < n; ++i) {
    ll a, b;
    cin >> a >> b;
    if (a < 0) {
      a *= -1;
      b *= -1;
    }
    if (a == 0 && b == 0)
      ++mp00;
    else if (b == 0)
      ++mp[make_pair(1, 0)];
    else if (a == 0)
      ++mp[make_pair(0, -1)];
    else if (b < 0) {
      b *= -1;
      ++mp[make_pair(a / gcd(a, b), b / gcd(a, b) * (-1))];
    } else
      ++mp[make_pair(a / gcd(a, b), b / gcd(a, b))];
  }
  ll ans = 1;
  for (auto [ab, value] : mp) {
    ll a = ab.first, b = ab.second;
    P np;
    if (b < 0)
      np = make_pair(b * (-1), a);
    else
      np = make_pair(b, a * (-1));
    // cout << a << " " << b << " " << value << endl;
    // cout << mkai(value) << " " << mkai(mp[np]) << endl;
    ans *= (mkai(value) + mkai(mp[np]) - 1) % MOD;
    mp.erase(np);
    ans %= MOD;
    // cout << ans << endl;
  }
  ans += mp00 % MOD;
  cout << ans - 1 << endl;
}
Problem p02679 (C++) — buggy submission, verdict: Runtime Error

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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/e.in", "r", stdin);
//  freopen("../IO/e.out", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}

constexpr int P = 1000'000'007;

int64_t gcd(int64_t a, int64_t b) {
  while (b != 0) {
    tie(a, b) = make_pair(b, a % b);
  }
  return a;
}

void solve(std::istream &in, std::ostream &out) {
  int n;
  in >> n;
  int z = 0;
  map<pair<int64_t, int64_t>, int> m1, m2;
  for (int i = 0; i < n; ++i) {
    int64_t x, y;
    in >> x >> y;
    if (x == 0 && y == 0) {
      ++z;
      continue;
    }
    if (y < 0) {
      x = -x;
      y = -y;
    }
    int64_t g = gcd(abs(x), abs(y));
    x /= g;
    y /= g;
    m1[{x, y}]++;
    if (x >= 0) {
      m2[{-y, x}]++;
    } else {
      m2[{y, -x}]++;
    }
  }
  vector<int> p2(1, 1);
  while (p2.size() < n + 100) {
    p2.push_back(p2.back() * 2 % P);
  }
  int64_t res = 1;
  for (auto &[x, y] : m1) {
    auto [a, b] = x;
    int64_t a1 = -b, b1 = a;
    if (b1 <= 0) {
      a1 = -a1;
      b1 = -b1;
    }
    //    cout << a << ' ' << b << ": ";
    res *= (p2[y] + p2[m1[{a1, b1}]] - 1);
    res %= P;
    m1[{a1, b1}] = 0;
    m1[{a, b}] = 0;
  }
  out << (z + res + P - 1) % P << '\\n';
}


Error: 0

Fixed submission:

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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/e.in", "r", stdin);
//  freopen("../IO/e.out", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}

constexpr int P = 1000'000'007;

int64_t gcd(int64_t a, int64_t b) {
  while (b != 0) {
    tie(a, b) = make_pair(b, a % b);
  }
  return a;
}

void solve(std::istream &in, std::ostream &out) {
  int n;
  in >> n;
  int z = 0;
  map<pair<int64_t, int64_t>, int> m1, m2;
  for (int i = 0; i < n; ++i) {
    int64_t x, y;
    in >> x >> y;
    if (x == 0 && y == 0) {
      ++z;
      continue;
    }
    if (y < 0) {
      x = -x;
      y = -y;
    }
    if (x == 0 || y == 0)
      assert(false);
    if (x == 0)
      y = 1;
    if (y == 0)
      x = 1;
    int64_t g = gcd(abs(x), abs(y));
    x /= g;
    y /= g;
    m1[{x, y}]++;
    if (x >= 0) {
      m2[{-y, x}]++;
    } else {
      m2[{y, -x}]++;
    }
  }
  vector<int> p2(1, 1);
  while (p2.size() < n + 100) {
    p2.push_back(p2.back() * 2 % P);
  }
  int64_t res = 1;

  for (auto &[x, y] : m1) {
    auto [a, b] = x;
    int64_t a1 = -b, b1 = a;
    if (b1 < 0) {
      a1 = -a1;
      b1 = -b1;
    }
    //    cout << a << ' ' << b << ": ";
    res *= (p2[y] + p2[m1[{a1, b1}]] - 1);
    res %= P;
    m1[{a1, b1}] = 0;
    m1[{a, b}] = 0;
  }
  out << (z + res + P - 1) % P << '\\n';
}
Problem p02679 (C++) — buggy submission, verdict: Runtime Error

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

long long gcd(long long a, long long b) {
  if (a % b == 0)
    return b;
  return gcd(b, a % b);
}

long long w[400010];

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  constexpr int mod = 1000000007;
  w[0] = 1;
  for (int i = 0; i < 400000; i++) {
    w[i + 1] = w[i] * 2 % mod;
  }

  int N;
  cin >> N;
  long long Z = 0, AZ = 0, BZ = 0;
  map<pair<long long, long long>, long long> Mp, Mm;
  for (int i = 0; i < N; i++) {
    long long a, b;
    cin >> a >> b;
    if (a < 0)
      a *= -1, b *= -1;
    if (a == 0 || b == 0) {
      if (a == 0)
        AZ++;
      if (b == 0)
        BZ++;
      if (a == 0 && b == 0)
        Z++;
      continue;
    }
    long long g = gcd(a, abs(b));
    a /= g, b /= g;
    if (b > 0)
      Mp[{a, b}]++;
    else
      Mm[{-b, a}]++;
  }

  long long nz = 1;
  for (auto &[p, c] : Mp) {
    auto d = Mm[p];
    nz *= (w[c] + w[d] - 1) % mod;
    nz %= mod;
  }

  for (auto &[p, c] : Mm) {
    if (Mp.count(p))
      continue;
    nz *= w[c];
    nz %= mod;
  }

  long long ans = (nz - 1 + mod) % mod;
  ans += nz * (w[AZ - Z] - 1) % mod;
  ans += nz * (w[BZ - Z] - 1) % mod;
  ans += Z;

  cout << (ans + mod) % mod << "\\n";

  return 0;
}

Error: 0

Fixed submission:

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

long long gcd(long long a, long long b) {
  if (a % b == 0)
    return b;
  return gcd(b, a % b);
}

long long w[400010];

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  constexpr int mod = 1000000007;
  w[0] = 1;
  for (int i = 0; i < 400000; i++) {
    w[i + 1] = w[i] * 2 % mod;
  }

  int N;
  cin >> N;
  long long Z = 0, AZ = 0, BZ = 0;
  map<pair<long long, long long>, long long> Mp, Mm;
  for (int i = 0; i < N; i++) {
    long long a, b;
    cin >> a >> b;
    if (a < 0)
      a *= -1, b *= -1;
    if (a == 0 || b == 0) {
      if (a == 0)
        AZ++;
      if (b == 0)
        BZ++;
      if (a == 0 && b == 0)
        Z++;
    }
    long long g = gcd(a, abs(b));
    a /= g, b /= g;
    if (b > 0)
      Mp[{a, b}]++;
    else
      Mm[{-b, a}]++;
  }

  long long nz = 1;
  for (auto &[p, c] : Mp) {
    auto d = Mm[p];
    nz *= (w[c] + w[d] - 1) % mod;
    nz %= mod;
  }

  for (auto &[p, c] : Mm) {
    if (Mp.count(p))
      continue;
    nz *= w[c];
    nz %= mod;
  }

  long long ans = nz - 1;
  ans += nz * (w[AZ - Z] - 1) % mod;
  ans += nz * (w[BZ - Z] - 1) % mod;
  ans += Z;

  cout << ans % mod << "\\n";

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

#include <bits/stdc++.h>

using namespace std;

constexpr auto MOD = 1000000007LL;

// a^n mod m を計算する(繰り返し二乗法,二分累乗法:O(logn)) (再帰版)
long long modpow(long long a, long long n) {
  return n ? modpow(a * a % MOD, n / 2) * (n % 2 ? a : 1) % MOD : 1;
}

// // MOD考慮power関数
// inline long long modpow(long long a,long long n)
// {
// 	long long ret=1;
// 	for(long long i=0;i<n;i++){
// 		ret*=a;
// 		ret%=MOD;
// 	}
// 	return ret;
// }

// gcd関数
// inline long long gcd(long long a, long long b)
// {
// 	if(a<b) swap(a,b);
// 	if(a%b==0) return b;
// 	else return gcd(b,a%b);
// }

int main() {
  int n;
  cin >> n;
  long long zero = 0;
  map<pair<long long, long long>, vector<int>> bad;
  while (n--) {
    long long x, y;
    cin >> x >> y;

    // 両方0ならカウントしてcontinue
    if (x == 0 && y == 0) {
      zero++;
      continue;
    }

    // 既約分数計算
    long long g = gcd(x, y);
    x /= g;
    y /= g;

    // 符号情報を統一
    if (y < 0)
      x = -x, y = -y;
    if (y == 0 && x < 0)
      x = -x, y = -y;

    int rotate90 = (x <= 0);
    if (rotate90) {
      swap(x, y);
      y = -y;
    }

    if (bad.count({x, y}) == 0)
      bad[{x, y}] = {0, 0};
    bad[{x, y}][rotate90]++;
  }

  // 組み合わせ計算
  long long ans = 1;
  for (auto x : bad) {
    vector<int> c = x.second;
    ans *= (modpow(2, c[0]) - 1) + (modpow(2, c[1]) - 1) + 1;
    ans %= MOD;
  }

  ans += zero - 1;
  ans = (ans + MOD) % MOD;
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

constexpr auto MOD = 1000000007LL;

// a^n mod m を計算する(繰り返し二乗法,二分累乗法:O(logn)) (再帰版)
long long modpow(long long a, long long n) {
  return n ? modpow(a * a % MOD, n / 2) * (n % 2 ? a : 1) % MOD : 1;
}

// // MOD考慮power関数
// inline long long modpow(long long a,long long n)
// {
// 	long long ret=1;
// 	for(long long i=0;i<n;i++){
// 		ret*=a;
// 		ret%=MOD;
// 	}
// 	return ret;
// }

// gcd関数
inline long long gcd(long long a, long long b) {
  if (a < b)
    swap(a, b);
  if (a % b == 0)
    return b;
  else
    return gcd(b, a % b);
}

int main() {
  int n;
  cin >> n;
  long long zero = 0;
  map<pair<long long, long long>, vector<int>> bad;
  while (n--) {
    long long x, y;
    cin >> x >> y;

    // 両方0ならカウントしてcontinue
    if (x == 0 && y == 0) {
      zero++;
      continue;
    }

    // 既約分数計算
    long long g = gcd(x, y);
    x /= g;
    y /= g;

    // 符号情報を統一
    if (y < 0)
      x = -x, y = -y;
    if (y == 0 && x < 0)
      x = -x, y = -y;

    int rotate90 = (x <= 0);
    if (rotate90) {
      swap(x, y);
      y = -y;
    }

    if (bad.count({x, y}) == 0)
      bad[{x, y}] = {0, 0};
    bad[{x, y}][rotate90]++;
  }

  // 組み合わせ計算
  long long ans = 1;
  for (auto x : bad) {
    vector<int> c = x.second;
    ans *= (modpow(2, c[0]) - 1) + (modpow(2, c[1]) - 1) + 1;
    ans %= MOD;
  }

  ans += zero - 1;
  ans = (ans + MOD) % MOD;
  cout << ans << endl;
}
Problem p02679 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <map>
#define int long long
using namespace std;
map<pair<int, int>, int> t;
int N;
int arr[200100][4];
int po[200100];
int gc(int a, int b) { return b ? gc(b, a % b) : a; }
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N;
  int i;
  int rr = 0;
  for (i = 0; i <= N; i++) {
    if (!i)
      po[i] = 1;
    else
      po[i] = po[i - 1] * 2 % 1000000007;
  }
  int ans = 1;
  for (i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    if ((a == 0) && (b == 0)) {
      rr++;
      continue;
    }

    int c = 0;
    while (!((a >= 0) && (b > 0))) {
      c++;
      int r = a;
      a = -b;
      b = r;
    }

    int x = gc(a, b);
    a /= x;
    b /= x;
    int r = t[{a, b}];
    if (r) {
      arr[r][c]++;
    } else {
      t[{a, b}] = t.size();
      arr[t.size()][c]++;
    }
  }
  N = t.size();

  for (i = 1; i <= N; i++) {
    int th = (po[arr[i][0] + arr[i][2]] + po[arr[i][1] + arr[i][3]] - 1) %
             1000000007;
    ans = ans * th % 1000000007;
  }
  cout << (ans + rr + 1000000006) % 1000000007;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#define int long long
using namespace std;
map<pair<int, int>, int> t;
int N;
int arr[200100][4];
int po[200100];
int gc(int a, int b) { return b ? gc(b, a % b) : a; }
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N;
  int i;
  for (i = 0; i <= N; i++) {
    if (!i)
      po[i] = 1;
    else
      po[i] = po[i - 1] * 2 % 1000000007;
  }
  int ans = 1;
  for (i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    if (a == 0 && b == 0)
      ans++;
    int c = 0;
    while (!((a >= 0) && (b > 0))) {
      c++;
      int r = a;
      a = -b;
      b = r;
    }

    int x = gc(a, b);
    a /= x;
    b /= x;
    int r = t[{a, b}];
    if (r) {
      arr[r][c]++;
    } else {
      t[{a, b}] = t.size();
      arr[t.size()][c]++;
    }
  }
  N = t.size();

  for (i = 1; i <= N; i++) {
    int th = (po[arr[i][0] + arr[i][2]] + po[arr[i][1] + arr[i][3]] - 1) %
             1000000007;
    ans = ans * th % 1000000007;
  }
  cout << (ans + 1000000006) % 1000000007;
}
Problem p02679 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
/*
gcdとって簡略化するかな
0の考慮ぬけてんのか
ペアになるとりかたで１まとまりと考えるか
1 0
1 0
1 0
0 1
0 1
なら、この5個で１かたまり、
1 0=2^3
0 1=2^2
=12通りから全部とらないが重複してるから-1=11通り
*/

int main() {
  ll N, MOD = 1e9 + 7, zero = 0, ans = 1;
  cin >> N;
  map<pair<ll, ll>, ll> M;
  vector<ll> Z(N + 1, 2);
  Z[0] = 1;
  for (ll i = 1; i <= N; i++)
    (Z[i] *= Z[i - 1]) %= MOD;
  // まずmapつくる
  for (ll i = 0; i < N; i++) {
    ll a, b;
    cin >> a >> b;
    if (a == 0 && b == 0) {
      zero++;
      continue;
    }
    if (a != 0 && b != 0) {
      ll c = __gcd(a, b);
      a /= c;
      b /= c;
      M[make_pair(a, b)]++;
    } else if (a == 0)
      M[make_pair(0, 1)]++;
    else if (b == 0)
      M[make_pair(1, 0)]++;
  }
  // 数え上げ
  for (auto v : M) { // 0 0は除外
    ll val1 = v.second;
    if (val1 == -1)
      continue;
    ll a = v.first.first;
    ll b = v.first.second;
    ll val2 = 0;
    if (a != 0 && b != 0) {
      val2 += M[make_pair(b, -a)];
      val2 += M[make_pair(-b, a)];
    } else if (a == 0)
      val2 += M[make_pair(1, 0)];
    else if (b == 0)
      val2 += M[make_pair(0, 1)];
    (ans *= (Z[val1] + Z[val2] - 1LL) % MOD) %=
        MOD; // どちらもとらないが重複で-1 or Z[0]=1が余分
    if (a != 0 && b != 0) {
      M[make_pair(b, -a)] = -1;
      M[make_pair(-b, a)] = -1;
    } else {
      M[make_pair(1, 0)] = -1;
      M[make_pair(0, 1)] = -1;
    }
  }
  ans--;
  ans += zero;
  if (ans < 0)
    ans += MOD;
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
/*
gcdとって簡略化するかな
*/

long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0)
    u += m;
  return u;
}

int main() {
  ll N, MOD = 1e9 + 7, ans = 1;
  cin >> N;
  map<pair<ll, ll>, ll> M;
  vector<ll> Z(N + 1, 2), INV(N + 1, 0);
  Z[0] = 1;
  for (ll i = 1; i <= N; i++)
    (Z[i] *= Z[i - 1]) %= MOD;
  for (ll i = 1; i <= N; i++)
    (INV[i] = modinv(Z[i], MOD)) %= MOD;
  for (ll i = 0; i < N; i++) {
    ll a, b;
    cin >> a >> b;
    ll c = __gcd(a, b);
    if (c < 0)
      c *= -1;
    a /= c;
    b /= c;
    M[make_pair(a, b)]++;
    ll tmp = 0;
    tmp += M[make_pair(-b, a)];
    tmp += M[make_pair(b, -a)];
    if (tmp > 0) {
      ll work = ans;
      (work *= INV[tmp]) %= MOD;
      (ans += work) %= MOD;
    } else
      (ans *= 2) %= MOD;
  }
  ans--;
  if (ans < 0)
    ans += MOD;
  cout << ans << endl;
}
Problem p02679 (C++) — buggy submission, verdict: Runtime Error

// Version.20.09.25.05.17.20.
#include <bits/stdc++.h>
#define pll pair<ll, ll>
using namespace std;
const int mod = 1e9 + 7;
typedef long long ll;

inline int fsp(int x, int k = mod - 2) {
  int res = 1;
  while (k) {
    if (k & 1)
      res = 1ll * res * x % mod;
    x = 1ll * x * x % mod, k >>= 1;
  }
  return res;
}

int n;
map<pll, int> num;
pll now[200200];

int main() {
#ifdef isLOCAL
  freopen(".in", "r", stdin);
  freopen(".out", "w", stdout);
#endif

  cin >> n;
  int aa = 0, bb = 0, cc = 0;
  for (int i = 1; i <= n; ++i) {
    long long x, y, g;
    scanf("%lld%lld", &x, &y);
    if (!x || !y) {
      if (!x && !y)
        ++cc;
      else if (!x)
        ++aa;
      else if (!y)
        ++bb;
      --i, --n;
      continue;
    }
    g = __gcd(abs(x), abs(y));
    if (x < 0)
      x = -x, y = -y;
    x /= g, y /= g;
    num[now[i] = make_pair(x, y)]++;
  }

  int ans = (fsp(2, aa) + fsp(2, bb) - 1) % mod;
  for (int i = 1; i <= n; ++i) {
    if (!num[now[i]])
      continue;
    pll tmp = make_pair(-now[i].second, now[i].first);
    if (tmp.first < 0)
      tmp.first *= -1, tmp.second *= -1;
    int x = num[now[i]], y = num[tmp];
    num[now[i]] = num[tmp] = 0;
    int t = (fsp(2, x) + fsp(2, y) - 1) % mod;
    ans = 1ll * ans * t % mod;
  }

  ans = (ans - 1 + cc) % mod;
  if (ans < 0)
    ans += mod;
  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

// Version.20.09.25.05.17.20.
#include <bits/stdc++.h>
#define pll pair<ll, ll>
using namespace std;
const int mod = 1e9 + 7;
typedef long long ll;

inline int fsp(int x, int k = mod - 2) {
  int res = 1;
  while (k) {
    if (k & 1)
      res = 1ll * res * x % mod;
    x = 1ll * x * x % mod, k >>= 1;
  }
  return res;
}

int n;
map<pll, int> num;
pll now[200200];

int main() {
#ifdef isLOCAL
  freopen(".in", "r", stdin);
  freopen(".out", "w", stdout);
#endif

  cin >> n;
  for (int i = 1; i <= n; ++i) {
    long long x, y, g;
    scanf("%lld%lld", &x, &y);
    g = __gcd(abs(x), abs(y));
    if (x < 0)
      x = -x, y = -y;
    x /= g, y /= g;
    num[now[i] = make_pair(x, y)]++;
  }

  int ans = 1;
  for (int i = 1; i <= n; ++i) {
    if (!num[now[i]])
      continue;
    pll tmp = make_pair(-now[i].second, now[i].first);
    if (tmp.first < 0)
      tmp.first *= -1, tmp.second *= -1;
    int x = num[now[i]], y = num[tmp];
    num[now[i]] = num[tmp] = 0;
    int t = (fsp(2, x) + fsp(2, y) - 1) % mod;
    ans = 1ll * ans * t % mod;
  }

  cout << (ans - 1 + mod) % mod << endl;

  return 0;
}