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

#include <bits/stdc++.h>
using namespace std;
#define reg register
#define ll long long
#define maxn 300005
#define mo 1000000007
#define int ll
inline ll read() {
  ll x = 0, w = 0;
  char ch = getchar();
  while (!isdigit(ch))
    w |= ch == '-', ch = getchar();
  while (isdigit(ch))
    x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
  return w ? -x : x;
}
struct op {
  ll x, y;
  inline void read() {
    x = ::read(), y = ::read();
    ll g = __gcd(abs(x), abs(y));
    if (g == 0)
      return;
    x /= g, y /= g;
  }
  bool operator==(op b) const { return x == b.x && y == b.y; }
  bool operator<(op b) const { return x == b.x ? y < b.y : x < b.x; }
  op inv() { return op{-x, -y}; }
} a[maxn];
map<op, int> mp;
int n;
int ans;
inline void Add(int &x, int y) {
  x += y;
  x -= (x >= mo ? mo : 0);
}
inline ll get(op x) { return mp.count(x) ? mp[x] : 0; }
int po[maxn];
signed main() {
  n = read();
  reg int i;
  reg int tmp1 = -1;
  for (i = 1; i <= n; ++i)
    a[i].read();
  for (i = 1; i <= n; ++i) {
    if (a[i] == op{0, 0}) {
      ++tmp1;
      continue;
    }
    mp[a[i]]++;
  }
  po[0] = 1;
  for (i = 1; i <= 200000; ++i)
    po[i] = po[i - 1] * 2 % mo;
  int res;
  op u, v;
  ans = 1;
  for (auto tmp : mp) {
    if (tmp.second == -1)
      continue;
    res = 1;
    v = tmp.first;
    u = op{-v.y, v.x};
    Add(res, po[get(v)] - 1);
    Add(res, po[get(u)] - 1);
    Add(res, po[get(v.inv())] - 1);
    Add(res, po[get(u.inv())] - 1);
    Add(res, 1ll * (po[get(v)] - 1) * (po[get(v.inv())] - 1) % mo);
    Add(res, 1ll * (po[get(u.inv())] - 1) * (po[get(u)] - 1) % mo);
    mp[u] = -1;
    mp[v] = -1;
    mp[u.inv()] = -1;
    mp[v.inv()] = -1;
    res += mo;
    res %= mo;
    ans = 1ll * ans * res % mo;
  }
  Add(ans, tmp1);
  ans %= mo;
  ans += mo;
  ans %= mo;
  cout << ans << "\\n";
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define reg register
#define ll long long
#define maxn 200005
#define mo 1000000007
inline ll read() {
  ll x = 0, w = 0;
  char ch = getchar();
  while (!isdigit(ch))
    w |= ch == '-', ch = getchar();
  while (isdigit(ch))
    x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
  return w ? -x : x;
}
struct op {
  ll x, y;
  inline void read() {
    x = ::read(), y = ::read();
    ll g = __gcd(abs(x), abs(y));
    x /= g, y /= g;
  }
  bool operator==(op b) const { return x == b.x && y == b.y; }
  bool operator<(op b) const { return x == b.x ? y < b.y : x < b.x; }
  op inv() { return op{-x, -y}; }
} a[maxn];
map<op, int> mp;
int n;
int ans;
inline void Add(int &x, int y) {
  x += y;
  x -= (x >= mo ? mo : 0);
}
inline ll get(op x) { return mp.count(x) ? mp[x] : 0; }
int po[maxn];
int main() {
  n = read();
  reg int i;
  reg int tmp1 = -1;
  for (i = 1; i <= n; ++i)
    a[i].read();
  for (i = 1; i <= n; ++i) {
    if (a[i] == op{0, 0}) {
      ++tmp1;
      continue;
    }
    mp[a[i]]++;
  }
  po[0] = 1;
  for (i = 1; i <= 200000; ++i)
    po[i] = po[i - 1] * 2 % mo;
  int res;
  op u, v;
  ans = 1;
  for (auto tmp : mp) {
    if (tmp.second == -1)
      continue;
    res = 1;
    v = tmp.first;
    u = op{-v.y, v.x};
    Add(res, po[get(v)] - 1);
    Add(res, po[get(u)] - 1);
    Add(res, po[get(v.inv())] - 1);
    Add(res, po[get(u.inv())] - 1);
    Add(res, 1ll * (po[get(v)] - 1) * (po[get(u)] - 1) % mo);
    Add(res, 1ll * (po[get(v.inv())] - 1) * (po[get(u.inv())] - 1) % mo);
    mp[u] = -1;
    mp[v] = -1;
    mp[u.inv()] = -1;
    mp[v.inv()] = -1;
    ans = 1ll * ans * res % mo;
  }
  Add(ans, tmp1);
  cout << ans << "\\n";
  return 0;
}