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: Accepted)

use std::io::Read;
use std::collections::HashMap;
use num_integer::gcd_lcm;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let mut zero: usize = 0;
    let mut mp: HashMap<(isize, isize), (isize, isize)> = HashMap::new();
    for _ in 0..n {
        let mut x: isize = iterator.next().unwrap().parse().unwrap();
        let mut y: isize = iterator.next().unwrap().parse().unwrap();
        if x == 0 && y == 0 {
            zero += 1;
            continue;
        }
        let g: isize = gcd_lcm(x, y).0;
        x /= g;
        y /= g;
        if y < 0 {
            x = -x;
            y = -y;
        }
        if y == 0 && x < 0 {
            x = -x;
            y = -y;
        }
        let rot90: bool = x <= 0;
        if rot90 {
            let tmp = y;
            y = -x;
            x = tmp;
        }
        if rot90 {
            (*mp.entry((x, y)).or_insert((0, 0))).0 += 1;
        } else {
            (*mp.entry((x, y)).or_insert((0, 0))).1 += 1;
        }
    }

    let mut ans: usize = 1;
    for x in mp {
        let s = (x.1).0;
        let t = (x.1).1;
        let mut now = 1;
        now += mod_pow(2, s as usize) - 1;
        now %= MOD;
        now += mod_pow(2, t as usize) - 1;
        now %= MOD;
        ans = ans * now % MOD;
    }
    if ans == 0 {
        ans = MOD - 1;
    } else {
        ans -= 1;
    }
    ans = ans + zero % MOD;
    return ans.to_string();

    // let mut signs: Vec<isize> = Vec::new();
    // let mut a: Vec<usize> = Vec::new();
    // let mut b: Vec<usize> = Vec::new();
    // for _ in 0..n {
    //     let mut sign = 1;
    //     let mut ai: isize = iterator.next().unwrap().parse().unwrap();
    //     if ai < 0 {
    //         sign *= -1;
    //         ai *= -1;
    //     }
    //     let mut bi: isize = iterator.next().unwrap().parse().unwrap();
    //     if bi < 0 {
    //         sign *= -1;
    //         bi *= -1;
    //     }
    //     a.push(ai as usize);
    //     b.push(bi as usize);
    //     signs.push(sign);
    // }
    //
    // let mut counts: HashMap<(isize, usize, usize), usize> = HashMap::new();
    // for i in 0..n {
    //     let g = gcd(a[i], b[i]);
    //     let p = (signs[i], a[i] / g, b[i] / g);
    //     *counts.entry(p).or_insert(0) += 1;
    // }
    // println!("{:?}", counts);
    //
    // let mc = ModComb::init(n);
    //
    // let mut ans: usize = 0;
    // for i in 0..n {
    //     ans = (ans + 1) % MOD;
    //     let g = gcd(a[i], b[i]);
    //     let d: usize= *counts.get(&(-signs[i], b[i] / g, a[i] / g)).unwrap_or(&0);
    //     println!("{} {}", i, d);
    //     for r in 2..=(n - d - 1) {
    //         ans = (ans + mc.calc(n - d - 1, r - 1)) % MOD;
    //     }
    // }
    // return ans.to_string();
}

const MOD: usize = 1_000_000_007;

fn mod_pow(a: usize, b: usize) -> usize {
    let mut result = 1;
    for _ in 0..b {
        result = result * a % MOD;
    }
    return result
}