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

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::collections::{HashMap, HashSet};

const MOD: u64 = 1000000007;
const ZERO: (bool, i128, i128) = (false, 0, 0);

fn gcd(a: i128, b: i128) -> i128 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

fn make(a: i128, b: i128) -> (bool, i128, i128) {
    if a == 0 && b == 0 {
        ZERO
    } else if a == 0 {
        (false, 1, 0)
    } else if b == 0 {
        (true, 0, 1)
    } else {
        let g = gcd(a, b);
        let aa = (a / g).abs();
        let bb = (b / g).abs();
        (a * b < 0, aa, bb)
    }
}

fn flip(p: (bool, i128, i128)) -> (bool, i128, i128) {
    (!p.0, p.2, p.1)
}

fn mod_pow(mut base: u64, mut exp: u64) -> u64 {
    let mut result = 1;
    base = base % MOD;
    while exp > 0 {
        if exp % 2 == 1 {
            result = result * base % MOD;
        }
        exp = exp >> 1;
        base = base * base % MOD
    }
    result
}

fn main() {
    input! {
        n: usize,
        ab : [(i128, i128); n],
    };

    let mut m1 = HashMap::new();
    for (a, b) in ab {
        let p = make(a, b);
        *m1.entry(p).or_insert(0) += 1;
    }
    let zero = *m1.get(&ZERO).unwrap_or(&0);
    let mut ans = mod_pow(2, zero);
    let mut used = HashSet::new();
    for (&p1, &c1) in m1.iter() {
        if p1 == ZERO {
            continue;
        }
        if used.contains(&p1) {
            continue;
        }
        let p2 = flip(p1);
        used.insert(p2);
        let c2 = *m1.get(&p2).unwrap_or(&0);
        // println!("{:?} {} {:?} {}", p1, c1, p2, c2);
        // println!("{} {}", mod_pow(2, c1), mod_pow(2, c2));
        ans = ans * (mod_pow(2, c1) + mod_pow(2, c2) - 1) % MOD;
    }
    println!("{}", (ans + MOD - 1) % MOD);
}