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: Runtime Error)

#include<bits/stdc++.h>

using namespace std;

#define LL long long
#define N 200005
#define mod 1000000007

LL ans, a[N], b[N], _gcd, p, q;
int n, cur, T, i, r, vis[N];
map<pair<LL,LL>, int> K;
pair<LL,LL> Q[N];
pair<pair<LL,LL>, int> label[N];

LL power(LL x,int y)
{
	LL t=1;
	for (; y; y>>=1) {
		if (y&1) t=t*x%mod;
		x=x*x%mod; 
	}
	return t;
}

int main (void)
{
	scanf("%d",&n);
	for (i=1; i<=n; i++) {
		scanf("%lld%lld",&a[i],&b[i]);
		_gcd=__gcd(a[i],b[i]);
		a[i]/=_gcd,b[i]/=_gcd;
		Q[i]=make_pair(a[i],b[i]);
	}	
	sort(Q+1,Q+n+1);
	cur=T=1;
	for (i=2; i<=n; i++) {
		if (Q[i].first==Q[i-1].first&&Q[i].second==Q[i-1].second) cur++;
		else label[T]=make_pair(Q[i-1],cur),T++,cur=1;
	}
	if (cur) label[T]=make_pair(Q[i-1],cur);
	for (i=1; i<=T; i++) K[label[i].first]=i;
	ans=1;
	for (i=1; i<=T; i++) {
		if (vis[i]) continue;
		p=-label[i].first.second; q=label[i].first.first;
		_gcd=__gcd(p,q);
		p/=_gcd,q/=_gcd;
		r=K[make_pair(p,q)];
		if (!r) {
			p=label[i].first.second; q=-label[i].first.first;
			_gcd=__gcd(p,q);
			p/=_gcd,q/=_gcd;
			r=K[make_pair(p,q)];
		}
		if (r) {
			ans=ans*(power(2,label[i].second)+power(2,label[r].second)-1)%mod;
			if (ans<0) ans+=mod;
			vis[i]=vis[r]=1;
		}
		else {
			ans=ans*power(2,label[i].second)%mod;
			vis[i]=1;
		}
		//printf("%lld %d\n",ans,T);
	}
	ans=(ans-1)%mod;
	if (ans<0) ans+=mod;
	printf("%lld\n",ans);
	return 0;
}