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>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-12;
constexpr double pi=3.14159265358979323846264338;
//int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
int n;
pair<double,double>p[200010];
vector<double>args;
int cnt(double x){
    return upper_bound(all(args),x+eps)-lower_bound(all(args),x-eps);
}
signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>n;
    map<double,int>mp2;
    int f=0;
    rep(i,n){
        cin>>p[i].fi>>p[i].se;
        if(p[i].fi==0&&p[i].se==0){
            f=1;
            continue;
        }
        double foo=(p[i].fi==0?pi/2:atan2(p[i].se,p[i].fi))+pi;
        while(foo>=pi/2)foo-=pi/2;
        args.pb(foo);
    }
    sort(all(args));
    double now=-1;
    rep(i,args.size()){
        if(i&&args[i]-args[i-1]<eps){
            if(now==-1){
                now=args[i-1];
            }
            double foo=now;
            while(foo>=pi/2)foo-=pi/2;
            mp2[foo]++;
        }
        else{
            now=-1;
            double foo=args[i];
            while(foo>=pi/2)foo-=pi/2;
            mp2[foo]++;
        }
    }
    args.clear();
    rep(i,n){
        if(p[i].fi==0&&p[i].se==0)continue;
        double foo=(p[i].fi==0?pi/2:atan2(p[i].se,p[i].fi))+pi;
        args.pb(foo);
    }
    sort(all(args));
    int ans=1;
    for(pair<double,int>hoge:mp2){
        double t=hoge.fi;
        vector<double>v={t,t+pi/2,t+pi,t+pi*3/2};
        int res=0;
        res++;
        rep(i,4){
            res+=modpow(2,cnt(v[i]))+mod-1;
            res%=mod;
        }
        rep(i,2){
            res+=(modpow(2,cnt(v[i]))+mod-1)%mod*(modpow(2,cnt(v[i+2]))+mod-1)%mod;
            res%=mod;
        }
        ans*=res;
        ans%=mod;
    }
    cout<<ans-1+f<<endl;
    return 0;
}