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 rep(i,n) for(int i=0;i<(n);++i)
#define Rep(i,n) for(int i=1;i<=(n);++i)
using LL = long long;
using ULL = unsigned long long;

const int mod = 1000000007;
const double pi = acos(-1.0);
const double eps = 1e-6;

struct point {
	double x, y, z;
	point(){}
	point(double x, double y): x(x), y(y) {
		z = atan2(y, x);
		if(z <= 0) z += pi, x = -x, y = -y;
	}
	bool operator < (const point& b) const {
		return z < b.z;
	}
} p[200123], q[200123];

double dot(const point& a, const point& b) {
	return a.x * b.x + a.y * b.y;
}

double cross(const point& a, const point& b) {
	return a.x * b.y - a.y * b.x;
}

LL p2[200123]{1};

int main()
{
	Rep(i, 200000) {
		p2[i] = p2[i-1] * 2;
		if(p2[i] >= mod) p2[i] -= mod;
	}
	// int a, b;
	// while(cin >> a >> b) cout << atan2(a, b) << endl;
	int n, a = 0, b = 0;
	cin >> n;
	rep(i, n) {
		double x, y;
		scanf("%lf%lf", &x, &y);
		if(abs(x) < eps && abs(y) < eps) {
			continue;
		}
		auto _ = point(x, y);
		if(_.z > pi/2) p[a++] = _;
		else q[b++] = _;
	}
	sort(p, p+a);
	sort(q, q+b);
	int c = 0, d = 0, sum = a + b;
	LL ans = 1;
	while(c < a && d < b) {
		int c1 = c + 1;
		while(c1 < a && abs(cross(p[c], p[c1])) < eps) ++c1;
		while(d < b) {
			double x = q[d].x, y = q[d].y;
			auto _ = point(-y, x);
			if(cross(_, p[c]) > eps) ++d;
			else break;
		}
		if(abs(dot(q[d], p[c])) > eps) {
			c = c1;
			continue;
		}
		int d1 = d + 1;
		while(d1 < b && abs(cross(q[d], q[d1])) < eps) ++d1;
		int x = c1 - c, y = d1 - d;
		sum -= x + y;
		int temp = p2[x] + p2[y] - 1;
		ans = ans * temp % mod;
		c = c1;
		d = d1;
	}
	ans = ans * p2[sum] % mod;
	--ans;
	ans += n - a - b;
	if(ans < 0) ans += mod;
	if(ans >= mod) ans -= mod;
	cout << ans << endl;
	return 0;
}