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

#include <bits/stdc++.h>
#include <math.h>
#include <vector>
using namespace std;
#define MAX 200005
#define MOD 1000000007
long long arr[MAX];
map<pair<long long, long long>, int> M;
set<pair<long long, long long>> S;
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int main() {
  pair<long long, long long> p, q;
  arr[0] = 1;
  int n, i, j;
  long long g;
  scanf("%d", &n);
  long long current = 0, ans = 1;
  for (i = 0; i < n; i++) {
    arr[i + 1] = (arr[i] * 2) % MOD;
    scanf("%lld %lld", &p.first, &p.second);
    g = gcd(abs(p.first), abs(p.second));
    if (g == 0) {
      current++;
      continue;
    }
    p.first = p.first / g;
    p.second = p.second / g;
    if (p.first < 0 || (p.first == 0 && p.second < 0)) {
      p.first = -p.first;
      p.second = -p.second;
    }
    j = S.size();
    S.insert(p);
    if (S.size() == j) {
      M[p]++;
    } else {
      M[p] = 1;
    }
  }
  long long zeros = current;
  while (S.size() > 0) {
    j = S.size();
    p = *(S.begin());
    current = arr[M[p]];
    q.first = p.second;
    q.second = -p.first;
    swap(p, q);
    if (p.first < 0 || (p.first == 0 && p.second < 0)) {
      p.first = -p.first;
      p.second = -p.second;
    }
    S.erase(p);
    if (S.size() < j) {
      current = (current + arr[M[p]] + MOD - 1) % MOD;
    }
    ans = (ans * current) % MOD;
    S.erase(q);
  }
  ans = (ans + zeros) % MOD;
  ans = (ans + MOD - 1) % MOD;
  printf("%lld", ans);
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#include <math.h>
#include <vector>
using namespace std;
#define MAX 100005
#define MOD 1000000007
long long arr[MAX];
map<pair<long long, long long>, int> M;
set<pair<long long, long long>> S;
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int main() {
  pair<long long, long long> p, q;
  arr[0] = 1;
  int n, i, j;
  long long g;
  scanf("%d", &n);
  long long current = 0, ans = 1;
  for (i = 0; i < n; i++) {
    arr[i + 1] = (arr[i] * 2) % MOD;
    scanf("%lld %lld", &p.first, &p.second);
    g = gcd(abs(p.first), abs(p.second));
    if (g == 0) {
      current++;
      continue;
    }
    p.first = p.first / g;
    p.second = p.second / g;
    if (p.first < 0 || (p.first == 0 && p.second < 0)) {
      p.first = -p.first;
      p.second = -p.second;
    }
    j = S.size();
    S.insert(p);
    if (S.size() == j) {
      M[p]++;
    } else {
      M[p] = 1;
    }
  }
  long long zeros = current;
  while (S.size() > 0) {
    j = S.size();
    p = *(S.begin());
    current = arr[M[p]];
    q.first = p.second;
    q.second = -p.first;
    swap(p, q);
    if (p.first < 0 || (p.first == 0 && p.second < 0)) {
      p.first = -p.first;
      p.second = -p.second;
    }
    S.erase(p);
    if (S.size() < j) {
      current = (current + arr[M[p]] + MOD - 1) % MOD;
    }
    ans = (ans * current) % MOD;
    S.erase(q);
  }
  ans = (ans + zeros) % MOD;
  ans = (ans + MOD - 1) % MOD;
  printf("%lld", ans);
  return 0;
}
Problem p02679 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define all(x) x.begin(), x.end()
#define FIO ios_base::sync_with_stdio(false), cin.tie(NULL);
#define N 200005
const int mod = 1000000007;
map<pair<ll, ll>, pair<int, int>> mp;
int n;
ll a[N], b[N];
ll p2[N];
int main() {
  FIO;
  p2[0] = 1;
  for (int i = 1; i < N; i++)
    p2[i] = (p2[i - 1] * 2) % mod;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i] >> b[i];
  ll x1 = 0, x2 = 0, y = 0;
  for (int i = 0; i < n; i++) {
    ll g = __gcd(a[i], b[i]);
    if (a[i] == 0 && b[i] == 0)
      y++;
    else if (a[i] == 0)
      x1++;
    else if (b[i] == 0)
      x2++;
    else {
      if ((a[i] > 0 && b[i] < 0) || (a[i] < 0 && b[i] > 0)) {
        mp[{abs(b[i] / g), abs(a[i] / g)}].second++;
      } else {
        mp[{abs(a[i] / g), abs(b[i] / g)}].first++;
      }
    }
  }
  ll ans = 1;
  for (auto v : mp) {
    ans = (ans * ((p2[v.second.first] + p2[v.second.second] - 1) % mod)) % mod;
  }
  ans = (ans * ((p2[x1] + p2[x2] - 1) % mod)) % mod;
  ans = (ans + y) % mod;
  cout << ((ans - 1) % mod + mod) % mod << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define all(x) x.begin(), x.end()
#define FIO ios_base::sync_with_stdio(false), cin.tie(NULL);
#define N 200005
const int mod = 1000000007;
map<pair<ll, ll>, pair<int, int>> mp;
int n;
ll a[N], b[N];
ll p2[N];
int main() {
  FIO;
  p2[0] = 1;
  for (int i = 1; i < N; i++)
    p2[i] = (p2[i - 1] * 2) % mod;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i] >> b[i];
  for (int i = 0; i < n; i++) {
    ll g = __gcd(a[i], b[i]);
    if ((a[i] > 0 && b[i] < 0) || (a[i] < 0 && b[i] > 0)) {
      mp[{abs(b[i] / g), abs(a[i] / g)}].second++;
    } else {
      mp[{abs(a[i] / g), abs(b[i] / g)}].first++;
    }
  }
  ll ans = 1;
  for (auto v : mp) {
    ans = (ans * ((p2[v.second.first] + p2[v.second.second] - 1) % mod)) % mod;
  }
  cout << ((ans - 1) % mod + mod) % mod << endl;
  return 0;
}
Problem p02679 (C++) — buggy submission, verdict: Runtime Error

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

