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 Java (OpenJDK 1.8.0) (judge verdict: Wrong Answer)


import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	final static long MOD = 1000000007;
	static long modpow(long n, long y){
		if(y == 0){
			return 1;
		}else if(y == 1){
			return n % MOD;
		}else{
			if(y % 2 == 0){
				long r = modpow(n , y / 2);
				return (r * r) % MOD;
			}else{
				long r = modpow(n , y / 2);
				long r2 = (r * r) % MOD;
				return (r2 * n) % MOD;				
			}
		}
	}	
	static long gcd(long a , long b){
		if(a < b)return gcd(b, a);
		if(b == 0)return a;
		return gcd(b , a % b);
	}
	static class State{
		long a;
		long b;
		State(long a , long b){
			if(a < 0){
				a = -a;
				b = -b;
			}else if(a == 0){
				b = 1;
			}
			this.a = a;
			this.b = b;
		}
		@Override
		public boolean equals(Object obj) {
			State s = (State)obj;
			return a == s.a && b == s.b;
		}
		@Override
		public int hashCode() {
			return (int)a + 31 * (int)b;
		}
		@Override
		public String toString() {
			return a + " " + b;
		}
	}
	static long solve(long A[] , long B[]){
		HashMap<State, Integer> counter = new HashMap<State, Integer>();
		long zeros = 0;
		for(int i = 0 ; i < A.length ; ++i){
			if(A[i] == 0 && B[i] == 0){
				zeros++;
				continue;
			}
			State s = new State(A[i], B[i]);
			if(!counter.containsKey(s)){
				counter.put(s, 1);
			}else{
				int v = counter.get(s);
				counter.put(s, v + 1);				
			}
		}
		Set<State> ks = new HashSet<State>(counter.keySet());
		long ret = 1;
		for(State s : ks){
			State rs = new State(- s.b , s.a);
			int c = 0;
			int r = 0;
			if(counter.containsKey(s)){
				c = counter.get(s);
				counter.remove(s);
			}
			if(counter.containsKey(rs)){
				r = counter.get(rs);
				counter.remove(rs);
			}
			long t = modpow(2, c) + modpow(2, r) - 1;
			ret = (ret * t) % MOD;
		}
		ret -= 1;
		ret += zeros;
		return ret;
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long A[] = new long[N];
		long B[] = new long[N];
		for(int i = 0 ; i < N ; ++i){
			long a = sc.nextLong();
			long b = sc.nextLong();
			if(a != 0){
				long g = gcd(Math.abs(a) , Math.abs(b));
				A[i] = a / g;
				B[i] = b / g;				
			}else{
				A[i] = 0;
				B[i] = 1;
			}
		}
		System.out.println(solve(A , B));
	}
}