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 C++ (GCC 9.2.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>
#include <climits>
#include <sstream>
using namespace std;

long long modpow(long long U){
    
    long long ans = 1;
    while(U>0){
        ans*=2;
        ans %= 1000000007;
        U--;
    }
    return ans;
    
}


int main() {
    
    int N;
    cin >> N;
    long long A,B;
    int zero = 0;
    map<pair<long long, long long>,int> mp;
    pair<long long,long long> Azero = make_pair(0,-1);
    pair<long long,long long> Bzero = make_pair(1,0);
    pair<long long,long long> pr;
    vector<pair<long long,long long>> vec;
    for(int i = 0; i < N;i++){
        cin >> A >> B;
        if(A==0&&B==0){
            zero++;
            continue;
        }else if(A == 0){
            mp[Azero]++;
            vec.push_back(Azero);
            continue;
        }else if(B == 0){
            mp[Bzero]++;
            vec.push_back(Bzero);
            continue;
        }else{
            long long g = gcd(A, B);
            if(A<0)g *= -1;
            pr = make_pair(A/g,B/g);
            mp[pr]++;
            vec.push_back(pr);
        }
    }
    sort(vec.begin(),vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    //cout << vec.size() <<endl;
    map<pair<long long, long long>,int> end;
    pair<long long, long long> u;
    long long U = 0;
    long long V = 0;
    long long ans = 1;
    for(auto v:vec){
        if(v.second<0){
            u = make_pair( -v.second,v.first);
        }else{
            u = make_pair( v.second,-v.first);
        }
        
        if(end[u]==0&&end[v]==0){
            U = mp[u];
            V = mp[v];
            // cout << u.first <<" "<<u.second<<" "<<U<<endl;
            // cout << v.first <<" "<<v.second<<" "<<V<<endl;            
            // cout <<  (modpow(U)-1) + (modpow(V)-1) + 1 <<endl;
            ans *= (modpow(U)-1)+(modpow(V)-1)+1;
            ans %= 1000000007;
            end[u]++;
            end[v]++;
        }
    }
    cout << ((ans + zero)% 1000000007 - 1)% 1000000007<<endl;
    
}