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

require 'pp'

# f = Fcational.new(max, MOD)
# f.at(10) #=> 10! (mod MOD)
# f.inv(10) #=> (10!)^(-1) (mod MOD)

class Fractional
    attr_reader :mod

    def initialize(max, mod)
        @max = max
        @mod = mod
        @frac     = { 0 => 1, 1 => 1 }
        @frac_inv = { 0 => 1, 1 => 1 }
        @inv      = {         1 => 1 }

        pre_calc(max)
    end

    def pre_calc(max)
        2.upto(max) do |i|
            @frac[i] = @frac[i - 1] * i % @mod;
            @inv[i] = @mod - @inv[@mod % i] * (@mod / i) % @mod
            @frac_inv[i] = @frac_inv[i - 1] * @inv[i] % @mod
        end
    end

    def at(i)
        @frac[i]
    end

    def inv_at(i)
        @frac_inv[i]
    end
end

# precalc_fraciotnalを使う前提
# f = Fcational.new(max, mod)
# c = Combination.new(f)
# c.calc(n, r)

class Combination
    def initialize(fraction)
        @fraction = fraction
    end

    def calc(n, r)
        return 0 if n < r
        return 0 if (n < 0 || r < 0)

        denom_inv = (@fraction.inv_at(r) * @fraction.inv_at(n - r) % @fraction.mod)
        return @fraction.at(n) * denom_inv % @fraction.mod
    end
end



# n^r (mod M)
def pow(n, r, m)
    ans = 1
    i = r
    x = n
    while i > 0
        if i % 2 == 0
            i /= 2
            x = (x ** 2) % m
        else
            i -= 1
            ans = (ans * x) % m
        end
    end

    return ans
end

#puts pow(2, 10**9,10 ** 9 + 7)

MOD = 1000000007
n = gets.to_i
x_n = Array.new(n)
memo1 = Array.new(n) # Aj / Bj
memo2 = Array.new(n) # -Bi / Ai
memo3 = Hash.new(0)
memo4 = Hash.new(0)
n.times do |i|
    a, b = gets.split.map(&:to_i)
    x_n[i] = [a, b]
    memo1[i] = Rational(a, 1) / Rational(b, 1)
    memo2[i] = Rational(-b, 1) / Rational(a, 1)

    memo3[memo1[i].to_s] += 1
    memo4[memo2[i].to_s] += 1
end

f = Fractional.new(2 * (10 ** 5), MOD)
c = Combination.new(f)
#.calc(n, r)

# 2組でかぶる組み合わせの合計
dup_comb = 0
memo3.each do |k, v|
    next if memo4[k].nil?

    dup_comb += v * memo4[k]
end
dup_comb /= 2

# nC0は入らない
sum = n # nC1

2.upto(n-dup_comb) do |r|
    sum += (((sum + c.calc(n-dup_comb, r)) % MOD) * dup_comb) % MOD
end    
puts sum