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: Wrong Answer)

#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);

using namespace std;
typedef long long int  ll;
typedef pair<ll, ll> P;

constexpr ll MOD = 1e9 + 7;
constexpr ll inf = 1LL << 60;

template< typename S, typename T >
inline void chmax(S &a, const T &b) { if(a < b) a = b; }
 
template< typename S, typename T >
inline void chmin(S &a, const T &b) { if(a > b) a = b; }
 


//a^n mod p//
ll modpow(ll a, ll n, ll p) {
  if( n==0) return (ll)1;
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / (ll)2, p);
  return (t * t) % p;
}

//inversemod//
ll modinv(ll a, ll m) {
	if(m==0)return (ll)1;
	ll b = m, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
// 
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		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 COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}

//radP
ll rad(ll u, ll p){
ll cnt=0;
	while(u%p==0){
		u/=p;
		cnt++;
	}
	return cnt;
}

ll gcdd(ll x, ll y) {
	if (x == 0) return y;
	return gcdd(y%x, x);
}



////////////////////////////////////////////////////////////////////

int main() {
ll n;
cin>>n;

vector<P> vec{};
map<P, ll> mp{};

ll t=0;

rep(i,n){
  ll p,q;
  cin>>p>>q;
  ll pp=abs(p);
  ll qq=abs(q);
  if(pp!=0 && qq!=0){
    ll v=gcdd(pp, qq);
    p/=v;
    q/=v;
  }


  if(q<0 && p<0){
    p=-p;
    q=-q;
  }
  if(p<0 && q>0){
    q=-q;
    p=-p;
  }

  if(p==0 && q==0){t++; continue;}
  if(p==0)q=10;
  if(q==0)p=10;
vec.push_back(make_pair(p,q));
if(!mp.count(make_pair(p,q))) mp[make_pair(p,q)]=1;
else mp[make_pair(p,q)]++;

 
}


ll ans=(ll)1;


for(ll i=0;i<vec.size();i++){
 ll p=vec[i].first;
 ll q=vec[i].second;

ll val=(ll)0;

if(mp[make_pair(p,q)]==0){continue;}
val+=modpow((ll)2,mp[make_pair(p,q)], MOD);
val%=MOD;

ll newp;
ll newq;
if(p>=0 && q>=0){newp=q; newq=-p;}
else{newp=-q; newq=p;}

if(mp.count(make_pair(newp,newq))){
val+=modpow((ll)2,mp[make_pair(newp,newq)],MOD);
val+=MOD-1;
mp[make_pair(newp,newq)]=0;
val%=MOD;
}
ans*=val;
ans%=MOD;

mp[make_pair(p,q)]=0;
}

cout<<(ans-(ll)1+t+MOD)%MOD<<endl;

return 0;


}