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

#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define all(x) begin(x),end(x)
using namespace std;
typedef long long ll;
const ll INF = 1e9;
template<class T=ll> using V = vector<T>;
template<class T=ll> using PQ = priority_queue<T>;
template<class T=ll> using PQG = priority_queue<T, V<T>, greater<T>>;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
template<class T>bool chmax(T &a, const T &b) {if (a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if (a>b) {a=b; return 1;} return 0;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#define YN(e) cout << ((e) ? "YES" : "NO") << endl
#define yn(e) cout << ((e) ? "Yes" : "No") << endl
#pragma endregion RegionDefs

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


ll modpow(ll a, ll n, ll mod)
{
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll get(map<pair<ll,ll>,ll>& m, ll a, ll b) {
    auto p = make_pair(a, b);
    if (m.find(p) == m.end()) return 0;
    ll c = m[p];
    m[p] = 0;
    return c;
}

void solve()
{
    IN(n);
    map<pair<ll,ll>,ll> m;
    ll temp = 0;
    rep(i, n) {
        IN(a, b);
        if (a == 0 || b == 0) {
            if (a != 0) {
                m[make_pair(1, 0)] += 1;
                continue;
            } else if (b != 0) {
                m[make_pair(0, 1)] += 1;
                continue;
            }
            temp++;
            continue;
        }
        ll g = gcd(a, b);
        m[make_pair(a/g, b/g)] += 1;
    }
    vector<pair<ll,ll>> keys;
    for (auto&& t : m) {
        keys.emplace_back(t.first.first, t.first.second);
    }
    vector<pair<ll,ll>> v;
    rep (j, keys.size()) {
        auto& t = m[keys[j]];
        if (t == 0) continue;
        ll n1 = get(m, keys[j].second, -keys[j].first);
        ll n2 = get(m, -keys[j].second, keys[j].first);
        v.emplace_back(t, n1+n2);
    }
    ll s = 1;
    rep(i, v.size()) {
        if (v[i].second == 0) {
            s = (s * modpow(2, v[i].first, MOD)) % MOD;
        } else {
            s = (s * ((modpow(2, v[i].first, MOD) + modpow(2, v[i].second, MOD) + MOD - 1) % MOD)) % MOD;
        }
    }
    cout << (s + MOD + temp - 1) % MOD << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}