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)

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include<cassert>
using namespace std;
int _P=1000000007;
long long _gcd(long long a, long long b) {
	a = abs(a);
	b = abs(b);
	if(a>b) {long long tmp = a; a = b; b = tmp;}
	if(b==0) return 0;
	while(b%=a) {
		long long tmp = a;
		a = b;
		b = tmp;
	}
	return a;
}
struct pair_hash
{
	template <class T1, class T2>
	std::size_t operator() (const pair<T1, T2> &pair) const
	{
		return std::hash<T1>()(pair.first) ^ std::hash<T2>()(pair.second);
	}
};
template<class T, class P>
void addto(T& x, P& p) {
	if(x.count(p)) ++x[p];
	else x[p]=1;
}
long long tpp(int n) {
	long long res=1;
	long long p=2;
	while(n>0){
		if(n&1) res=(res*p)%_P;
		n>>=1;
		p = (p*p)%_P;
	}
	return res;
}
int main(){
	typedef pair<long long, long long> pl;
	int N;
	cin >> N;
	unordered_map<pl, int, pair_hash> pool;
	for(int i=1;i<=N;++i) {
		long long a, b;
		cin >> a >> b;
		pl p;
		if(a==0) {
			p.first = 0;
			if(b==0) {
				p.second=0;
				addto(pool, p);
			}
			else {
				p.second = 1;
				addto(pool, p);
			}
			continue;
		}
		if(b==0) {
			p.first = 1;
			p.second = 0;
			addto(pool, p);
			continue;
		}
		long long d = _gcd(a,b);
		if(a<0) {a=-a; b=-b;}
		p.first = a/d;
		p.second = b/d;
		addto(pool, p);
	}
	vector<vector<long long>> stat;
	unordered_set<pl, pair_hash> flag;
	long long reszero=0;
	for(auto& x:pool) {
//		cout << x.first.first << ',' << x.first.second << ','
//				<< x.second << '\n';
		if(x.first.first==0 && x.first.second==0) ++reszero;
		else if(flag.count(x.first)) continue;
		else
		{
			pl p;
			if(x.first.second<=0) {
				p.first = -x.first.second;
				p.second = x.first.first;
			}
			else {
				p.first = x.first.second;
				p.second = -x.first.first;
			}
//			cout << "p=" << p.first <<','<< p.second <<'\n';
			flag.insert(p);
			stat.push_back({x.second, pool.count(p)?pool[p]:0});
		}
	}
//	cout << "next" << '\n';
	long long res=1;
	for(auto& x:stat) {
//		cout << x[0] << ',' <<  x[1] << '\n';
		long long tmp = tpp(x[0]);
		if(x[1])
			tmp = (tmp + _P + tpp(x[1])-1) %_P;
		res = (res * tmp) %_P;
//		cout << "res=" << res << '\n';
	}
	cout << (res+reszero-1)%_P << endl;
	return 0;
}