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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll MOD = 1e9 + 7;
using P = pair<ll, ll>;
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
ll mod_pow(ll x, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) {
      res = res * x % MOD;
    }
    x = x * x % MOD;
    n >>= 1;
  }
  return res;
}

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> b(n);
  for (int i = 0; i < n; i++)
    cin >> a[i] >> b[i];
  map<P, ll> ma;
  int zero = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] < 0) {
      a[i] *= -1;
      b[i] *= -1;
    }
    P p;
    if (a[i] == 0 && b[i] == 0) {
      zero++;
      continue;
    } else if (a[i] == 0) {
      p = P(0, -1);
    } else {
      ll g = gcd(a[i], b[i]);
      p = P(a[i] / g, b[i] / g);
    }
    if (ma.find(p) == ma.end())
      ma[p] = 1;
    else
      ma[p]++;
  }
  vector<ll> count;
  while (!ma.empty()) {
    auto itr = ma.begin();
    P p = itr->first;
    ll c = itr->second;
    ll x = p.first;
    ll y = p.second;
    ll tx = y;
    ll ty = x;
    if (tx < 0)
      tx *= -1;
    else
      ty *= -1;
    if (ma.find(P(tx, ty)) != ma.end()) {
      ll tc = ma[P(tx, ty)];
      count.push_back((mod_pow(2, c) + mod_pow(2, tc) - 1) % MOD);
      ma.erase(P(tx, ty));
    } else {
      count.push_back(mod_pow(2, c));
    }
    ma.erase(p);
  }
  ll ans = 1;
  for (ll c : count) {
    ans = ans * c % MOD;
  }
  ans = (ans + zero - 1 + MOD) % MOD;
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll MOD = 1e9 + 7;
using P = pair<ll, ll>;
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
ll mod_pow(ll x, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) {
      res = res * x % MOD;
    }
    x = x * x % MOD;
    n >>= 1;
  }
  return res;
}

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> b(n);
  for (int i = 0; i < n; i++)
    cin >> a[i] >> b[i];
  map<P, ll> ma;
  for (int i = 0; i < n; i++) {
    if (a[i] < 0) {
      a[i] *= -1;
      b[i] *= -1;
    }
    ll g = gcd(a[i], b[i]);
    P p = P(a[i] / g, b[i] / g);
    if (ma.find(p) == ma.end())
      ma[p] = 1;
    else
      ma[p]++;
  }
  vector<ll> count;
  while (!ma.empty()) {
    auto itr = ma.begin();
    P p = itr->first;
    ll c = itr->second;
    ll x = p.first;
    ll y = p.second;
    ll tx = y;
    ll ty = x;
    if (y < 0)
      tx *= -1;
    else
      ty *= -1;
    if (ma.find(P(tx, ty)) != ma.end()) {
      ll tc = ma[P(tx, ty)];
      count.push_back((mod_pow(2, c) + mod_pow(2, tc) - 1) % MOD);
      ma.erase(P(tx, ty));
    } else {
      count.push_back(mod_pow(2, c));
    }
    ma.erase(p);
  }
  ll ans = 1;
  for (ll c : count) {
    ans = ans * c % MOD;
  }
  ans = (ans - 1 + MOD) % MOD;
  cout << ans << endl;
}
Problem p02679 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define D(x) cerr << #x << " = " << (x) << '\\n'
using ll = long long;

const int mod = 1e9 + 7;

ll fast(ll b, ll e) {
  ll ans = 1;
  for (; e; b = b * b % mod, e /= 2)
    if (e & 1)
      ans = ans * b % mod;
  return ans;
}

ll add(ll x, ll y) { return (x + y) % mod; }

