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;
using ll = long long;
const ll MOD = 1e9+7;

ll gcd(ll a,ll b)
{
	return (a%b==0?b:gcd(b,a%b));
}

template< typename T >
T mod_pow(T x, T n, const T &p) {
  T ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= p;
    (x *= x) %= p;
    n >>= 1;
  }
  return ret;
}
class bunsu
{
	public:
	ll a,b;
	bool pn;
	bunsu()
	{
		a = 0;
		b= 0;
		pn = false;
	}
	bunsu(ll a,ll b,ll pn)
	{
		this->a = a;
		this->b = b;
		this->pn = pn;
	}
	bool operator<(const bunsu& value)const
	{
		if(pn!=value.pn)return pn<value.pn;
		if(value.a!=a)return a<value.a;
		return b<value.b;
	}
};

int main()
{
	ll zero = 0;
	ll n;
	cin >> n;
	map<bunsu,ll> mp;
	map<bunsu,bool> exsit;
	vector<pair<ll,ll>> AB;
	vector<bunsu> vb;
	for(ll i = 0;i<n;i++)
	{
		ll a,b;
		cin >> a >> b;
		AB.emplace_back(a,b);
		if(a==0&&b==0)
		{
			vb.emplace_back(0,0,0);
			zero ++;
			continue;
		}
		else if(a==0)
		{
			//return 1;
			vb.emplace_back(0,1,0);
			continue;
		}
		else if(b==0)
		{
			//return 1;
			vb.emplace_back(1,0,0);
			continue;
		}
		ll G = gcd(abs(a),abs(b));

		vb.emplace_back(abs(a/G),abs(b/G),(a<0&&b>0)||(a>0&&b<0));
	}
	for(ll i = 0;i<n;i++)
	{
		exsit[vb[i]] = true;
		
		mp[vb[i]]++;
		mp[bunsu(vb[i].b,vb[i].a,!vb[i].pn)]+=0;
	}
	//ll ans = 1;
	ll add = 0;
	vector<ll> ANS;
	
	for(auto i:mp)
	{
		if(i.first.a==0&&i.first.b==0)
		{
			continue;
		}
	/*	else if(i.first.a==0)
		{
			ll qwe = n - mp[bunsu(1,0,0)] - mp[bunsu(0,0,0)]-i.second;
			ll asd = mod_pow(0LL+2,i.second,MOD)-1;
			(asd *= (mod_pow(0LL+2,qwe,MOD)+MOD))%=MOD;
			//((asd -= 2)+=MOD)%=MOD;
			if(exsit[i.first])
			{
				//ANS.push_back(asd);
				//cout<<asd<<endl;
				(add += asd)%=MOD;
			}
			continue;
		}
		else if(i.first.b==0)
		{
			ll qwe = n - mp[bunsu(0,1,0)]-mp[bunsu(0,0,0)]-i.second;
			ll asd = mod_pow(0LL+2,i.second,MOD)-1;
			(asd *= (mod_pow(0LL+2,qwe,MOD)+MOD))%=MOD;
			//((asd -= 2)+=MOD)%=MOD;
			if(exsit[i.first])
			{
				//ANS.push_back(asd);
				(add += asd)%=MOD;
				//cout<<add<<endl;
				//exsit[i.first] = false;
			}
			continue;
		}
		*/
		bunsu alt(i.first.b,i.first.a,!i.first.pn);
		ll now =  mod_pow(0LL+2,i.second,MOD)-1;
		(now += MOD)%=MOD;
		now += mod_pow(0LL+2,mp[alt],MOD)-1;
		(now += MOD)%=MOD;
		(now +=1)%=MOD;
		if(exsit[i.first])
		{
			ANS.push_back(now);
			exsit[alt] = false;
		}
		//cout<<now<<endl;
		//cout<<mp[bunsu(i.first.b,i.first.a,!i.first.pn)]<<endl;
		//cout<<i.first.a<<' '<<i.first.b<<' '<<i.first.pn<<endl;
	}
	ll ans = 1;
	for(auto i:ANS)
	{
		(ans *= i)%=MOD;
		//cout<<ans<<';'<<i<<endl;
	}
	cout<<(ans-1+add+MOD+zero)%MOD<<endl;
}