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 OCaml (4.10.0) (judge verdict: Accepted)

Scanf.scanf "%d" (fun n ->
    let rec gcd a b = if b = 0 then a else gcd b (a mod b) in
    let agcd a b = gcd (abs a) (abs b) in

    let module M = Map.Make (struct type t = int * int let compare = compare end) in

    let rec loop i map a0 b0 c0 d0 e0 =
        if i = n then map, a0, b0, c0, d0, e0 else
            let a, b = Scanf.scanf " %d %d" (fun a b -> a, b) in
            if a = 0 && b = 0 then loop (i + 1) map a0 b0 (c0 + 1) d0 e0 else
            if a = 0 then loop (i + 1) map (a0 + 1) b0 c0 d0 e0 else
            if b = 0 then loop (i + 1) map a0 (b0 + 1) c0 d0 e0 else
            if a = b then loop (i + 1) map a0 b0 c0 (d0 + 1) e0 else
            if a = -b then loop (i + 1) map a0 b0 c0 d0 (e0 + 1) else
            let g = agcd a b in
            let a = a / g in
            let b = b / g in
            let flag = if a < 0 && b < 0 || a > 0 && b > 0 then 2 else 0 in
            let flag = if abs a < abs b then flag + 1 else flag in
            let key = if abs a < abs b then abs a, abs b else abs b, abs a in
            let (ca, cb, cc, cd) = try M.find key map with _ -> 0, 0, 0, 0 in
            let abcd = if flag = 0 then ca + 1, cb, cc, cd else
                       if flag = 1 then ca, cb + 1, cc, cd else
                       if flag = 2 then ca, cb, cc + 1, cd else
                                        ca, cb, cc, cd + 1
            in
            let map = M.add key abcd map in
            loop (i + 1) map a0 b0 c0 d0 e0
    in
    let map, a0, b0, c0, d0, e0 = loop 0 M.empty 0 0 0 0 0 in
    let m = 1_000_000_007 in
    let ( +@) a b = (a + b) mod m in
    let ( -@) a b = (((a - b) mod m) + m) mod m in
    let ( *@) a b = (a * b) mod m in

    let powmod a b =
        let rec loop r i acc =
            if i = 0 then acc else
                loop (r *@ r) (i lsr 1) (if i land 1 = 1 then r *@ acc else acc)
        in
        loop a b 1
    in

    let ans1 =
        M.fold (fun (k1, k2) (ca, cb, cc, cd) acc ->
            (powmod 2 ca +@ powmod 2 cd -@ 1) *@ (powmod 2 cb +@ powmod 2 cc -@ 1) *@ acc
        ) map 1
    in
    let ans2 = ans1 *@ (powmod 2 d0 +@ powmod 2 e0 -@ 1) in
    let ans3 = ans2 *@ (powmod 2 a0 +@ powmod 2 b0 -@ 1) in
    let ans4 = ans3 + c0 in
                       Printf.printf "%d\n" (ans4 -@ 1)
)