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)

#![allow(unused_imports)]
#![allow(dead_code)]
use datastructure::*;
use grapth::*;
use math::*;
use string_algorithm::*;
use util::*;
use input_scanner::*;

use std::cmp;
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};

fn main() {
    let mut scan = Scanner::new();
    let n: usize = scan.next();
    let mut zero = 0u64;
    let mut a0 = 0u64;
    let mut b0 = 0u64;
    let mut h: HashMap<(i64,i64), u64> = HashMap::new();
    for _ in 0..n {
        let mut a: i64 = scan.next();
        let mut b: i64 = scan.next();
        if b < 0 {
            a = -a;
            b = -b;
        }

        if a == 0 && b==0 {
            zero += 1;
        }else if a==0 {
            a0 += 1;
        }else if b==0 {
            b0 += 1;
        }else{
            let g: i64 = gcd(a.abs() as u64, b.abs() as u64) as i64;
            let e1 = h.entry((a/g,b/g)).or_insert(0);
            *e1 += 1;
        }
    }
    const MOD: u64 = 1_000_000_007;
    let mut ans: u64 = 1;
    for p in &h {
        let p1 = p.0;
        if p1.0 < 0 {
            continue;
        }
        let p2 = (-p1.1, p1.0);
        let c1 = p.1;
        if let Some(v) = h.get(&p2) {
            let c2 = v;
            ans *= pow_mod(2, *c1, MOD)  - 1 + pow_mod(2, *c2, MOD);
            ans %= MOD;
        }
    }
    for p in &h {
        let p1 = p.0;
        let c1 = p.1;
        if None == h.get(&(p1.1, -p1.0)) && None == h.get(&(-p1.1, p1.0)) {
            ans *= pow_mod(2, *c1, MOD);
            ans %= MOD;
        }
    }
    ans *= (pow_mod(2, a0, MOD) - 1) + pow_mod(2, b0, MOD);
    ans += cmp::min(1, zero);
    ans %= MOD;
    println!("{}", if ans > 0 {ans -1} else {MOD-1});
}

mod datastructure {}
mod grapth {}
mod math {
    pub fn pow_mod(mut x: u64, mut y: u64, modv: u64) -> u64 {
        let mut ret: u64 = 1;
        while y > 0 {
            if (y & 1) != 0 {
                ret = ret * x % modv;
            }
            y >>= 1;
            x = x * x % modv;
        }
        ret
    }
    pub fn gcd(a: u64, b: u64) -> u64 {
        if b == 0 {
            a
        } else {
            gcd(b, a % b)
        }
    }    
}
mod string_algorithm {}
mod util {}
mod input_scanner {
    pub struct Scanner {
        bytes: Vec<u8>,
        begin: usize,
        end: usize,
    }
    
    impl Scanner {
        pub fn new() -> Self {
            use std::io::Read;
            let mut buffer: Vec<u8> = Vec::new();
            std::io::stdin().read_to_end(&mut buffer).unwrap();
            let end = (0..buffer.len())
                .find(|i| buffer[*i].is_ascii_whitespace())
                .unwrap_or(buffer.len());
            Scanner {
                bytes: buffer,
                begin: 0,
                end: end,
            }
        }
        pub fn next<T: std::str::FromStr>(&mut self) -> T {
            let s: &str = unsafe { std::str::from_utf8_unchecked(&self.bytes[self.begin..self.end]) };
            let ret: T = s.parse::<T>().ok().expect("Parse error.");
            self.skip();
            ret
        }
        pub fn next_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }
        pub fn next_word(&mut self) -> Vec<u8> {
            let r = Vec::from(&self.bytes[self.begin..self.end]);
            self.skip();
            r
        }
        fn skip(&mut self) {
            self.begin = (self.end..self.bytes.len())
                .find(|i| !self.bytes[*i].is_ascii_whitespace())
                .unwrap_or(self.bytes.len());
            self.end = (self.begin..self.bytes.len())
                .find(|i| self.bytes[*i].is_ascii_whitespace())
                .unwrap_or(self.bytes.len());
        }
    }
}