const int N = 2e5 + 20, MOD = 1e9 + 7;

int n, zero, p[N];
long long a, b, ans = 1;
map<pair<long long, long long>, pair<int, int>> m;

int main() {
  p[0] = 1;
  for (int i = 1; i < N; i++)
    p[i] = (p[i - 1] * 2) % MOD;

  scanf("%d", &n);
  while (n--) {
    scanf("%lld%lld", &a, &b);

    if (a == 0 and b == 0) {
      zero++;
      continue;
    }

    long long g = __gcd(a, b);
    a /= g, b /= g;
    if (b < 0)
      a *= -1, b *= -1;
    if (a <= 0)
      m[{b, -a}].second++;
    else
      m[{a, b}].first++;
  }

  for (auto i : m) {
    auto pr = i.second;
    ans *= (p[pr.first] + p[pr.second] - 1ll) % MOD;
    ans %= MOD;
  }

  ans = (ans + zero - 1) % MOD;
  if (ans < 0)
    ans += MOD;
  printf("%lld", ans);
}

Error: 0

Fixed submission:

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

#define int long long int
#define vi vector<int>
#define vvi vector<vi>
#define read(a)                                                                \\
  for (int i = 0; i < n; i++)                                                  \\
    cin >> a[i];
#define print(a)                                                               \\
  for (int i = 0; i < n; i++)                                                  \\
    cout << a[i] << " ";
#define pb push_back
#define pql priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define pqlv priority_queue<vi>
#define pqsv priority_queue<vi, vvi, greater<vi>>
// #define endl '\\n'
#define N 2000005
#define MOD 1000000007

