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

package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

const p = 1000000007

func Pow(n, k int) int {
  m := 1
  for 1 << uint(m) <= k { m++ }
  P := make([]int, m)
  P[0] = n % p
  for i := range P[1:] { P[i + 1] = P[i] * P[i] % p }
  a := 1
  for i := 0; 0 < k; i++ {
    if k % 2 == 1 { a = a * P[i] % p }
    k /= 2
  }
  return a
}

func GCD(a, b int) int {
  if a < b { a, b = b, a }
  if b == 0 { return a }
  return GCD(b, a % b)
}

func Solve() {
  var N int
  NextInt(&N)
  F := make([]int, 3)
  MA := make(map[int]map[int]int)
  MB := make(map[int]map[int]int)
  var a, b, gcd int
  var ok bool
  for i := 0; i < N; i++ {
    NextInt(&a, &b)
    if a == 0 && b == 0 {
      F[0]++
    } else if a == 0 {
      F[1]++
    } else if b == 0 {
      F[2]++
    } else if a * b > 0 {
      gcd = GCD(AbsInt(a), AbsInt(b))
      a, b = AbsInt(a) / gcd, AbsInt(b) / gcd
      if _, ok = MA[a]; !ok { MA[a] = make(map[int]int) }
      if _, ok = MA[a][b]; !ok { MA[a][b] = 0 }
      MA[a][b]++
    } else {
      gcd = GCD(AbsInt(a), AbsInt(b))
      a, b = AbsInt(a) / gcd, AbsInt(b) / gcd
      if _, ok = MB[a]; !ok { MB[a] = make(map[int]int) }
      if _, ok = MB[a][b]; !ok { MB[a][b] = 0 }
      MB[a][b]++
    }
  }
  cnt := 1
  var v int
  var M map[int]int
  for a, M = range MA {
    for b, v = range M {
      if _, ok = MB[b][a]; ok {
        cnt = cnt * (Pow(2, v) + Pow(2, MB[b][a]) - 1) % p
      } else {
        cnt = cnt * Pow(2, v) % p
      }
    }
  }
  for a, M = range MB {
    for b, v = range M {
      if _, ok = MA[b][a]; !ok {
        cnt = cnt * Pow(2, v) % p
      }
    }
  }
  ans := (F[0] + cnt * ((Pow(2, F[1]) + Pow(2, F[2]) - 1) % p) - 1) % p
  Write(ans)
}

func main() {
  Solve()
  Output()
}

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}
func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}
func AbsInt(x int) int {
  if x < 0 { x = -x }
  return x
}