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: Accepted)

/* #include <bits/stdc++.h> */
#include <vector>
#include <iostream>
#include <deque>
#include <unordered_map>
using namespace std;

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair< int, int > pii;
typedef vector< int > vi;

//
struct pair_hash {
    template <class T1, class T2>
    std::size_t operator () (const std::pair<T1,T2> &p) const {
        auto h1 = std::hash<T1>{}(p.first);
        auto h2 = std::hash<T2>{}(p.second);

        // Mainly for demonstration purposes, i.e. works but is overly simple
        // In the real world, use sth. like boost.hash_combine
        return h1 ^ h2;  
    }
};
//

ll gcd(ll x, ll y) {
    if (x > y) swap(x, y);
    if (x == 0) return y;
    return gcd(y % x, x);
}

ll euclid(ll a, ll b, ll &x, ll &y) {
	if (b) { ll d = euclid(b, a % b, y, x);
		return y -= a/b * x, d; }
	return x = 1, y = 0, a;
}

const ll mod = 1000000007;
struct Mod {
	ll x;
	Mod(ll xx) : x(xx) {}
	Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
	Mod operator-(Mod b) { return Mod((x - b.x + mod) % mod); }
	Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
	Mod operator/(Mod b) { return *this * invert(b); }
	Mod invert(Mod a) {
		ll x, y, g = euclid(a.x, mod, x, y);
		 return Mod((x + mod) % mod);
	}
	Mod operator^(ll e) {
		if (!e) return Mod(1);
		Mod r = *this ^ (e / 2); r = r * r;
		return e&1 ? *this * r : r;
	}
};

void solve() {
    int N; cin >> N;
    unordered_map<pair<ll, ll>, pair<int, int>, pair_hash> ok;
    ll AB0 = 0;
    for (int i = 0; i < N; i++) {
        ll A, B; cin >> A >> B;
        if (A == 0 && B == 0) {
            AB0++;
            continue;
        }
        ll G = gcd(abs(A), abs(B));
        A /= G;
        B /= G;
        int nrots = 0;
        while (A < 0 || B <= 0) {
            A *= -1;
            swap(A, B);
            nrots++;
        }
        pii curr = ok[{A, B}];
        if (nrots % 2) {
            curr.first++;
        } else {
            curr.second++;
        }
        ok[{A, B}] = curr;
    }
    Mod sol(1);
    for (pair<pair<ll, ll>, pair<int, int>> p : ok) {
        int x, y;
        tie(x, y) = p.second;
        Mod a = (Mod(2) ^ x) - 1;
        Mod b = (Mod(2) ^ y) - 1;
        sol = sol * (Mod(1) + a + b);
    }
    sol = sol - Mod(1);
    sol = sol + AB0;
    cout << (sol.x % mod + mod) % mod << "\n";
}

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(cin.failbit);
    solve();
}