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 <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); bool s=false; if(c=='-'){s=true;c=getchar_unlocked();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); int s=0; if(c=='-'){s=1;c=getchar_unlocked();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar_unlocked(); while(c==' '||c=='\n') c=getchar_unlocked(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar_unlocked(); } *s='\0'; return len; }

#define P 1000000007

int comp(const void *a, const void *b){
	if(*(long*)a==*(long*)b){
		return (*((long*)a+1)>*((long*)b+1))-(*((long*)a+1)<*((long*)b+1));
	}else{
		return (*((long*)a+0)>*((long*)b+0))-(*((long*)a+0)<*((long*)b+0));
	}
}

long gcd2(long a, long b){
	long t;
	if(a>b) t=a, a=b, b=t;
	t = b % a;
	while(t!=0){
		b = a;
		a = t;
		t = b % a;
	}
	return a;
}

int icomp(const long *a, const long *b){
	if(a[0]==b[0]){
		return (a[1]>b[1])-(a[1]<b[1]);
	}else{
		return (a[0]>b[0])-(a[0]<b[0]);
	}
}

int m[200001];

long a[200000][2], b[200000][2];
int A, B;
int main(void){
	int n=nextint();
	for(int i=0; i<n; i++){
		long x=nextlong();
		long y=nextlong();
		bool f=false;
		if(x<0){x=-x; f=!f;}
		if(y<0){y=-y; f=!f;}
		long g = gcd2(x, y);
		if(f){
			a[A][0]=x/g;
			a[A][1]=y/g;
			A++;
		}else{
			b[B][0]=y/g;
			b[B][1]=x/g;
			B++;
		}
	}
	qsort(a, A, sizeof(long)*2, comp);
	qsort(b, B, sizeof(long)*2, comp);
	m[0]=1;
	for(int i=0; i<n; i++){
		m[i+1]=m[i]*2%P;
	}
	long ans=1;
	int x=0, y=0;
	int k=0;
	while(x<A&&y<B){
		int cp = icomp(a[x], b[y]);
		if(cp<0){
			x++; k++;
			ans=ans*2%P;
		}else if(cp>0){
			y++; k++;
			ans=ans*2%P;
		}else{
			int c=1, d=1;
			x++; y++; k+=2;
			while(x<A&&a[x][0]==a[x-1][0]&&a[x][1]==a[x-1][1]){ x++; k++; c++;}
			while(y<B&&b[y][0]==b[y-1][0]&&b[y][1]==b[y-1][1]){ y++; k++; d++;}
			ans=ans*(m[c]+m[d]-1)%P;
		}
	}
	ans=ans*m[n-k]%P;
	printf("%ld\n", ans-1);
}