signed main() {
  int t = 1;
  // cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vi a(n), b(n);
    vi p(N);
    p[0] = 1;
    for (int i = 1; i < N; i++) {
      p[i] = (p[i - 1] * 2) % MOD;
    }
    map<vi, pair<int, int>> mp;
    int zero = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i] >> b[i];
      if (!a[i] && !b[i]) {
        zero++;
      }
      int g = __gcd(abs(a[i]), abs(b[i]));
      a[i] /= g;
      b[i] /= g;
      if (a[i] < 0) {
        a[i] *= -1;
        b[i] *= -1;
      }
      if (b[i] <= 0) {
        mp[{-b[i], a[i]}].second++;
      } else {
        mp[{a[i], b[i]}].first++;
      }
    }
    int ans = 1;
    for (auto &it : mp) {
      ans *= (p[it.second.first] + p[it.second.second] - 1 + MOD) % MOD;
    }
    cout << (ans + zero - 1 + MOD) % MOD << endl;
  }
}
Problem p02679 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MAX_N = 200005;
const ll MOD = 1e9 + 7;
ll A[MAX_N], B[MAX_N];
map<P, P> ab;

ll mygcd(ll a, ll b) {
  if (b == 0)
    return a;
  else
    return mygcd(b, a % b);
}

ll pow2(ll n) {
  if (n == 0)
    return ll(1);
  if (n == 1)
    return ll(2);
  if (n % 2 == 0) {
    ll p = pow2(n / 2);
    return p * p % MOD;
  } else {
    return 2 * pow2(n - 1) % MOD;
  }
}

int main() {
  ll N;
  cin >> N;
  rep(i, N) {
    cin >> A[i] >> B[i];
    ll g = mygcd(abs(A[i]), abs(B[i]));
    if (g != 0) {
      A[i] /= g;
      B[i] /= g;
    }
  }
  /*
  rep(i,N)
  {
          cout << A[i] << " " << B[i] << endl;
  }
  */
  ll ans = 1;
  ll cnt0 = 0;
  rep(i, N) {
    if (A[i] == 0 && B[i] == 0) {
      cnt0++;
      continue;
    }
    if (A[i] < 0 || (A[i] == 0 && B[i] < 0)) {
      A[i] *= -1;
      B[i] *= -1;
    }
    if (B[i] > 0)
      ab[P(A[i], B[i])].first++;
    else
      ab[P(ll(-1) * B[i], A[i])].second++;
  }
  for (auto i : ab) {
    ans = ans * (pow2(i.second.first) + pow2(i.second.second) + MOD - 1) % MOD;
    // cout << i.first.first << " " << i.first.second << " ";
    // cout << ans << endl;
  }
  ans = (ans + cnt0 + MOD - 1) % MOD;
  cout << ans << endl;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MAX_N = 200005;
const ll MOD = 1e9 + 7;
ll A[MAX_N], B[MAX_N];
vector<P> ab;

ll mygcd(ll a, ll b) {
  if (b == 0)
    return a;
  else
    return mygcd(b, a % b);
}

ll pow2(ll n) {
  if (n == 0)
    return ll(1);
  if (n == 1)
    return ll(2);
  if (n % 2 == 0) {
    ll p = pow2(n / 2);
    return p * p % MOD;
  } else {
    return 2 * pow2(n / 2) % MOD;
  }
}

int main() {
  ll N;
  cin >> N;
  rep(i, N) {
    cin >> A[i] >> B[i];
    ll g = mygcd(abs(A[i]), abs(B[i]));
    A[i] /= g, B[i] /= g;
  }
  /*
  rep(i,N)
  {
          cout << A[i] << " " << B[i] << endl;
  }
  */
  ll ans = 1;
  ab.push_back(P(A[0], B[0]));
  rep(i, N - 1) {
    ll cnt = 0;
    if (A[i + 1] == ll(0) && B[i + 1] == ll(0)) {
      ab.push_back(P(A[i + 1], B[i + 1]));
      continue;
    }
    cnt += upper_bound(ab.begin(), ab.end(), P(-1 * B[i + 1], A[i + 1])) -
           upper_bound(ab.begin(), ab.end(), P(-1 * B[i + 1], A[i + 1]));
    cnt += upper_bound(ab.begin(), ab.end(), P(B[i + 1], -1 * A[i + 1])) -
           upper_bound(ab.begin(), ab.end(), P(B[i + 1], -1 * A[i + 1]));
    // cout << cnt << endl;
    ans = (ans + pow2(i + 1 - cnt)) % MOD;
    ab.push_back(P(A[i + 1], B[i + 1]));
  }
  cout << ans << endl;
  return 0;
}
Problem p02679 (C++) — buggy submission, verdict: Runtime Error

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

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

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

  ll N;
  cin >> N;
  map<pair<ll, ll>, pair<ll, ll>> cnt;

  ll cnt00 = 0;
  for (ll i = 0; i < N; i++) {
    ll A, B;
    cin >> A >> B;
    if (A == 0 && B == 0) {
      cnt00++;
      continue;
    }

    ll g = GCD(abs(A), abs(B));
    A /= g, B /= g;
    if (A == 0) {
      cnt[{0, 0}].first++;
    } else if (B == 0) {
      cnt[{0, 0}].second++;
    } else {
      if (A < 0) {
        A = -A, B = -B;
      }
      if (B > 0)
        cnt[{A, B}].first++;
      else
        cnt[{-B, A}].second++;
    }
  }

  ll MOD = 1e9 + 7;
  vector<ll> pow2(200200, 0);
  pow2[0] = 1;
  for (ll i = 1; i < 200200; i++) {
    pow2[i] = (pow2[i - 1] * 2) % MOD;
  }

  ll ans = 1;
  for (auto p : cnt) {
    ans =
        (ans * (pow2[p.second.first] + pow2[p.second.second] - 1) % MOD) % MOD;
  }
  ans = (ans + cnt00 - 1 + MOD) % MOD;

  cout << ans << '\\n';
  return 0;
}

