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)

#include <bits/stdc++.h>
using namespace std;
#define MODNUMBER (long long)1000000007

long long pow_mod(long long a, long long n)
{ // a^n mod MODNUMBER
	long long result = 1;
	long long a_i = a;
	long long n_tmp = n;
	while (n_tmp > 0)
	{
		if (n_tmp & 0b1)
		{
			result = (result * a_i) % MODNUMBER;
			// cout << result << "\n";
		}
		a_i = a_i * a_i % MODNUMBER;
		n_tmp = n_tmp >> 1;
	}
	return result;
}

long long fact_mod(long long k)
{ // k! mod MODNUMBER

	long long result = 1;
	for (int i = 1; i <= k; i++)
	{
		result = (result * i) % MODNUMBER;
	}
	return result;
}
vector<long long> fact_mod_vector(long long k)
{ // k! mod MODNUMBER

	vector<long long> result(k + 1, 1);
	result[0] = 1;
	for (int i = 1; i <= k; i++)
	{
		result[i] = (result[i - 1] * i) % MODNUMBER;
	}
	return result;
}

long long inv_mod(long long k)
{ // k^(-1) mod MODNUMBER

	return pow_mod(k, MODNUMBER - 2);
}

/* DONE: fact_mod()の途中経過を使いまわす実装にすれば早くなるらしい */
/* ↓ */
/* fact_mod_vector()を使ってfact_resultをあらかじめ作っておく */
/*(nの最大値で作っておく)*/
long long comb_mod(long long n, long long k, vector<long long> *fact_result)
{ // nCk mod MODNUMBER
	return ((*fact_result)[n] *
			inv_mod(((*fact_result)[k] * (*fact_result)[n - k]) % MODNUMBER)) %
		   MODNUMBER;
}

long long my_gcd(long long A, long long B)
{
	while (A > 0 && B > 0)
	{
		if (A > B)
		{
			A = A % B;
		}
		else
		{
			B = B % A;
		}
	}
	// A or B =0
	return A + B;
}

int main()
{
	//cin.tie(0);
	//ios::sync_with_stdio(false);
	int N;
	scanf("%d", &N);

	map<pair<long long, long long>, pair<long long, long long>> c; // 既約分数にして、A/Bがindex(B>0)

	for (int i = 0; i < N; i++)
	{
		long long A, B;
		scanf("%lld %lld", &A, &B);
		// cout << A << " " << B;
		if (A == 0 || B == 0)
		{
			c[make_pair(0, 0)].first++;
			break;
		}

		long long gcd = my_gcd(abs(A), abs(B));
		// cout << gcd;
		A = A / gcd;
		B = B / gcd;
		if (B < 0)
		{
			A = -A;
			B = -B;
		}
		if (A > 0)
		{
			c[make_pair(A, B)].first++;
		}
		else
		{
			c[make_pair(B, -A)].second++;
		}
	}

	long long result = 1;
	for (auto i : c)
	{
		// cout << i.first.first << " " << i.first.second << " " << i.second.first << " " << i.second.second << "\n";
		// cout << i.second.first << " " << i.second.second << "\n";
		long long tmp = ((pow_mod((long long)2, i.second.first) - (long long)1) + (pow_mod((long long)2, i.second.second) - 1) + 1) % MODNUMBER;
		// cout << tmp << "\n";
		result = ((result * tmp)+MODNUMBER) % MODNUMBER;
	}
	cout << ((result - (long long)1) + MODNUMBER) % MODNUMBER; //0
	return 0;
}
/*
Ai/Bi +Bj/Aj=0

Ci=Ai/Bi

Ci+1/Cj=0
Ci=-1/Cj
*/