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: Runtime Error)

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    int n;cin>>n;
    map<pll,ll>c,f;
    set<pll>e;
    rep(i,n){
        ll a,b;
        cin>>a>>b;
        ll GCD=gcd(abs(a),abs(b));
        a/=GCD;b/=GCD;
        if(a>=0&&b>=0){
            c[MP(abs(a),abs(b))]++;
            f[MP(abs(a),abs(b))]=1;
            f[MP(-abs(b),abs(a))]=1;
            e.insert(MP(abs(a),abs(b)));
        }
        else{
            c[MP(-abs(a),abs(b))]++;
            f[MP(-abs(a),abs(b))]=1;
            f[MP(abs(b),abs(a))]=1;
            e.insert(MP(-abs(a),abs(b)));
        }
        
    }
    vl d(n+1);
    d[0]=1;
    rep(i,n){
        d[i+1]=d[i]*2;
        d[i+1]%=MOD;
    }
    ll ans=1;
    for(auto x : e){
       
        if(f[x]==1&&f[MP(-x.S,x.F)]==1&&x.F>=0){
          ans*=(d[c[x]]+d[c[MP(-x.S,x.F)]]-1);
          f[x]=0;f[MP(-x.S,x.F)]=0;}
        else if(f[x]==1&&f[MP(x.S,-x.F)]==1&&x.F<0){
          ans*=(d[c[x]]+d[c[MP(x.S,-x.F)]]-1);
          f[x]=0;f[MP(x.S,-x.F)]=0;}
        ans%=MOD;
        while(ans<0)ans+=MOD;
    }
    ans--;
    while(ans<0)ans+=MOD;
    cout<<ans<<endl;
}