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: Wrong Answer)

import java.util.*;

public class Main {

    private static final int MOD = 1_000_000_007;

    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++) {
            A[i] = sc.nextLong();
            B[i] = sc.nextLong();
        }

        int allZero = 0;
        Map<List<Long>, Pair> map = new HashMap<>();
        for (int i = 0; i < N; i++) {
            long g = gcd(Math.abs(A[i]),Math.abs(B[i]));
            List<Long> ab = new ArrayList<>();
            List<Long> ba = new ArrayList<>();
            if (A[i] == 0 && B[i] == 0) {
                allZero++;
            } else if (A[i] == 0) {
                ab.add(0L);
                ab.add(1L);
                ba.add(-1L);
                ba.add(0L);
            } else if (B[i] == 0) {
                ab.add(1L);
                ab.add(0L);
                ba.add(0L);
                ba.add(-1L);
            } else if ((A[i] > 0 && B[i] > 0) || (A[i] < 0 && B[i] < 0) ) {
                ab.add(Math.abs(A[i])/g);
                ab.add(Math.abs(B[i])/g);
                ba.add(-1L);
                ba.add(Math.abs(B[i])/g);
                ba.add(Math.abs(A[i])/g);
            } else {
                ab.add(-1L);
                ab.add(Math.abs(A[i])/g);
                ab.add(Math.abs(B[i])/g);
                ba.add(Math.abs(B[i])/g);
                ba.add(Math.abs(A[i])/g);
            }
            if (map.containsKey(ab)) {
                map.get(ab).ab++;
            } else if (map.containsKey(ba)) {
                map.get(ba).ba++;
            } else {
                map.put(ab,new Pair(1,0));
            }
        }
        //System.out.println(map);

        long ans = 1;
        for (Map.Entry<List<Long>,Pair> ent : map.entrySet()) {
            List<Long> key = ent.getKey();
            int cntAB = ent.getValue().ab;
            int cntBA = ent.getValue().ba;
            //System.out.println("AB: " + cntAB + ", BA:"+cntBA);
            long tmp;
            if (cntBA > 0) {
                tmp = (pow(2,cntAB) + pow(2,cntBA))%MOD-1;
                tmp = tmp < 0 ? tmp+MOD : tmp;
            } else {
                tmp = pow(2,cntAB);
            }
            //System.out.println(tmp);
            ans *= tmp;
            ans %= MOD;
        }
        ans += allZero;
        ans %= MOD;
 
        System.out.println(ans-1);
    }

    private static class Pair {
        private int ab;
        private int ba;
        Pair(int ab , int ba) {
            this.ab = ab;
            this.ba = ba;
        }
    }

    private static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a%b);
    }

    private static long pow(long a, int b) {
        if (b == 0) {
            return 1;
        }
        if (b%2 == 1) {
            return a*pow(a,b-1)%MOD;
        }
        long half = pow(a,b/2);
        return half*half%MOD;
    }
}