Error: 0

Fixed submission:

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

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

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

  ll N;
  cin >> N;
  vector<pair<ll, ll>> AB(N);
  for (ll i = 0; i < N; i++) {
    ll A, B;
    cin >> A >> B;
    if (A == 0 || B == 0) {
      AB[i] = make_pair(A, B);
    }
    ll g = GCD(abs(A), abs(B));
    AB[i] = make_pair(A / g, B / g);
  }

  vector<pair<double, ll>> frac(N);
  for (ll i = 0; i < N; i++) {
    double fa, fb;
    pair<ll, ll> p = AB[i];
    fa = (double)p.first, fb = (double)p.second;
    if (fa == 0 || fb == 0) {
      frac[i] = make_pair(0, i);
    } else {
      if (fa <= fb)
        swap(fa, fb);
      frac[i] = make_pair(abs(fa / fb), i);
    }
  }
  sort(frac.begin(), frac.end());

  // for (ll i = 0; i < N; i++) {
  //   cout << frac[i].first << ' ' << frac[i].second << '\\n';
  // }

  vector<ll> cnt(N, 0);
  pair<double, ll> p = frac[0];
  ll ix = 0;
  cnt[ix]++;
  for (ll i = 1; i < N; i++) {
    pair<double, ll> c = frac[i];
    ll pi = p.second, ci = c.second;
    if (c.first == 0) { // 分母か分子が0の場合
      if (AB[pi].first * AB[ci].first + AB[pi].second * AB[ci].second == 0) {
        cnt[ix]++; // 同じグループ
      } else {
        ix++;
        cnt[ix]++; // 別のグループ
      }
    } else { // 分母も分子も0でない。互いに素。
      if (c.first - p.first > 0.00001) { // 同じ値ではない。
        ix++;
        cnt[ix]++; // 別のグループ
      } else {
        ll A1 = AB[pi].first, B1 = AB[pi].second;
        ll A2 = AB[ci].first, B2 = AB[ci].second;
        ll q1 = B1 / A2, q2 = A1 / B2;
        if (q1 == -q2) {
          cnt[ix]++; // 同じグループ
        } else {
          ix++;
          cnt[ix]++; // 別のグループ
        }
      }
    }
    p = c;
  }

  ll ans = 1;
  ll MOD = 1e9 + 7;
  for (ll i = 0; i < N; i++) {
    if (cnt[i] == 0)
      break;
    ans = (ans * (cnt[i] + 1)) % MOD;
  }
  cout << ans - 1 << '\\n';
  return 0;
}
Problem p02679 (C++) — buggy submission, verdict: Time Limit Exceeded