ll sub(ll x, ll y) { return (x - y + mod) % mod; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll n, ans = 1, zeros = 0;
  cin >> n;
  map<pair<ll, ll>, pair<int, int>> m;
  for (int i = 0; i < n; ++i) {
    ll a, b;
    cin >> a >> b;
    if (a == 0 && b == 0)
      zeros++;
    else {
      ll g = __gcd(a, b);
      a /= g, b /= g;
      if (b < 0)
        a = -a, b = -b;
      if (a > 0)
        m[{a, b}].first++;
      else
        m[{b, -a}].second++;
    }
  }
  for (auto e : m) {
    int x, y;
    tie(x, y) = e.second;
    ans = ans * sub(add(fast(2, x), fast(2, y)), 1) % mod;
  }
  cout << sub(add(ans, zeros), 1) << '\\n';
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define D(x) cerr << #x << " = " << (x) << '\\n'
using ll = long long;

const int mod = 1e9 + 7;

ll fast(ll b, ll e) {
  ll ans = 1;
  for (; e; b = b * b % mod, e /= 2)
    if (e & 1)
      ans = ans * b % mod;
  return ans;
}

int add(int x, int y) { return (x + y) % mod; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, ans = 1;
  cin >> n;
  map<pair<int, int>, pair<int, int>> m;
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    if (a == 0 && b == 0)
      ans++;
    else {
      int g = __gcd(a, b);
      a /= g, b /= g;
      if (a > 0)
        m[{a, b}].first++;
      else
        m[{b, -a}].second++;
    }
  }
  for (auto e : m) {
    int x, y;
    tie(x, y) = e.second;
    ans = ans * add(fast(2, x), fast(2, y) - 1) % mod;
  }
  cout << (ans - 1 + mod) % mod << '\\n';
}
Problem p02679 (C++) — buggy submission, verdict: Runtime Error

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

typedef long long ll;
const int NMAX = 2e5 + 10;
const int MOD = 1e9 + 7;

