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: Accepted)

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

typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> lll;

const ll MOD = 1000000007;
const ll INF = 1e9+5;
const double eps = 1e-7;
const double PI = acos(-1.0);

#define FOR(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RFOR(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define ull unsigned long long
#define deb(x )     cerr << #x << " = "<< x << endl;
#define endl    "\n"
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define fill(x, y) memset(x, y, sizeof(y))
#define all(x) (x).begin(), (x).end()
#define bitcount(x) __builtin_popcount(x)
#define cps CLOCKS_PER_SEC
#define verify(x) if(x >= MOD) x -= MOD;

inline void debug_vi(vi a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void debug_vll(vll a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void print_case(int tn) {cout<<"Case #"<<tn<<": ";}

template<typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;

template<typename T>
using maxpq = priority_queue<T>;
/*----------------------------------------------------------------------*/

//return x^y mod p
ll power(ll x,ll y, ll p)
{
    ll res = 1;     
    x = x % p; 
 
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
 
        y = y>>1; // y = y/2
        x = (x*x) % p;  
    }
    return res;
}

int main(){
    std::ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int n; cin>>n;
    vector<lll> arr(n);
    map<lll, int> cnt;
    FOR(i, 0, n) {
        cin>> arr[i].ff >> arr[i].ss;
        if(arr[i].ff || arr[i].ss) {
            ll g = __gcd(abs(arr[i].ff), abs(arr[i].ss));
            arr[i].ff /= g;
            arr[i].ss /= g;

            if(arr[i].ss < 0) {
                arr[i].ss *= -1;
                arr[i].ff *= -1;
            } else if(arr[i].ss == 0) arr[i].ff = 1; 
        }
        cnt[{arr[i].ff, arr[i].ss}]++;
    }

    // for(auto itr : cnt) {
    //     cout << itr.ff.ff << " " << itr.ff.ss << " " << itr.ss << endl;
    // }
    // cout << endl << endl << endl;

    ll res = 1;
    for(auto itr : cnt) {
        ll a, b; tie(a, b) = itr.ff;
        if(a == 0 && b == 0) continue;
        ll freq = itr.ss;
        ll reva = -b, revb = a;
        if(revb < 0) {
            revb *= -1;
            reva *= -1;
        } else if(revb == 0) reva = 1;

        if(!cnt.count({reva, revb})) {
            res *= power(2, freq, MOD);
            res %= MOD;
            continue;
        }
        if(a > reva) continue;
        ll freq2 = cnt[{reva, revb}];
        ll curr = (power(2LL, freq, MOD) + power(2LL, freq2, MOD) - 1 + MOD)%MOD;
        res *= curr; res %= MOD;
    }
    res = (res - 1 + MOD)%MOD; // choose at least one.
    res = (res + cnt[{0, 0}])%MOD;
    cout << res;
    return 0;
}