// #define TIMER_
#include <bits/stdc++.h>
using namespace std;
#define rep(i, r) for (int i = 0; i < (r); i++)
#define pb push_back
#define ALL(a) a.begin(), a.end()
#define fastio                                                                 \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
// #define int long long
using ll = long long;
using ull = unsigned long long;
const long long mod = 1000000007;
long long pw[200200] = {1};

signed main() {
  fastio;
  map<pair<ll, ll>, pair<ll, ll>> chk;

  for (int i = 1; i < 200200; i++)
    pw[i] = (pw[i - 1] * 2) % mod;

  ll z = mod - 1;
  int n;
  cin >> n;
  while (n--) {
    ll a, b;
    cin >> a >> b;
    if (a == 0 && b == 0) {
      z++;
      continue;
    } else if (a == 0) {
      chk[make_pair(0, 1)].first++;
    } else if (b == 0) {
      chk[make_pair(0, 1)].second++;
    } else {
      ll g = __gcd(abs(a), abs(b));
      a /= g;
      b /= g;
      if (a * b > 0) {
        chk[make_pair(abs(a), abs(b))].first++;
      } else {
        chk[make_pair(abs(b), abs(a))].second++;
      }
    }
  }

  ll r = 1;
  for (auto &p : chk) {
    r = r * (pw[p.second.first] + pw[p.second.second] - 1) % mod;
  }

  cout << (z + r) % mod << "\\n";

#ifdef TIMER_
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\\n";
#endif
}


Error: TLE

Fixed submission:

// #define TIMER_
#include <bits/stdc++.h>
using namespace std;
#define rep(i, r) for (int i = 0; i < (r); i++)
#define pb push_back
#define ALL(a) a.begin(), a.end()
#define fastio                                                                 \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
// #define int long long
using ll = long long;
using ull = unsigned long long;
const long long mod = 1000000007;
long long pw[200200] = {1};