ll fast_pow(ll a, ll n) {
  ll ans = 1;
  while (n) {
    if (n & 1)
      ans = ans * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return ans;
}
int main(int argc, char const *argv[]) {
  map<pair<ll, ll>, int> one;
  map<pair<ll, ll>, int> four;
  set<pair<ll, ll>> list;
  int n;
  scanf("%d", &n);
  ll ans = 1, ant = 0;
  ll a, b;
  for (register int _ = 0; _ < n; _++) {
    scanf("%lld%lld", &a, &b);
    ll ab_gcd = __gcd(abs(a), abs(b));
    if (!a && !b) {
      ant++;
      continue;
    }
    if (a >= 0 && b > 0 || a <= 0 && b < 0) {
      if (a != 0) {
        a = abs(a) / ab_gcd;
        b = abs(b) / ab_gcd;
      } else {
        a = 0;
        b = 1;
      }
      one[{a, b}]++;
    } else {
      if (b != 0) {
        a = abs(a) / ab_gcd;
        b = abs(b) / ab_gcd;
      } else {
        a = 1, b = 0;
      }
      four[{b, a}]++;
    }
  }
  for (map<pair<ll, ll>, int>::iterator it = one.begin(); it != one.end(); it++)
    list.insert(it->first);
  for (map<pair<ll, ll>, int>::iterator it = four.begin(); it != four.end();
       it++)
    list.insert(it->first);
  for (set<pair<ll, ll>>::iterator it = list.begin(); it != list.end(); it++)
    ans =
        ans * (fast_pow(2, one[*it]) + fast_pow(2, four[*it]) - 1 + MOD) % MOD;
  printf("%lld\\n", (ans + ant - 1 + MOD) % MOD);
  return 0;
}

Error: 0

Fixed submission:

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

typedef long long ll;
const int NMAX = 2e5 + 10;
const int MOD = 1e9 + 7;

ll fast_pow(ll a, ll n) {
  ll ans = 1;
  while (n) {
    if (n & 1)
      ans = ans * a % MOD;
    a = a * a % MOD;
    n >>= 1;
  }
  return ans;
}
int main(int argc, char const *argv[]) {
  map<pair<ll, ll>, int> one;
  map<pair<ll, ll>, int> four;
  set<pair<ll, ll>> list;
  int n;
  scanf("%d", &n);
  ll ans = 1, ant = 0;
  ll a, b;
  for (register int _ = 0; _ < n; _++) {
    scanf("%lld%lld", &a, &b);
    ll ab_gcd = __gcd(abs(a), abs(b));
    if (!a && !b)
      ant++;
    if (a >= 0 && b > 0 || a <= 0 && b < 0) {
      if (!ab_gcd) {
        a = abs(a) / ab_gcd;
        b = abs(b) / ab_gcd;
      } else
        a = abs(a), b = abs(b);
      one[{a, b}]++;
    } else {
      if (!ab_gcd) {
        a = abs(a) / ab_gcd;
        b = abs(b) / ab_gcd;
      } else
        a = abs(a), b = abs(b);
      four[{b, a}]++;
    }
  }
  for (map<pair<ll, ll>, int>::iterator it = one.begin(); it != one.end(); it++)
    list.insert(it->first);
  for (map<pair<ll, ll>, int>::iterator it = four.begin(); it != four.end();
       it++)
    list.insert(it->first);
  for (set<pair<ll, ll>>::iterator it = list.begin(); it != list.end(); it++)
    ans =
        ans * (fast_pow(2, one[*it]) + fast_pow(2, four[*it]) - 1 + MOD) % MOD;
  printf("%lld\\n", (ans + ant - 1 + MOD) % MOD);
  return 0;
}
Problem p02679 (C++) — buggy submission, verdict: Runtime Error

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

const int mod = 1e9 + 7;

int pw(int a, int t) {
  int x = 1;
  while (t) {
    if (t & 1)
      x = x * a % mod;
    a = a * a % mod, t >>= 1;
  }
  return x;
}
int32_t main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int n, z = 0;
  cin >> n;
  map<pair<int, int>, int> m;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    if (a == 0 and b == 0) {
      z++;
      continue;
    }
    if (b < 0)
      b = -b, a = -a;
    int g = __gcd(abs(a), abs(b));
    a /= g, b /= g;
    if (a == 0 or b == 0)
      a = abs(a), b = abs(b);
    m[{a, b}]++;
  }
  int ans = 1;
  for (auto i : m) {
    int a = i.first.first, b = i.first.second;
    if (i.second == 0)
      continue;
    int na = -b, nb = a;
    if (a < 0)
      na = -na, nb = -nb;
    if (na == 0 or nb == 0)
      na = abs(na), nb = abs(nb);
    int x = i.second, y = m[{na, nb}];
    m[{na, nb}] = 0;
    int r = (pw(2, x) + pw(2, y) - 1 + mod) % mod;
    ans = (ans * r) % mod;
  }
  cout << (ans + mod - 1 + z) % mod;
}

Error: WA

Fixed submission:

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

const int mod = 1e9 + 7;

int pw(int a, int t) {
  int x = 1;
  while (t) {
    if (t & 1)
      x = x * a % mod;
    a = a * a % mod, t >>= 1;
  }
  return x;
}
int32_t main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int n;
  cin >> n;
  map<pair<int, int>, int> m;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    if (b < 0)
      b = -b, a = -a;
    int g = __gcd(a, b);
    a /= g, b /= g;
    m[{a, b}]++;
  }
  int ans = 1;
  for (auto i : m) {
    int a = i.first.first, b = i.first.second;
    if (a == 0 and b == 0) {
      ans = (ans * (i.second + 1)) % mod;
      continue;
    }
    if (i.second == 0)
      continue;
    int na = -b, nb = a;
    if (a < 0)
      na = -na, nb = -nb;
    int x = i.second, y = m[{na, nb}];
    m[{na, nb}] = 0;
    int r = (pw(2, x) + pw(2, y) - 1 + mod) % mod;
    ans = (ans * r) % mod;
  }
  cout << (ans + mod - 1) % mod;
}
Problem p02679 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
using namespace std;

long long pow(long long a, long long b, long long mod) {
  if (b == 0) {
    return 1;
  } else {
    if (b % 2 == 0) {
      return pow(a * a % mod, b / 2, mod);
    } else {
      return pow(a * a % mod, b / 2, mod) * a % mod;
    }
  }
}

