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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define mp make_pair
#define all(x) (x).begin(), (x).end()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;

typedef tree <pii, null_type, less <pii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 2e5 + 123, MOD = 1e9 + 7;
int n, m, cnt[N];
pll a[N], b[N];
map <pll, int> ind;

int bp(int x, int y) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = (ll)res * x % MOD;
		}
		x = (ll)x * x % MOD;
		y /= 2;
	}
	return res;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	cin >> n;
	int A = 0, B = 0, bad = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i].F >> a[i].S;
		if (a[i].F == 0 && a[i].S == 0) {
			bad++;
		}	else {
			if (a[i].F == 0) {
				A++;
			}	else if (a[i].S == 0) {
				B++;
			}	else {
				ll g = __gcd(a[i].F, a[i].S);
				a[i].F /= g;
				a[i].S /= g;
				if (a[i].F > 0 && a[i].S < 0) {
					a[i].F *= -1;
					a[i].S *= -1;
				}
				if (ind.count(a[i])) {
					int & x = cnt[ind[a[i]]];
					x = x * 2 % MOD;
				}	else {
					ind[a[i]] = ++m;
					b[m] = a[i];
					cnt[m] = 2;
				}
			}
		}
	}
	A = bp(2, A) - 1, B = bp(2, B) - 1;
	int ans = (ll)(A + 1) * (B + 1) % MOD - (ll)A * B % MOD + MOD;
	if (ans >= MOD) {
		ans -= MOD;
	}
	ind.clear();
	pii need;
	for (int i = 1; i <= m; i++) {
		need = {-b[i].S, b[i].F};
		if ((need.F > 0 && need.S < 0) || (need.F < 0 && need.S < 0)) {
			need.F *= -1;
			need.S *= -1;
		}
		if (ind.count(need)) {
			int j = ind[need];
			int tmp = (ll)cnt[i] * cnt[j] % MOD - (ll)(cnt[i] - 1) * (cnt[j] - 1) % MOD + MOD;
			if (tmp >= MOD) {
				tmp -= MOD;
			}
			ans = (ll)ans * tmp % MOD;
			ans = (ll)ans * bp(cnt[j], MOD - 2) % MOD;
		}	else {
			ans = (ll)ans * cnt[i] % MOD;
		}
		ind[b[i]] = i;
	}
	ans = (ans + bad) % MOD;
	ans = (ans - 1 + MOD) % MOD;
	cout << ans;
}