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)

#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;

/*** MOD CALCULATION ***/

const int MOD = 1e9+7;
const int MAX = 510000;

ll addM(ll a, ll b){
	ll temp = (a + b) % MOD;
	while(temp<0) temp += MOD;
	return temp;
}

ll mulM(ll a, ll b){
	ll temp = (a * b) % MOD;
  	while(temp<0) temp += MOD;
  	return temp;
}

ll powM(ll a, ll b){
	if(b == 0) return 1;
  	else if(b == 1) return a%MOD;
  	else if(b%2==0) return mulM(powM(a,b/2),powM(a,b/2));
  	else return mulM(a,mulM(powM(a,(b-1)/2),powM(a,(b-1)/2)));
}

// b^{-1} = b^{p-2} (mod p)
// a/b = a*b^{p-2} (mod p)
ll divM(ll a, ll b){ 
  	return mulM(a,powM(b,MOD-2));
}

// n!, (n!)^{-1} のテーブル作成
ll fac[MAX], finv[MAX], inv[MAX];
void COMBinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    rep3(i,2,MAX-1){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COMB(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

/*** MOD CALCULATION ここまで ***/

void Main() {
	int n;
	cin >> n;
    vll a(n), b(n);
    vector<Pll> data;
    ll anstemp = 0;
    
    rep(i, n) {
        cin >> a[i] >> b[i];
        if(a[i] == 0 && b[i] == 0) {
            anstemp++;
            continue;
        }
        if(a[i] == 0) data.pb(Pll(0, 1));
        else if(b[i] == 0) data.pb(Pll(1, 0));
        else {
            ll g = gcd(a[i], b[i]);
            if(a[i]/g > 0) data.pb(Pll(a[i]/g, b[i]/g));
            else data.pb(Pll(-a[i]/g, -b[i]/g));
        }
    }
    
    /*
    for(auto i : data) cout << i.fi << " " << i.se << endl;
    cout << endl;
    //*/
    
    ll ans = 1;
    map<Pll, ll> mp;
    
    rep(i, data.size()){
        mp[data[i]]++;
    }
    
    map<Pll, bool> seen;
    
    for(auto k : data){
        if(seen[k]) continue;
        ll temp;
        auto [x, y] = k;
        Pll l;
        if (y == 0) l = Pll(0, 1);
        else if (x == 0) l = Pll(1, 0);
        else if(y > 0) l = Pll (y, -x);
        else l = Pll(-y, x);
        temp = addM( powM(2, mp[k]), powM(2, mp[l]) - 1 );
        ans = mulM(ans, temp);
        //cout << "k = " << x << "," << y << ": " << seen[k] << ", ans = " << ans << endl;
        //cout << "l = " << l.fi << "," << l.se << ": " << seen[l] << endl;
        seen[k] = true;
        seen[l] = true;
    }
    
    cout << addM( ans - 1, anstemp ) << endl;
    return;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}