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>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std ;
template< class T > inl T read() {
	T x = 0 ; int f = 1 ; char k = getchar() ;
	for( ; k > '9' || k < '0'; k = getchar() ) if( k == '-' ) f = -1 ;
	for( ; k >= '0' && k <= '9'; k = getchar() ) x = x * 10 + k - '0' ;
	return x * f ;
}
template< class T > inl T read( T &x ) { return x = read<T>() ; }
int _num, _buf[20];
template< class T > il print( T x ) {
   	if( x == 0 ) return putchar( '0' ) ,void() ;
	if( x < 0 ) putchar( '-' ), x = -x ;
	while( x ) _buf[++_num] = x % 10, x /= 10 ;
	while( _num ) putchar( _buf[_num--] + '0' ) ;
}
ll mul( ll a, ll b, ll mod ) { long double c = 1. ; return ( a * b - (ll)( c * a * b / mod ) * mod ) % mod ; }
it qpow( int x, int m, int mod ) {
	int res = 1, bas = x ;
	while(m) {
		if( m & 1 ) res = ( 1ll * res * bas ) % mod ;
		bas = ( 1ll * bas * bas ) % mod, m >>= 1 ;
	}
	return res ;
}
const int N = 2e5 + 5, mod = 1e9 + 7 ;
it add( int x, int y ) {
	return x + y >= mod ? x + y - mod : x + y ;
}
it mul( int x, int y ) {
	return 1ll * x * y % mod ;
}
il inc( int &x, int y ) {
	x = add( x, y ) ;
}
int n, ans, num[2], f[N], pw[N];
ll A[N], B[N];
map< pair< ll, ll >, int > cnt;
int main() {
//	freopen( ".in", "r", stdin ) ;
//	freopen( ".out", "w", stdout ) ;
	n = read<int>(), pw[0] = 1 ;
	for( ri i = 1; i <= n; ++i ) {
		A[i] = read<ll>(), B[i] = read<ll>() ;
		pw[i] = mul( pw[i - 1], 2 ) ;
	}
	for( ri i = 1; i <= n; ++i ) {
		ans += A[i] == 0 && B[i] == 0 ;
		num[0] += A[i] == 0 && B[i] != 0 ;
		num[1] += A[i] != 0 && B[i] == 0 ;
	}
	int res = add( pw[num[0]], pw[num[1]] ) ;
	inc( res, mod - 1 ) ;
	for( ri i = 1; i <= n; ++i ) {
		if( !A[i] || !B[i] ) continue ;
		ll d = __gcd( A[i], B[i] ) ;
		pair< ll, ll > tmp = { -B[i] / d, A[i] / d } ;
		if( tmp.second < 0 )
			tmp.first = -tmp.first, tmp.second = -tmp.second ;
		cnt[tmp] += 1 ;
	}
	for( ri i = 1; i <= n; ++i ) {
		if( !A[i] || !B[i] ) continue ;
		ll d = __gcd( A[i], B[i] ) ;
		pair< ll, ll > tmp = { -B[i] / d, A[i] / d } ;
		if( tmp.second < 0 )
			tmp.first = -tmp.first, tmp.second = -tmp.second ;
		int x = cnt[tmp] ;
		cnt[tmp] = 0 ;
		tmp = { A[i] / d, B[i] / d } ;
		if( tmp.second < 0 )
			tmp.first = -tmp.first, tmp.second = -tmp.second ;
		int y = cnt[tmp] ;
		cnt[tmp] = 0 ;
		int upd = add( pw[x], pw[y] ) ;
		inc( upd, mod - 1 ) ;
		res = mul( res, upd ) ;
	}
	inc( ans, res ), inc( ans, mod - 1 ) ;
	print( ans ), puts( "" ) ;
	cerr << 1. * clock() / CLOCKS_PER_SEC << "\n" ;
	return 0;
}