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;
//#pragma GCC target("popcnt")  //https://godbolt.org/z/yQv94Y 

typedef long long int ll;
typedef unsigned long long int  ull;
typedef long double ld;

#define INF 1e9
#define pi 3.141592653589
#define e 2.718281828459
#define phi 1.618033988749
#define MOD 1000000007
#define printarr(arr,n){for(int i=0;i<(n);i++){cout<<arr[i]<<" ";}cout<<endl;}
#define foreach(it , l) for(auto it = l.begin(); it != l.end(); ++it)
#define xlr8 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pll pair<ll,ll>
#define vpll vector<pair<ll,ll> >
#define rev_sort(a) sort(a.rbegin(),a.rend());

struct Timer
{
    chrono::time_point<chrono::high_resolution_clock> start , end;
    chrono:: duration<float> dur;
    Timer()
    {
        start = chrono::high_resolution_clock::now();
    }
    ~Timer()
    {
        end = chrono::high_resolution_clock::now();
        dur = end - start;
        cout<<"\nTime Elapsed : " <<dur.count() << " s\n";
    }
};

ll sum() {return 0;}
template<typename T, typename... Args>
T sum(T a , Args... args)   {return a + sum(args...); }

//76149
template<int D, typename T> 
struct Vec : public vector<Vec<D - 1, T>> {
  static_assert(D >= 1, "Vector dimension must be greater than zero!");
  template<typename... Args>
  Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {
  }
};
template<typename T>
struct Vec<1, T> : public vector<T> {
  Vec(int n = 0, T val = T()) : vector<T>(n, val) {
  }
};


ll binpow(ll x, ll n,ll mod = MOD )
{
    ll ans =1;
    x = x%mod;
    while(n>=1)
    {
        if(n&1)
            ans=(ans*x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return ans;
}
int main()
{
    xlr8;
    int testCases  = 1;
    //cin>>testCases;
    while (testCases--)
    {
        const ll mod = 1000000007;
        ll n;
        cin>>n;
        map<pair<ll , ll> , ll > m , m2;
        vector<pair<ll , ll> > a(n);
        ll xz = 0 , zx = 0 , zz  = 0;
        for(int i = 0; i< n ; i++)
        {
            cin>>a[i].first>>a[i].second;
            if(a[i].first == 0 || a[i].second == 0)
            {
                if(a[i].first == 0 && a[i].second == 0)
                    zz++;
                else if(a[i].first == 0)
                    zx++;
                else 
                    xz++;
                continue;
            }
            
            int sign = ( (a[i].first > 0 && a[i].second < 0) || (a[i].first < 0 && a[i].second > 0) );
            a[i].first = abs(a[i].first) , a[i].second = abs(a[i].second);
            ll g = __gcd(a[i].first , a[i].second);
            a[i].first/=g , a[i].second/=g;

            if(sign) 
                {
                    m[{a[i].second , a[i].first}]++;
                    a[i].first*=-1;
                }
            else 
                {
                    m[{-a[i].second , a[i].first}]++;
                }
            m2[{a[i].first , a[i].second}]++;
        }
        n-=zz;
        ll ans = 1LL;
        ll cnt = 0;
        for(auto p : m2)
        {
            ll x = m[{p.first.first , p.first.second}];
            if(x > 0)
            {
                cnt+= (p.second + x);
                ll tmp = ( (binpow(2LL , p.second ) + binpow(2LL , x))%mod + (mod -1))%mod;
                int sign = ( p.first.first < 0 );
                if(sign)
                    m[{p.first.second , -p.first.first}] = 0;
                else 
                    m[{-p.first.second , p.first.first}] = 0;
                ans = (ans* tmp)%mod;
            }
        }
            ll tmp = ( (binpow(2LL , zx ) + binpow(2LL , xz))%mod + (mod -1))%mod;
            ans = (ans*tmp)%mod;
            cnt+= (zx + xz);
        ans = (ans*binpow(2 , n - cnt))%mod;
        cout<<(ans + (mod - 1)%mod)%mod<<"\n";

        
    }
    
    

    

}