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 Go (1.14.1) (judge verdict: Accepted)

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const N = 1000000007

func main() {
	sc := NewScanner()

	n := sc.ReadInt()
	cntZeroZero := 0
	battles := make(map[PairInt][]int)

	for i := 0; i < n; i++ {
		a := sc.ReadInt()
		b := sc.ReadInt()
		ra, rb := Ratio(a, b)
		if ra == 0 && rb == 0 {
			cntZeroZero++
			continue
		}

		if rb <= 0 {
			ra, rb = ReverseRatio(ra, rb)
			pair := PairInt{ra, rb}
			_, exists := battles[pair]
			if !exists {
				battles[pair] = make([]int, 2)
			}
			battles[pair][1]++
		} else {
			pair := PairInt{ra, rb}
			_, exists := battles[pair]
			if !exists {
				battles[pair] = make([]int, 2)
			}
			battles[pair][0]++
		}
	}

	cnt := 1
	for _, battle := range battles {
		cntSub := Pow(2, uint(battle[0])) + Pow(2, uint(battle[1])) - 1
		cnt = cnt * cntSub % N
	}

	cnt = (cnt + cntZeroZero - 1) % N
  	cnt = cnt + N
    cnt = cnt % N

	fmt.Println(cnt)
}

type PairInt struct {
	A int
	B int
}

// util
// *   math/simple

func Ratio(x, y int) (int, int) {
	if x == 0 {
		if y == 0 {
			return 0, 0
		}
		return 0, 1
	} else if y == 0 {
		return 1, 0
	}

	sign := 1
	if x > 0 && y < 0 {
		sign = -1
	} else if x < 0 && y > 0 {
		sign = -1
	}

	x = Abs(x)
	y = Abs(y)
	var small, big int
	if x < y {
		small, big = x, y
	} else {
		small, big = y, x
	}
	gcd := GCD(small, big)
	return x / gcd, sign * y / gcd
}

func ReverseRatio(x, y int) (int, int) {
	sign := -1
	if x == 0 || y <= 0 {
		sign = 1
	}

	return Abs(y), sign * Abs(x)
}

func GCD(smaller, bigger int) int {
	rem := bigger % smaller
	if rem == 0 {
		return smaller
	}
	return GCD(rem, smaller)
}

func Abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func Min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow(base int, exponent uint) int {
	answer := 1
	for i := uint(0); i < exponent; i++ {
		answer = answer * base % N
	}
	return answer
}

// *   io

type Scanner struct {
	bufScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	bufSc.Buffer(nil, 100000000)
	return &Scanner{bufSc}
}

func (sc *Scanner) ReadString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *Scanner) ReadInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}