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();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

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

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        v: [(i128, i128); n]
    }
    let d = 1000000007;
    let mut w: Vec<_> = v.iter().cloned().filter(|x| x.0 != 0 || x.1 != 0).map(|x| if x.0 == 0 && x.1 < 0 || x.0 < 0 {(-x.0, -x.1)} else {x}).collect();
    let ans = n - w.len();
    let n = w.len();
    w.sort_by(|x, y| (x.1 as f64).atan2(x.0 as f64).partial_cmp(&(y.1 as f64).atan2(y.0 as f64)).unwrap());
    let mut l = 0;
    while l < n && w[l].1 <= 0 {
        l += 1;
    }
    if l == n {
        println!("{}", (ans + pow_m(2, n, d) - 1) % d);
        return;
    }
    let l0 = l;
    let mut t = 1;
    let mut c = 1;
    let mut i = 1;
    while i < l0 {
        if w[i - 1].0 * w[i].1 == w[i].0 * w[i - 1].1 {
            i += 1;
            c += 1;
        } else {
            while l < n && w[i - 1].0 * w[l].0 + w[i - 1].1 * w[l].1 > 0 {
                l += 1;
                t = t * 2 % d;
            }
            if l == n {
                t = t * pow_m(2, n - l + l0 - i + c, d) % d;
                println!("{}", (ans + t - 1) % d);
                return;
            }
            if w[i - 1].0 * w[l].0 + w[i - 1].1 * w[l].1 < 0 {
                t = t * pow_m(2, c, d) % d;
            } else {
                let mut r = l + 1;
                while r < n && w[i - 1].0 * w[r].0 + w[i - 1].1 * w[r].1 == 0 {
                    r += 1;
                }
                t = t * (pow_m(2, c, d) + pow_m(2, r - l, d) - 1) % d;
                l = r;
            }
            i += 1;
            c = 1;
        }
    }
    while l < n && w[i - 1].0 * w[l].0 + w[i - 1].1 * w[l].1 > 0 {
        l += 1;
    }
    if l == n {
        t = t * pow_m(2, n - l + c, d) % d;
        println!("{}", (ans + t - 1) % d);
        return;
    }
    if w[i - 1].0 * w[l].0 + w[i - 1].1 * w[l].1 < 0 {
        t = t * pow_m(2, c, d) % d;
    } else {
        let mut r = l + 1;
        while r < n && w[i - 1].0 * w[r].0 + w[i - 1].1 * w[r].1 == 0 {
            r += 1;
        }
        t = t * (pow_m(2, c, d) + pow_m(2, r - l, d) - 1) % d;
        l = r;
    }
    t = t * pow_m(2, n - l, d) % d;
    println!("{}", (ans + t - 1) % d);
}

fn pow_m(n: usize, mut p: usize, d: usize) -> usize {
    let mut r = n;
    let mut ret = 1;
    while p > 0 {
        if p % 2 == 0 {
            r = r * r % d;
            p /= 2;
        } else {
            ret = ret * r % d;
            p -= 1;
        }
    }
    ret
}