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 11.0.6) (judge verdict: Runtime Error)

//make sure to make new file!
import java.io.*;
import java.util.*;

public class Main{

   public static long MOD = 1000000007L;
   
   public static void main(String[] args)throws IOException{
      BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
      PrintWriter out = new PrintWriter(System.out);
      
      int n = Integer.parseInt(f.readLine());
      
      long[] pow2 = new long[200005];
      
      pow2[0] = 1L;
      for(int k = 1; k < 200005; k++){
         pow2[k] = pow2[k-1]*2L;
      }
      
      
      
      Vec[] array = new Vec[n];
      HashMap<Vec,Integer> hmap = new HashMap<Vec,Integer>();
      for(int k = 0; k < n; k++){
         StringTokenizer st = new StringTokenizer(f.readLine());
         
         long a = Long.parseLong(st.nextToken());
         long b = Long.parseLong(st.nextToken());
         
         long neg = 1;
         if(a < 0) neg*=-1;
         if(b < 0) neg*=-1;
         
         a = Math.abs(a);
         b = Math.abs(b); 
         
         long gcd = gcd(a,b);
         
         array[k] = new Vec(a/gcd,b/gcd,neg);  
         
         if(hmap.containsKey(array[k])){
            hmap.put(array[k],hmap.get(array[k])+1);
         } else {
            hmap.put(array[k],1);
         }    
         
      }
      
      
      long answer = 1L;
      
      HashSet<Vec> seen = new HashSet<Vec>();
      
      for(Vec v : hmap.keySet()){
         if(seen.contains(v)){
            continue;
         }
         if(hmap.containsKey(getrec(v))){
            answer = (answer*(pow2[hmap.get(v)] + pow2[hmap.get(getrec(v))]-1) + MOD)%MOD;
            seen.add(getrec(v));
         } else {
            answer = (answer*pow2[hmap.get(v)] + MOD)%MOD;
         }
      }
      
      answer--;
      out.println(answer);
      
      
      
      
      out.close();
   }
   
   public static Vec getrec(Vec v){
      return new Vec(v.run,v.rise,v.sign*-1);
   }
   
   public static long gcd(long a, long b){
      if(a==b) return a;
      if(a > b){
         if(b == 0) return a;
         return gcd(a%b,b);
      } else {
         if(a == 0) return b;
         return gcd(b%a,a);
      }
   }
   
   public static class Vec{
      long rise;
      long run;
      long sign;
      public Vec(long a, long b, long c){
         rise = a;
         run = b;
         sign = c;
      }
      
      public boolean equals(Object o){
         Vec v = (Vec)o;
         return rise == v.rise && run == v.run && sign == v.sign;
      }
      public int hashCode(){
         return toString().hashCode();
      }
      public String toString(){
         return "" + rise + " " + run + " " + sign;
      } 
      
   }
      
}