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

int mod_pow(int n, int e, int mod){
    int ans = 1;
    n = n % mod;
    while(e != 0){
        if(e % 2 == 1){
            ans = (ans * n) % mod;
        }
        e /= 2;
        n = (n * n) % mod;
    }
    return ans;
}

int my_gcd(int n, int m){
    if(n < 0) n*=-1;
    if(m < 0) m*=-1;
    if(n < m) swap(n, m);
    if(m == 0) return n;
    else return my_gcd(m, n%m);
}

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> a_zero;
    vector<int> b_zero;
    for(int i=0; i<n; i++){
        cin >> a[i] >> b[i];
        // if(a[i] == 0) a_zero.push_back(i);
        // if(b[i] == 0) b_zero.push_back(i);
    }

    map<pair<int, int>, int> mp;
    for(int i=0; i<n; i++){
        if(a[i] == 0 && b[i] != 0){
            if(mp.find(make_pair(1,0)) != mp.end()){
                mp[make_pair(1,0)]++;
            }
            else mp[make_pair(1,0)] = 1;
        }
        else if(a[i] != 0 && b[i] == 0){
            if(mp.find(make_pair(0,1)) != mp.end()){
                mp[make_pair(0,1)]++;
            }
            else mp[make_pair(0,1)] = 1;
        }
        else if(a[i] == 0 && b[i] == 0){
            // if(mp.find(make_pair(0,0)) != mp.end()){
            //     mp[make_pair(0,0)]++;
            // }
            // else mp[make_pair(0,0)] = 1;
        }
        else{
            int g = my_gcd(a[i], b[i]);
            if(a[i] < 0){
                a[i] *= -1;
                b[i] *= -1;
            }
            pair<int, int> p = make_pair(a[i]/g, b[i]/g);
            if(mp.find(p) != mp.end()) mp[p]++;
            else mp[p] = 1;
        }
    }

    int ans = 1;
    int mod = 1e9+7;
    for(auto itr=mp.begin(); itr != mp.end(); itr++){
        pair<int, int> right;
        if(itr->first.second > 0){
            right = make_pair(itr->first.second, itr->first.first * -1);
        }
        else{
            right = make_pair(itr->first.second * (-1), itr->first.first);
        }
        int m = 0;
        if(mp.find(right) != mp.end()){
            m = mp[right];
        }
        ans = (ans * ((mod_pow(2, itr->second, mod) + mod_pow(2, m, mod) - 1) % mod))%mod;
        if(m != 0) mp[right] = 0;
        itr->second = 0;
    }
    cout << ans - 1 << endl;

    return 0;
}