signed main() {
  fastio;
  map<pair<ll, ll>, pair<ll, ll>> chk;

  for (int i = 1; i < 200200; i++)
    pw[i] = (pw[i - 1] * 2) % mod;

  ll z = mod - 1;
  ll n;
  scanf("%d", &n);
  while (n--) {
    ll a, b;
    cin >> a >> b;
    if (a == 0 && b == 0) {
      z++;
      continue;
    } else if (a == 0) {
      chk[make_pair(0, 1)].first++;
    } else if (b == 0) {
      chk[make_pair(0, 1)].second++;
    } else {
      ll g = __gcd(abs(a), abs(b));
      a /= g;
      b /= g;
      if (a * b > 0) {
        chk[make_pair(abs(a), abs(b))].first++;
      } else {
        chk[make_pair(abs(b), abs(a))].second++;
      }
    }
  }

  ll r = 1;
  for (auto &p : chk) {
    r = r * (pw[p.second.first] + pw[p.second.second] - 1) % mod;
  }

  cout << (z + r) % mod << "\\n";

#ifdef TIMER_
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\\n";
#endif
}
Problem p02679 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
map<pair<long long, long long>, long long> mp;
map<pair<long long, long long>, bool> done;
long long modpow(long long x, long long e) {
  if (x == 1 || e == 0)
    return 1;
  long long c = modpow(x, e / 2);
  long long c1 = (c * c) % MOD;
  if (e % 2 == 0)
    return c1;
  else
    return (c1 * x) % MOD;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  set<pair<long long, long long>> s;
  long long z1 = 0, z2 = 0, z0 = 0;
  for (int i = 1; i <= n; i++) {
    long long a, b;
    cin >> a >> b;
    if (a == 0 && b == 0) {
      z0++;
    } else if (a == 0) {
      z1++;
    } else if (b == 0) {
      z2++;
    } else {
      long long g = __gcd(a, b);
      mp[{-a / g, -b / g}]++;
      mp[{a / g, b / g}]++;
      s.insert({a / g, b / g});
    }
  }
  long long fans = 1;
  for (auto p : s) {
    if (done[p])
      continue;
    long long ans = modpow(2, mp[p]) + modpow(2, mp[{-p.second, p.first}]) - 1;
    done[p] = true;
    done[{-p.second, p.first}] = true;
    done[{p.second, -p.first}] = true;
    done[{-p.first, -p.second}] = true;
    fans = (fans * ans) % MOD;
  }
  long long mul = modpow(2, z1) + modpow(2, z2) - 1;
  fans = (fans * mul) % MOD;
  cout << (fans + MOD - 1 + z0) % MOD;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
map<pair<long long, long long>, long long> mp;
map<pair<long long, long long>, bool> done;
long long modpow(long long x, long long e) {
  if (x == 1 || e == 0)
    return 1;
  long long c = modpow(x, e / 2);
  long long c1 = (c * c) % MOD;
  if (e % 2 == 0)
    return c1;
  else
    return (c1 * x) % MOD;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  set<pair<long long, long long>> s;
  for (int i = 1; i <= n; i++) {
    long long a, b;
    cin >> a >> b;
    long long g = __gcd(a, b);
    mp[{-a / g, -b / g}]++;
    mp[{a / g, b / g}]++;
    s.insert({a / g, b / g});
  }
  long long fans = 1;
  for (auto p : s) {
    if (done[p])
      continue;
    long long ans = modpow(2, mp[p]) + modpow(2, mp[{-p.second, p.first}]) - 1;
    done[p] = true;
    done[{-p.second, p.first}] = true;
    done[{p.second, -p.first}] = true;
    done[{-p.first, -p.second}] = true;
    fans = (fans * ans) % MOD;
  }
  cout << (fans + MOD - 1) % MOD;
}
Problem p02679 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// cout << fixed << setprecision(17) << res << endl;

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

void reg(ll &a, ll &b) {
  ll g = gcd(abs(a), abs(b));
  a = a / g;
  b = b / g;
  if (a < 0 && b < 0) {
    a = -a;
    b = -b;
  } else if (a <= 0 && b > 0) {
    a = -a;
    b = -b;
  }
}

#define M 1000000007

ll mpow(ll x, ll n) {
  ll ans = 1;
  while (n > 0) {
    if (n & 1)
      ans = ans * x % M;
    x = x * x % M;
    n = n >> 1;
  }
  return ans;
}

int main() {
  ll n;
  cin >> n;
  map<pair<ll, ll>, pair<ll, ll>> m;

  ll zeros = 0;
  for (ll i = 0; i < n; ++i) {
    ll a, b;
    cin >> a >> b;
    if (a == 0 && b != 0) {
      m[make_pair(0, 0)].first++;
      continue;
    }
    if (a != 0 && b == 0) {
      m[make_pair(0, 0)].second++;
      continue;
    }
    if (a == 0 || b == 0) {
      ++zeros;
      continue;
    }
    reg(a, b);
    // cerr << "Checking:" << a << "," << b << endl;
    if ((a >= 0 && b >= 0) || (a <= 0 && b <= 0)) {
      m[make_pair(a, b)].first++;
    } else {
      m[make_pair(abs(b), abs(a))].second++;
    }
  }
  ll res = 1;
  for (auto p : m) {
    // cerr << p.first.first << "," << p.first.second << ":" << p.second.first
    // << "," << p.second.second << endl;
    res = res * (mpow(2, p.second.first) + mpow(2, p.second.second) - 1);
    // cerr << res << endl;
    res %= M;
  }
  res = (res + zeros + M - 1) % M;
  cout << res << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// cout << fixed << setprecision(17) << res << endl;

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

void reg(ll &a, ll &b) {
  if (a == 0 && b != 0) {
    b = b / abs(b);
    return;
  }
  if (a != 0 && b == 0) {
    a = a / abs(a);
    return;
  }
  ll g = gcd(abs(a), abs(b));
  a = a / g;
  b = b / g;
  if (a < 0 && b < 0) {
    a = -a;
    b = -b;
  } else if (a <= 0 && b > 0) {
    a = -a;
    b = -b;
  }
}

#define M 1000000007

ll mpow(ll x, ll n) {
  ll ans = 1;
  while (n > 0) {
    if (n & 1)
      ans = ans * x % M;
    x = x * x % M;
    n = n >> 1;
  }
  return ans;
}

int main() {
  ll n;
  cin >> n;
  map<pair<ll, ll>, pair<ll, ll>> m;

  for (ll i = 0; i < n; ++i) {
    ll a, b;
    cin >> a >> b;
    reg(a, b);
    // cerr << "Checking:" << a << "," << b << endl;
    if ((a >= 0 && b >= 0) || (a <= 0 && b <= 0)) {
      m[make_pair(a, b)].first++;
    } else {
      m[make_pair(abs(b), abs(a))].second++;
    }
  }
  ll res = 1;
  for (auto p : m) {
    // cerr << p.first.first << "," << p.first.second << ":" << p.second.first
    // << "," << p.second.second << endl;
    res = res * (mpow(2, p.second.first) + mpow(2, p.second.second) - 1);
    // cerr << res << endl;
    res %= M;
  }
  --res;
  res = (res + M) % M;
  cout << res << endl;
}
Problem p02679 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define ROF(i, a, b) for (int i = a; i >= b; i--)
using namespace std;

using pii = pair<int, int>;
using vpii = vector<pii>;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vll = vector<ll>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  map<pll, pll> cnt;
  ll c0 = MOD - 1;
  vll pw2(n + 1);
  pw2[0] = 1;
  FOR(i, 1, n) {
    pw2[i] = pw2[i - 1] * 2 % MOD;

    ll a, b;
    cin >> a >> b;
    if (!a && !b) {
      c0++;
      continue;
    }
    ll g = __gcd(a, b);
    a /= g, b /= g;
    if (b < 0)
      a = -a, b = -b;
    if (a <= 0)
      cnt[{b, -a}].se++;
    else
      cnt[{a, b}].fi++;
  }
  ll ans = 1;
  for (auto u : cnt)
    ans = ans * (pw2[u.se.fi] + pw2[u.se.se] - 1 + MOD) % MOD;
  cout << (ans + c0) % MOD << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define ROF(i, a, b) for (int i = a; i >= b; i--)
using namespace std;

using pii = pair<int, int>;
using vpii = vector<pii>;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vll = vector<ll>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  map<pll, pll> cnt;
  ll c0 = MOD - 1;
  vll pw2(n + 1);
  pw2[0] = 1;
  FOR(i, 1, n) {
    pw2[i] = pw2[i - 1] * 2 % MOD;

    int a, b;
    cin >> a >> b;
    if (!a && !b) {
      c0++;
      continue;
    }
    int g = __gcd(a, b);
    a /= g, b /= g;
    if (a <= 0)
      cnt[{b, -a}].se++;
    else
      cnt[{a, b}].fi++;
  }
  ll ans = 1;
  for (auto u : cnt)
    ans = ans * (pw2[u.se.fi] + pw2[u.se.se] - 1 + MOD) % MOD;
  cout << (ans + c0) % MOD << endl;
}