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;


const int combination_max=100000+10;
const int combination_modulo=1000000007;
vector<int64_t> factorials(combination_max);
vector<int64_t> factorials_inv(combination_max);
vector<int64_t> inverse(combination_max);
int combination_mod(int n, int k);
int prepare_combination_mod();
	

int64_t multiply_new_set(int64_t count, int c1, int c2);

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

	vector<int64_t> a(n), b(n);
	for (int i=0;i<n;++i)
	{
		cin >> a[i] >> b[i];
	}

	map<pair<int64_t,int64_t>,int> iwashi_count;
	for (int i=0;i<n;++i)
	{
		if (a[i]==0)
		{
			if (b[i]==0)
			{
				iwashi_count[make_pair(0,0)]++;
			}
			else
			{
				iwashi_count[make_pair(0,1)]++;
			}
		}
		else if (b[i]==0)
		{
			iwashi_count[make_pair(1,0)]++;
		}
		else
		{
			int64_t aa,bb;
			if (a[i]<0)
			{
				a[i]=-a[i];
				b[i]=-b[i];
			}
			int64_t g=__gcd(a[i],abs(b[i]));
			aa=a[i]/g;
			bb=b[i]/g;
			iwashi_count[make_pair(aa,bb)]++;
		}
	}

	for (pair<pair<int64_t,int64_t>,int> p : iwashi_count)
	{
		//fprintf(stderr,"(%lld %lld) %d\n",p.first.first, p.first.second, p.second);
	}

	prepare_combination_mod();
	int64_t count=1;
	int last_offset=-1;
	if (iwashi_count.count(make_pair(0,0))>0)
	{
		last_offset+=iwashi_count[make_pair(0,0)];
		iwashi_count[make_pair(0,0)]=0;
	}

	if ( (iwashi_count.count(make_pair(1,0))>0) || (iwashi_count.count(make_pair(0,1))>0) )
	{
		int c1=iwashi_count[make_pair(1,0)];
		int c2=iwashi_count[make_pair(0,1)];
		count=multiply_new_set(count,c1,c2);
		iwashi_count[make_pair(1,0)]=0;
		iwashi_count[make_pair(0,1)]=0;
	}

	for (pair<pair<int64_t,int64_t>,int> p: iwashi_count)
	{
		int c1=p.second;
		pair<int64_t,int64_t> p2=make_pair(-p.first.second,p.first.first);
		if (c1<=0)
		{
			continue;
		}

		if (iwashi_count.count(p2)>0)
		{
			//fprintf(stderr,"\t(%lld,%lld) %d, (%lld,%lld) %d\n",p.first.first,p.first.second,p.second, p2.first,p2.second,iwashi_count[p2]);
			count=multiply_new_set(count,c1,iwashi_count[p2]);
			iwashi_count[p.first]=0;
			iwashi_count[p2]=0;
		}
		else
		{
			//fprintf(stderr,"\t(%lld,%lld) %d\n",p.first.first,p.first.second,p.second );
			count=multiply_new_set(count,c1,0);
			iwashi_count[p.first];
		}
	}

	count+=last_offset;
	cout << count << endl;	

}


int64_t multiply_new_set(int64_t count, int c1, int c2)
{
	int64_t new_count=1;

	for (int i=1;i<=c1;++i)
	{
		new_count+=combination_mod(c1,i);
		new_count%=combination_modulo;
	}
	for (int i=1;i<=c2;++i)
	{
		new_count+=combination_mod(c2,i);
		new_count%=combination_modulo;
	}
	//fprintf(stderr, "%lld - (%d %d)=%lld  ",count,c1,c2,new_count);
	count*=new_count;
	count%=combination_modulo;
	//fprintf(stderr,"%lld\n",count);
	return count;
}




int prepare_combination_mod()
{
	factorials[0]=1;
	factorials[1]=1;
	factorials_inv[0]=1;
	factorials_inv[1]=1;
	inverse[1]=1;
	for (int i=2;i<combination_max;++i)
	{
		factorials[i]=factorials[i-1]*i%combination_modulo;
		inverse[i]=combination_modulo - inverse[combination_modulo%i]*(combination_modulo/i)%combination_modulo;
		factorials_inv[i]=factorials_inv[i-1]*inverse[i]%combination_modulo;
	}
}

int combination_mod(int n, int k)
{
	return factorials[n]*(factorials_inv[k]*factorials_inv[n-k]%combination_modulo)%combination_modulo;
}