Problem:
Score: 500 points

Problem Statement

We have caught N sardines. The deliciousness and fragrantness of the i-th sardine is A_i and B_i, respectively.

We will choose one or more of these sardines and put them into a cooler. However, two sardines on bad terms cannot be chosen at the same time.

The i-th and j-th sardines (i \neq j) are on bad terms if and only if A_i \cdot A_j + B_i \cdot B_j = 0.

In how many ways can we choose the set of sardines to put into the cooler? Since the count can be enormous, print it modulo 1000000007.

Constraints

All values in input are integers.

1 \leq N \leq 2 \times 10^5

-10^{18} \leq A_i, B_i \leq 10^{18}

Input

Input is given from Standard Input in the following format:

N
A_1 B_1
:
A_N B_N

Output

Print the count modulo 1000000007.

Sample Input 1

3
1 2
-1 1
2 -1

Sample Output 1

5

There are five ways to choose the set of sardines, as follows:

The 1-st

The 1-st and 2-nd

The 2-nd

The 2-nd and 3-rd

The 3-rd

Sample Input 2

10
3 2
3 2
-1 1
2 -1
-3 -9
-8 12
7 7
8 1
8 2
8 4

Sample Output 2

479

Solution in C++ (GCC 9.2.1) (judge verdict: Runtime Error)

#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

template <std::uint_fast64_t Modulus>
class modint {
  using u64 = std::uint_fast64_t;

 public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, c, d, tmp, m, h, w, x, y, sum, k, q;
map<pair<P, ll>, ll> le, ri, mem;
ll rui[ohara], dat[ohara];
ld inf = (ld)1000000000000000100.0;
V a, b;
ll le_ze, ri_ze;

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

  using mint = modint<MOD>;

  cin >> n;
  rui[0] = 1;
  rrep(i, 1, n + 10) {
    rui[i] = rui[i - 1] * 2;
    rui[i] %= MOD;
  }
  rep(i, n) {
    cin >> c >> d;
    assert(c == 0 && d == 0);
    if (c == 0 && d == 0)
      continue;
    else if (c == 0)
      le_ze++;
    else if (d == 0)
      ri_ze++;
    else {
      ll see = 1;
      if (c < 0 && d > 0)
        see = 0;
      else if (c > 0 && d < 0)
        see = 0;
      if (c < 0) c *= -1;
      if (d < 0) d *= -1;
      tmp = __gcd(c, d);
      c /= tmp;
      d /= tmp;
      le[{{c, d}, see}]++;
      ri[{{d, c}, see}]++;
      // debug(c);
      dat[cnt++] = see;
      a.p_b(c);
      b.p_b(d);
    }
  }
  n = Size(a);
  mint ans = mint(1);
  rep(i, n) {
    ll see, now = dat[i];
    if (now == 0)
      see = 1;
    else
      see = 0;
    // debug("AAA");
    // debug(b[i]);
    // Cout((le[{{a[i], b[i]}, now}]));
    if (le[{{a[i], b[i]}, now}] == 0 || mem[{{a[i], b[i]}, now}]) continue;
    mint kake;
    // debug("AAA");
    if (ri[{{a[i], b[i]}, see}] != 0) {
      kake = mint(rui[le[{{a[i], b[i]}, now}]]);
      kake -= mint(1);
      kake += mint(rui[ri[{{a[i], b[i]}, see}]]);
      le[{{a[i], b[i]}, now}] = 0;
      mem[{{b[i], a[i]}, see}] = 1;
      ans *= kake;
    } else {
      kake = mint(rui[le[{{a[i], b[i]}, now}]]);
      le[{{a[i], b[i]}, now}] = 0;
      ans *= kake;
    }
    // Cout(ans.value());
    // debug(i);
  }
  // Cout(n);
  mint kake;
  if (ri_ze) {
    kake = mint(rui[le_ze]);
    kake -= mint(1);
    kake += mint(rui[ri_ze]);
    ans *= kake;
  } else {
    kake = mint(rui[le_ze]);
    ans *= kake;
  }
  ans -= mint(1);
  Cout(ans.value());
  return 0;
}