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++ (Clang 10.0.0) (judge verdict: Runtime Error)

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define fr(i, k, N) for (decltype(N + k) i = k; i < N; i++)
#define rep(i, N) for (decltype(N) i = 0; i < N; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
template <class X>
void pr(X test) {
  cout << test << endl;
}
template <class X>
void prr(X test) {
  for (auto it : test) cout << it << " ";
  cout << endl;
}
template <class X>
void prrr(X test) {
  int f = 0;
  for (auto it : test) cout << (f++ != 0 ? " " : "") << it;
  cout << endl;
}
template <typename X>
istream &operator>>(istream &i, vector<X> &v) {
  for (X &x : v) i >> x;
  return i;
}

class UF {  // union find from https://github.com/kartikkukreja/blog-codes (MIT)
            // [usage]
            // auto uf = new UF(n);
            // uf->merge(l, r); // 0 <= l, r <= n-1
            // uf->sz[uf->find(l)]; // size of l's union
            // ...
 public:
  int *id;  // inner id
  int cnt;  // number of all vartices
  int *sz;  // sz[i] means size of i's set
  UF(int N) {
    cnt = N;
    id = new int[N];
    sz = new int[N];
    for (int i = 0; i < N; i++) {
      id[i] = i;
      sz[i] = 1;
    }
  }
  ~UF() {
    delete[] id;
    delete[] sz;
  }
  int find(int p) {
    int root = p;
    while (root != id[root]) root = id[root];
    while (p != root) {
      int newp = id[p];
      id[p] = root;
      p = newp;
    }
    return root;
  }
  void merge(int x, int y) {
    int i = find(x);
    int j = find(y);
    if (i == j) return;

    if (sz[i] < sz[j]) {
      id[i] = j;
      sz[j] += sz[i];
    } else {
      id[j] = i;
      sz[i] += sz[j];
    }
    cnt--;
  }
  bool connected(int x, int y) { return find(x) == find(y); }
  int count() { return cnt; }
};

// return 約数unordered_set 1 <= x <= n
auto divv(ll n) {
  unordered_set<decltype(n)> v;
  for (decltype(n) i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      v.insert(i);
      if (i * i != n) v.insert(n / i);
    }
  }
  return v;
};

// check prime (and n>=2) or not
auto isPrime(ll n) {
  if (n <= 1) return false;
  for (decltype(n) i = 2; i <= sqrt(n); ++i) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}

// 最小公倍数
auto lcm_(ll a, ll b) {
  if (a < b) swap(a, b);
  auto r = a % b;
  auto x = a * b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return x / b;
}

// 最大公約数
auto gcd_(ll a, ll b) { return (a * b) / lcm_(a, b); };

// factorial n mod prm
ll factmod(ll a, ll prm) {
  return a == 0 ? 1 : (a * factmod(a - 1, prm)) % prm;
};

// 1/x mod prm
auto invmod = [](auto x, auto prm) {
  decltype(x) r = 1;
  if (x == 1) return r;
  for (auto ex = prm - 2; ex; ex >>= 1) {
    if (ex & 1) r = (r * x) % prm;
    x = (x * x) % prm;
  }
  return r;
};

// {{2, 3}, {3, 1}, {5, 2}, ...}
unordered_map<ll, ll> prime_factor(ll n) {
  unordered_map<ll, ll> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}

ll modpow(ll base, ll exp, ll mod) {
  base %= mod;
  ll result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % mod;
    base = (base * base) % mod;
    exp >>= 1;
  }
  return result;
}

// get {1, 1, 2, 6, ..., fact(n)}, size = n + 1
vector<ll> factvec(ll n, ll mod) {
  vector<ll> v(n + 1);
  v[0] = 1;
  fr(i, 1, n + 1) { v[i] = (i * v[i - 1]) % mod; }
  return v;
}

ll nPkMod(ll n, ll k, ll mod, const vector<ll> &factvec) {
  ll tmp = 1;
  tmp = (tmp * factvec[n]) % mod;
  tmp = (tmp * invmod(factvec[n - k], mod)) % mod;
  return tmp;
}

ll nCkMod(ll n, ll k, ll mod, const vector<ll> &factvec) {
  ll tmp = nPkMod(n, k, mod, factvec);
  return (tmp * invmod(factvec[k], mod)) % mod;
}

// ---

int main() {
  ll n;
  ll v1 = 0;
  ll v2 = 0;
  // vector<tuple<ll, ll, ll>> v;
  unordered_map<ll, unordered_map<ll, unordered_map<ll, ll>>> v;
  cin >> n;
  rep(i, n) {
    ll a, b;
    cin >> a >> b;
    if (a == 0 && b == 0) continue;
    if (a == 0)
      v1++;
    else if (b == 0)
      v2++;
    else {
      ll bl = 1;
      if (a * b < 0) {
        bl = -1;
      }
      a = abs(a);
      b = abs(b);
      auto gcddd = gcd_(a, b);
      if (gcddd == 0) {
        pr(1);
        return 0;
      }
      v[a / gcddd][b / gcddd][bl] += 1;
    }
  }
  // pr(v1.size());
  // pr(v2.size());
  // pr(vcnt);
  ll non = 0;
  vector<pair<ll, ll>> out;
  for (auto it : v) {
    ll a = it.first;
    for (auto jt : it.second) {
      ll b = jt.first;
      for (auto kt : jt.second) {
        ll bl = kt.first;
        ll cnt = kt.second;
        if (v.count(b) > 0 && v[b].count(a) > 0 && v[b][a].count(-bl) > 0) {
          ll tmp = v[b][a][-bl];
          // pair(cnt, tmp);
          out.emplace_back(min(cnt, tmp), max(cnt, tmp));
        } else {
          // pr("in non");
          // pr(cnt);
          non += cnt;
        }
      }
    }
  }
  sort(ALL(out));
  ll MODD = (ll)1000000007;

  ll base = modpow((ll)2, non, MODD);
  if (base == 0) {
    base = MODD;
  }
  base--;  // ok?

  rep(i, out.size()) {
    ll f = out[i].first;
    ll s = out[i].second;
    ll t = base % MODD;
    base += modpow((ll)2, f, MODD) - 1;
    base %= MODD;
    base += modpow((ll)2, s, MODD) - 1;
    base %= MODD;
    base += t * (modpow((ll)2, f, MODD) - 1);
    base %= MODD;
    base += t * (modpow((ll)2, s, MODD) - 1);
    base %= MODD;
    i++;
  }
  {
    ll f = v1;
    ll s = v2;
    ll t = base % MODD;
    base += modpow((ll)2, f, MODD) - 1;
    base %= MODD;

    base += modpow((ll)2, s, MODD) - 1;
    base %= MODD;

    base += t * (modpow((ll)2, f, MODD) - 1);
    base %= MODD;

    base += t * (modpow((ll)2, s, MODD) - 1);
    base %= MODD;
  }
  pr(base);
}