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 Rust (1.42.0) (judge verdict: Runtime Error)

//! Framework <https://github.com/vain0x/procon>

#![allow(non_snake_case)]
#![allow(unused_imports)]

use std::collections::*;

pub struct Scan(Box<dyn Iterator<Item = &'static str>>); // '

impl Scan {
    fn new() -> Self {
        let mut buf = String::new();
        let read_line = move || {
            std::io::stdin().read_line(&mut buf).unwrap();
            Box::leak(buf.split_off(0).into_boxed_str()).split_whitespace()
        };
        Scan(Box::new(std::iter::repeat_with(read_line).flatten()))
    }

    pub fn word<T: std::str::FromStr>(&mut self) -> T {
        self.0.next().unwrap().parse().ok().unwrap()
    }

    pub fn list<T: std::str::FromStr>(&mut self, len: usize) -> Vec<T> {
        std::iter::repeat_with(|| self.word()).take(len).collect()
    }
}

pub fn gcd(x: i64, y: i64) -> i64 {
    if y == 0 {
        x.abs()
    } else {
        gcd(y, x % y)
    }
}

pub fn pow(x: i64, n: i64) -> i64 {
    let (mut x, mut y, mut n) = (x % P, 1_i64, n);
    while n > 0 {
        if n % 2 != 0 {
            y = (y * x) % P;
            n -= 1;
        }

        x = (x * x) % P;
        n /= 2;
    }
    y
}

const P: i64 = 1_000_000_007;

type V2 = (i64, i64);

fn main() {
    let mut scan = Scan::new();

    let N = scan.word::<usize>();
    let mut total = 0_i64;

    // A = 0, B != 0
    let mut az = 0;
    // A != 0, B = 0
    let mut bz = 0;
    // A = B = 0
    let mut zz = 0;

    let mut freq = HashMap::<V2, [usize; 2]>::new();

    for _ in 0..N {
        let A = scan.word::<i64>();
        let B = scan.word::<i64>();

        match (A, B) {
            (0, 0) => zz += 1,
            (0, _) => az += 1,
            (_, 0) => bz += 1,
            _ => {}
        }

        let (r, s) = {
            let a = A.abs();
            let b = B.abs();
            let g = gcd(a, b);
            if A.signum() == B.signum() {
                ((a / g, b / g), 0)
            } else {
                ((b / g, a / g), 1)
            }
        };

        freq.entry(r).or_insert([0, 0])[s] += 1;
    }

    // A = B = 0 のサバは他のすべてのサバと相性が悪いので、
    // このようなサバ x を含む選び方は {x} しかない。
    total += zz;

    let mut ab = 1_i64;

    for (_, xs) in freq {
        let (x, y) = (xs[0], xs[1]);

        // x 匹のサバからなるグループと y 匹のサバからなるグループは互いに仲が悪いので、
        // 「サバを1匹も選ばない」「x 匹のグループから 1..=x 匹を選ぶ」「y 匹のグループから 1..=y 匹を選ぶ」
        // の3通りのケースを考える。
        // 他のサバに関しては好きに選んでいいので、場合の数は掛け合わせていく。
        ab *= (pow(2, x as i64) + pow(2, y as i64) - 1) % P;
        ab %= P;
    }

    ab *= (pow(2, az) + pow(2, bz as i64) - 1) % P;
    ab %= P;

    // サバを1匹も選ばないケースは除く。
    ab += P - 1;

    total += ab;
    total %= P;

    println!("{}", total);
}