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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define hii cout << "hii" << endl
#define int ll
#define endl '\n'
#define all(s) s.begin(), s.end()
 
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; } 
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE
 
 
const int N = 3e5 + 5;
const int MAXN = 3e5 + 5;
const int M = 3e5;
const int mod = 1e9 + 7;
const int MOD = 1e9 + 7;
const long double co = 0.0174533;
const int INF = 1e15;
const int LG = 21;
const long double PI = acos(-1);

int n;
int arr[N];

vector<int> g[N];
int pow(int a, int b, int m)
{
	int ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}


void solve()
{
	int n;
	cin >> n;
	vector<pair<int, int>> queries;
	map<pair<int, int>, int> neg;
	map<pair<int, int>, int> pos;
	map<pair<int, int>, int> zero;
	set<pair<int, int>> s;
	set<pair<int, int>> m;
	int z = 0;
	for(int i = 1; i <= n; i++)
	{
		int a, b;
		cin >> a >> b;
		if(a == 0 and b == 0)
		{
			z++;
			continue;
		}
		if(a == 0)
		{
			zero[{0, 1}]++;
			continue;
		}
		else if(b == 0)
		{
			zero[{1, 0}]++;
			continue;	
		}
		int tempa = abs(a);
		int tempb = abs(b);
		int g = __gcd(tempa, tempb);
		tempa /= g;
		tempb /= g;
		if(a < 0) tempa *= -1;
		if(b < 0) tempb *= -1;
		a = tempa;
		b = tempb;
		queries.push_back({a, b});
		if((a < 0 and b > 0) or (a > 0 and b < 0))
		{
			m.insert({abs(a), abs(b)});
			neg[{abs(a), abs(b)}]++;
		}
		else
		{
			s.insert({abs(a), abs(b)});
			pos[{abs(a), abs(b)}]++;
		}
	}
	vector<pair<int, int>> comp;
	for(auto x : s)
	{
		comp.push_back({pos[{x.first, x.second}], neg[{x.second, x.first}]});	
	}
	for(auto x : m)
	{
		if(pos.count({x.second, x.first})) continue;
		comp.push_back({0LL, neg[{x.first, x.second}]});	
	}
	comp.push_back({zero[{0, 1}], zero[{1, 0}]});
	int ret = 1;
	for(auto x : comp)
	{
		trace(x);
		int way1 = (pow(2, x.first, mod) - 1 + mod) % mod;
		int way2 = (pow(2, x.second, mod) - 1 + mod) % mod;
		way1 += 1;
		way1 += way2;
		way1 %= mod;
		ret *= way1;
		ret %= mod;
	}
	if(z)
	{
		ret += (z);
	}
	ret -= 1;
	ret += mod;
	ret %= mod;
	cout << ret << endl;
}
 
 
int32_t main() 
{	
    ios_base:: sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	    int t = 1;
	    // cin >> t;
	while(t--)solve();
	return 0;
}