long long gcd(long long a, long long b) {
  long long r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

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

  long long a, b, g;
  long long mod = 1000000007;
  map<pair<long long, long long>, pair<int, int>> m;
  int z = 0;

  for (int i = 0; i < N; i++) {
    cin >> a >> b;
    if (a == 0 && b == 0) {
      z++;
    } else if (a == 0) {
      m[{0, 1}].first++;
    } else if (b == 0) {
      m[{0, 1}].second++;
    } else if (a > 0 && b > 0) {
      g = gcd(a, b);
      m[{a / g, b / g}].first++;
    } else if (a > 0) {
      g = gcd(a, -b);
      m[{-b / g, a / g}].second++;
    } else if (b > 0) {
      g = gcd(-a, b);
      m[{b / g, -a / g}].second++;
    } else {
      g = gcd(-a, -b);
      m[{-a / g, -b / g}].first++;
    }
  }

  long long ans = 1;
  long long tmp;
  for (auto p : m) {
    // cout<<p.second.first<<" "<<p.second.second<<endl;
    tmp = pow(2, p.second.first, mod);
    tmp += pow(2, p.second.second, mod);
    tmp--;
    tmp %= mod;
    ans *= tmp;
    ans %= mod;
  }
  ans--;
  ans += mod;
  ans %= mod;
  ans += z;
  ans %= mod;
  cout << ans << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
using namespace std;

long long pow(long long a, long long b, long long mod) {
  if (b == 0) {
    return 1;
  } else {
    if (b % 2 == 0) {
      return pow(a * a % mod, b / 2, mod);
    } else {
      return pow(a * a % mod, b / 2, mod) * a % mod;
    }
  }
}

long long gcd(long long a, long long b) {
  long long r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

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

  long long a, b, g;
  long long mod = 1000000007;
  map<pair<long long, long long>, pair<int, int>> m;
  int z = 0;

  for (int i = 0; i < N; i++) {
    cin >> a >> b;
    if (a == 0 && b == 0) {
      z++;
    } else if (a > 0 && b > 0) {
      g = gcd(a, b);
      m[{a / g, b / g}].first++;
    } else if (a > 0) {
      g = gcd(a, -b);
      m[{-b / g, a / g}].second++;
    } else if (b > 0) {
      g = gcd(-a, b);
      m[{b / g, -a / g}].second++;
    } else {
      g = gcd(-a, -b);
      m[{-a / g, -b / g}].first++;
    }
  }

  long long ans = 1;
  long long tmp;
  for (auto p : m) {
    // cout<<p.second.first<<" "<<p.second.second<<endl;
    tmp = pow(2, p.second.first, mod);
    tmp += pow(2, p.second.second, mod);
    tmp--;
    tmp %= mod;
    ans *= tmp;
    ans %= mod;
  }
  ans--;
  ans += mod;
  ans %= mod;
  ans += z;
  ans %= mod;
  cout << ans << endl;

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

#include <bits/stdc++.h>

using namespace std;

const long long mod = 1000000007;

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

int main(int, char **) {
  int n;
  cin >> n;
  long long cnt0 = mod - 1;
  map<pair<long long, long long>, pair<long long, long long>> cnt;
  long long pw[202020] = {1};
  for (int i = 1; i < 202020; i++)
    pw[i] = (pw[i - 1] * 2) % mod;
  for (int i = 0; i < n; i++) {
    long long a, b;
    cin >> a >> b;
    if (a == 0 && b == 0) {
      cnt0++;
      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)
      cnt[{a, b}].first++;
    else
      cnt[{-b, a}].second++;
  }
  long long ret = 1;
  for (auto &c : cnt) {
    ret = ret * (pw[c.second.first] + pw[c.second.second] - 1) % mod;
  }
  cout << (ret + cnt0) % mod << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

const long long mod = 1000000007;

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

int main(int, char **) {
  int n;
  cin >> n;
  long long cnt0 = mod - 1;
  map<pair<long long, long long>, pair<long long, long long>> cnt;
  long long pw[202020] = {1};
  for (int i = 1; i < 202020; i++)
    pw[i] = (pw[i - 1] * 2) % mod;
  for (int i = 0; i < n; i++) {
    long long a, b;
    cin >> a >> b;
    if (a == 0 && b == 0) {
      cnt0++;
      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)
      cnt[{a, b}].first++;
    else
      cnt[{-b, a}].second++;
  }
  long long ret = 1;
  for (auto &c : cnt) {
    ret = ret * (pw[c.second.first] + pw[c.second.second] - 1) % mod;
  }
  cout << (ret + cnt0) % mod << endl;
  return 0;
}
Problem p02679 (C++) — buggy submission, verdict: Runtime Error

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

int A[200005], B[200005];
map<pair<int, int>, pair<int, int>> f;

const int mod = 1e9 + 7;

int pw(int b, int e) {
  if (e == 0) {
    return 1;
  }
  if (e & 1) {
    int k = pw(b, e / 2);
    k *= k;
    k %= mod;
    k *= b;
    k %= mod;
    return k;
  } else {
    int k = pw(b, e / 2);
    k *= k;
    k %= mod;
    return k;
  }
}

int32_t main() {
  int n;
  cin >> n;
  int ans = 1;
  int zeros = 0;
  int d = 0;
  for (int i = 1; i <= n; i++) {
    cin >> A[i] >> B[i];
    if (A[i] == 0 && B[i] == 0) {
      zeros++;
    } else {
      if (make_pair(A[i], B[i]) < make_pair(0LL, 0LL)) {
        A[i] = -A[i];
        B[i] = -B[i];
      }
      int g = __gcd(abs(A[i]), abs(B[i]));
      A[i] /= g;
      B[i] /= g;
      if (B[i] > 0) {
        f[{A[i], B[i]}].first++;
      } else {
        f[{-B[i], A[i]}].second++;
      }
    }
  }

  for (auto [a, b] : f) {
    // cout<<a.first<<" "<<a.second<<" "<<b.first<<" "<<b.second<<"\\n";
    ans = (ans * (pw(2, b.first) + pw(2, b.second) - 1)) % mod;
  }
  cout << (ans + zeros + mod - 1) % mod;
}


Error: WA

Fixed submission:

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

int A[100005], B[100005];

map<pair<int, int>, int> f;

pair<int, int> norm(int a, int b) {
  if (a == 0 && b == 0) {
    return {0, 0};
  } else if (b == 0) {
    return {1, 0};
  } else if (a == 0) {
    return {0, 1};
  } else {
    int g = __gcd(abs(a), abs(b));
    int sgn = ((a > 0) == (b > 0)) - ((a > 0) != (b > 0));
    a /= g;
    b /= g;
    return {sgn * abs(a), abs(b)};
  }
}

pair<int, int> opp(pair<int, int> p) {
  if (p.first == 0 && p.second == 0) {
    return {-1, -1};
  } else if (p.first == 0 && p.second == 0) {
    return {0, 1};
  } else if (p.first == 0 && p.second == 0) {
    return {1, 0};
  } else {
    return {-p.second, abs(p.first)};
  }
}

const int mod = 1e9 + 7;
int pw(int b, int e) {
  if (e == 0) {
    return 1;
  }
  if (e & 1) {
    int k = pw(b, e / 2);
    k *= k;
    k %= mod;
    k *= b;
    k %= mod;
    return k;
  } else {
    int k = pw(b, e / 2);
    k *= k;
    k %= mod;
    return k;
  }
}

int32_t main() {
  int n;
  cin >> n;
  int ans = 1;
  int zeros = 0;
  int d = 0;
  for (int i = 1; i <= n; i++) {
    cin >> A[i] >> B[i];
    if (A[i] == 0 && B[i] == 0) {
      zeros++;
    } else {
      f[norm(A[i], B[i])]++;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (A[i] == 0 && B[i] == 0) {
      continue;
    } else {
      auto a1 = norm(A[i], B[i]);
      auto a2 = opp(a1);
      auto t1 = f[a1];
      auto t2 = f[a2];
      // cout<<a1.first<<" "<<a1.second<<" "<<t1<<"\\n"<<
      //	  a2.first<<" "<<a2.second<<" "<<t2<<"\\n";
      if (t1 && t2 && a1.first != -a1.second) {
        ans *= pw(2, t1) + pw(2, t2) - 1;
        ans %= mod;
        d += t1 + t2;
        f[a1] = 0;
        f[a2] = 0;
        //	cout<<ans<<"\\n";
      }
    }
  }
  ans *= max(1LL, zeros);
  ans %= mod;
  ans *= pw(2, n - d - zeros);
  ans %= mod;
  ans += mod - 1;
  ans %= mod;
  cout << ans;
}
Problem p02679 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iostream>
#include <map>
#include <vector>

const long long MOD = 1000000007;

long long gcd(long long a, long long b) {
  long long r = a % b;
  return r ? gcd(b, r) : b;
}

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

  long long zero = 0;
  std::vector<long long> A(N), B(N);
  std::map<std::pair<long long, long long>, long long> m;
  for (int i = 0; i < N; i++) {
    long long a, b;
    std::cin >> a >> b;

    if (a == 0 && b == 0) {
      ++zero;
      continue;
    } else if (a == 0) {
      b = 1;
    } else if (b == 0) {
      a = -1;
    } else {
      long long g = gcd(std::abs(a), std::abs(b));
      a /= g;
      b /= g;

      if (b < 0) {
        a *= -1;
        b *= -1;
      }
    }

    A[i] = a;
    B[i] = b;

    m[std::make_pair(a, b)] += 1;
  }

  auto pow = [](long long a, int n) {
    long long res = 1;
    for (; n; n >>= 1) {
      if (n & 1)
        res = res * a % MOD;
      a = a * a % MOD;
    }
    return res;
  };

  long long ans = 1;

  for (int i = 0; i < N; i++) {
    auto p = std::make_pair(A[i], B[i]);
    if (m.count(p) == 0)
      continue;
    auto q =
        A[i] < 0 ? std::make_pair(B[i], -A[i]) : std::make_pair(-B[i], A[i]);

    long long x = m[p];
    long long y = m[q];

    long long res = ((pow(2, x) - 1) + (pow(2, y) - 1) + 1) % MOD;
    ans = ans * res % MOD;

    m.erase(p);
    m.erase(q);
  }

  ans = (ans + MOD + zero - 1) % MOD;

  std::cout << ans << "\\n";
}

Error: 0

Fixed submission:

#include <cmath>
#include <iostream>
#include <map>
#include <vector>

const long long MOD = 1000000007;

long long gcd(long long a, long long b) {
  long long r = a % b;
  return r ? gcd(b, r) : b;
}

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

  long long zero = 0;
  std::vector<long long> A(N), B(N);
  std::map<std::pair<long long, long long>, long long> m;
  for (int i = 0; i < N; i++) {
    long long a, b;
    std::cin >> a >> b;

    if (a == 0 && b == 0) {
      ++zero;
    } else if (a == 0) {
      b = 1;
    } else if (b == 0) {
      a = 1;
    }

    long long g = gcd(std::abs(a), std::abs(b));
    a /= g;
    b /= g;

    if (b < 0) {
      a *= -1;
      b *= -1;
    }

    A[i] = a;
    B[i] = b;

    m[std::make_pair(a, b)] += 1;
  }

  auto pow = [](long long a, int n) {
    long long res = 1;
    for (; n; n >>= 1) {
      if (n & 1)
        res = res * a % MOD;
      a = a * a % MOD;
    }
    return res;
  };

  long long ans = 1;

  for (int i = 0; i < N; i++) {
    auto p = std::make_pair(A[i], B[i]);
    if (m.count(p) == 0)
      continue;
    auto q =
        A[i] < 0 ? std::make_pair(B[i], -A[i]) : std::make_pair(-B[i], A[i]);

    long long x = m[p];
    long long y = m[q];

    long long res = ((pow(2, x) - 1) + (pow(2, y) - 1) + 1) % MOD;
    ans = ans * res % MOD;

    m.erase(p);
    m.erase(q);
  }

  ans = (ans + MOD + zero - 1) % MOD;

  std::cout << ans << "\\n";
}
Problem p02679 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
#define ll long long
const int N = 2e5 + 5, mod = 1e9 + 7;

ll p[N];

pair<ll, ll> inv(pair<ll, ll> x) {
  bool neg = 1;
  if (x.first < 0)
    neg = 0;
  pair<ll, ll> ret = {abs(x.second), abs(x.first)};
  if (neg)
    ret.first *= -1;
  return ret;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  p[0] = 1;
  for (int i = 1; i < N; i++) {
    p[i] = p[i - 1] * 2;
    p[i] %= mod;
  }
  map<pair<ll, ll>, ll> mp;
  int n;
  cin >> n;
  ll zeros1 = 0, zeros2 = 0, full = 0;
  for (int i = 1; i <= n; i++) {
    ll a, b;
    cin >> a >> b;
    if (a == 0 && b == 0) {
      full++;
      continue;
    } else if (a == 0) {
      zeros1++;
      continue;
    } else if (b == 0) {
      zeros2++;
      continue;
    }
    bool neg = 0;
    if ((a < 0) != (b < 0))
      neg = 1;
    a = abs(a), b = abs(b);
    ll g = __gcd(a, b);
    pair<ll, ll> cur = {a / g, b / g};
    if (neg)
      cur.first *= -1;
    mp[cur]++;
    //        cout << cur.first <<' ' << cur.second << endl;
  }
  ll ans = 1;
  for (auto it : mp) {
    if (it.second == 0)
      continue;
    ll cur = 0;
    pair<ll, ll> c = inv(it.first);
    if (mp.find(c) != mp.end()) {
      cur += p[it.second] - 1;
      cur += p[mp[c]] - 1;
      cur %= mod;
      mp[c] = 0;
      cur++;
    } else {
      cur = p[it.second];
    }
    ans *= cur;
    ans %= mod;
  }
  if (zeros1 && zeros2) {
    ll cur = 0;
    cur += p[zeros1] - 1;
    cur += p[zeros2] - 1;
    cur %= mod;
    cur++;
    ans *= cur;
    ans %= mod;
  } else if (zeros1 || zeros2) {
    ans *= p[(zeros1 + zeros2)];
    ans %= mod;
  }
  ans += full;
  ans %= mod;
  cout << (ans - 1 + mod) % mod;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
#define ll long long
const int N = 2e5 + 5, mod = 1e9 + 7;

ll p[N];
pair<ll, ll> inv(pair<ll, ll> x) {
  bool neg = 1;
  if (x.first < 0)
    neg = 0;
  pair<ll, ll> ret = {abs(x.second), abs(x.first)};
  if (neg)
    ret.first *= -1;
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  p[0] = 1;
  for (int i = 1; i < N; i++) {
    p[i] = p[i - 1] * 2;
    p[i] %= mod;
  }
  map<pair<ll, ll>, ll> mp;
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    ll a, b;
    cin >> a >> b;
    bool neg = 0;
    if ((a < 0) != (b < 0))
      neg = 1;
    a = abs(a), b = abs(b);
    ll g = __gcd(a, b);
    pair<ll, ll> cur = {a / g, b / g};
    if (neg)
      cur.first *= -1;
    mp[cur]++;
    //        cout << cur.first <<' ' << cur.second << endl;
  }
  ll ans = 1;
  for (auto it : mp) {
    if (it.second == 0)
      continue;
    ll cur = 0;
    pair<ll, ll> c = inv(it.first);
    if (mp.find(c) != mp.end()) {
      cur += p[it.second] - 1;
      cur += p[mp[c]] - 1;
      cur %= mod;
      mp[c] = 0;
      cur++;
    } else {
      cur = p[it.second];
    }
    ans *= cur;
    ans %= mod;
  }
  cout << ans - 1;
  return 0;
}