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<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;
ll modpow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
ll N;
P e[200010];
vector<P> pp,mm,pm,mp;
struct E
{
    ll A,B,C,D;
};

map<P,E> ptoE;
ll aZero,bZero;
int main(){
    cin>>N;
    ll ansPlus=0;
    for(ll i=0;i<N;i++){
        ll a,b;cin>>a>>b;
        if(a==0 || b==0){
            if(a==0 && b==0){
                ansPlus++;
            }else if(a==0){
                aZero++;
            }else{
                bZero++;
            }
            continue;
        }
        e[i]=P(a/gcd(abs(a),abs(b)),b/gcd(abs(a),abs(b)));
        if(a>0){
            if(b>0)pp.push_back(e[i]);
            if(b<0)pm.push_back(e[i]);
        }else{
            if(b>0)mp.push_back(e[i]);
            else mm.push_back(e[i]);
        }
    }
    for(auto p:pp){
        ptoE[p].A++;
    }
    for(auto p:pm){
        ptoE[P(-p.second,p.first)].B++;
    }
    for(auto p:mp){
        ptoE[P(p.second,-p.first)].C++;
    }
    for(auto p:mm){
        ptoE[P(-p.first,-p.second)].D++;
    }
    ll ans=1;
    for(auto p:ptoE){
        ll A=p.second.A,B=p.second.B;
        ll C=p.second.C,D=p.second.D;
        ans=ans*(modpow(2,A+D,MOD)+modpow(2,B+C,MOD)-1)%MOD;
    }
    ans=ans*((modpow(2,aZero,MOD)+modpow(2,bZero,MOD)-1)%MOD)%MOD;
    cout<<ans+ansPlus-1<<endl;
    return 0;
}