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: Runtime Error)

#include <stdio.h>
#include <stdlib.h>

#define HASH 100003
#define Mod 1000000007

typedef struct List {
	struct List *next;
	long long a, b;
	int num;
} list;

long long gcd(long long a, long long b)
{
	if (a > b) {
		a ^= b;
		b ^= a;
		a ^= b;
	}
	if (b % a == 0) return a;
	else return gcd(b % a, a);
}

int main()
{
	int h, i, N;
	long long A[200001], B[200001], G;
	list *p, *hash[HASH] = {}, d[200001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		scanf("%lld %lld", &(A[i]), &(B[i]));
		if (A[i] == 0 && B[i] == 0);
		else if (A[i] == 0) B[i] = 1;
		else if (B[i] == 0) A[i] = 1;
		else {
			G = gcd(labs(A[i]), labs(B[i]));
			A[i] /= G;
			B[i] /= G;
			if (A[i] < 0) {
				A[i] *= -1;
				B[i] *= -1;
			}
		}
		h = (A[i] % HASH + B[i] % HASH * 397 + HASH) % HASH;
		for (p = hash[h]; p != NULL; p = p->next) if (p->a == A[i] && p->b == B[i]) break;
		if (p != NULL) p->num++;
		else {
			d[i].a = A[i];
			d[i].b = B[i];
			d[i].num = 1;
			d[i].next = hash[h];
			hash[h] = &(d[i]);
		}
	}
	
	long long ans = 1, pow[200001], tmp;
	list *q, *r;
	for (i = 1, pow[0] = 1; i <= N; i++) pow[i] = pow[i-1] * 2 % Mod;
	for (h = 0; h < HASH; h++) {
		for (p = hash[h]; p != NULL; p = p->next) {
			if (p->num > 0) {
				if (p->a == 0 && p->b == 0) {
					for (q = hash[1]; q != NULL; q = q->next) if (q->b == 0) break;
					for (r = hash[397]; r != NULL; r = r->next) if (r->a == 0) break;
					tmp = p->num + 1;
					if (q != NULL) {
						tmp += pow[q->num] - 1;
						q->num = 0;
					}
					if (r != NULL) {
						tmp += pow[r->num] - 1;
						r->num = 0;
					}
					ans = ans * tmp % Mod;
				} else {
					tmp = (p->b <= 0)? p->a: -(p->a);
					i = (labs(p->b) % HASH + tmp % HASH * 397 + HASH) % HASH;
					for (q = hash[i]; q != NULL; q = q->next) if (q->a == labs(p->b) && q->b == tmp) break;
					if (q == NULL) ans = ans * pow[p->num] % Mod;
					else {
						ans = ans * (pow[p->num] + pow[q->num] - 1) % Mod;
						q->num = 0;
					}
				}
			}
		}
	}
	printf("%lld\n", (ans + Mod - 1) % Mod);
	fflush(stdout);
	return 0;
}