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 Python (3.8.2) (judge verdict: Wrong Answer)

#!/usr/bin/env python3
import sys
import math

MOD = 1000000007  # type: int


def pow2(x):
    res = 1
    a = 2
    while x > 0:
        if x & 1:
            res = (res * a) % MOD
        a = a * a % MOD
        x >>= 1
    return res

def solve(N: int, A: "List[int]", B: "List[int]"):
    m = {}

    for i in range(N):
        if A[i] == 0:
            if "0" in m:
                m["0"][0] += 1
            else:
                m["0"] = [1, 0]
            continue
        if B[i] == 0:
            if "0" in m:
                m["0"][1] += 1
            else:
                m["0"] = [0,1]


        gcd = math.gcd(A[i],B[i])

        a = A[i] // gcd
        b = B[i] // gcd
        if (a < 0 and b < 0 ) or (a > 0 and b > 0):
            key = str(abs(a)) + "/" + str(abs(b))
            if key in m:
                m[key][0] += 1
            else:
                m[key] = [1, 0]
        else:
            key =str(abs(b)) + "/" + str(abs(a))
            if key in m:
                m[key][1] += 1
            else:
                m[key] = [0, 1]

    ans = 1
    for v in m.values():
        ans = (ans * (pow2(v[0]) + pow2(v[1]) - 1)) % MOD
    print(ans-1)
            
        

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]"
    B = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, A, B)

if __name__ == '__main__':
    main()