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 <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template<u32 M = 1000000007>
struct modint{
    u32 val;
    modint(): val(0){}
    template<typename T>
    modint(T t){t %= (T)M; if(t < 0) t += (T)M; val = t;}

    modint pow(ll k) const {
        modint res(1), x(val);
        while(k){
            if(k&1) res *= x;
            x *= x;
            k >>= 1;
        }
        return res;
    }
    template<typename T>
    modint& operator=(T t){t %= (T)M; if(t < 0) t += (T)M; val = t; return *this;}
    modint inv() const {return pow(M-2);}
    modint& operator+=(modint a){val += a.val; if(val >= M) val -= M; return *this;}
    modint& operator-=(modint a){if(val < a.val) val += M-a.val; else val -= a.val; return *this;}
    modint& operator*=(modint a){val = (u64)val*a.val%M; return *this;}
    modint& operator/=(modint a){return (*this) *= a.inv();}
    modint operator+(modint a) const {return modint(val) +=a;}
    modint operator-(modint a) const {return modint(val) -=a;}
    modint operator*(modint a) const {return modint(val) *=a;}
    modint operator/(modint a) const {return modint(val) /=a;}
    modint operator-(){return modint(M-val);}
    bool operator==(const modint a) const {return val == a.val;}
    bool operator!=(const modint a) const {return val != a.val;}
    bool operator<(const modint a) const {return val < a.val;}
};
using mint = modint<MOD>;


template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
    os << "{";
    for (int i = 0; i < v.size(); ++i) {
        if(i) os << ", ";
        os << v[i];
    }
    return os << "}";
}

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
    return os << "{" << p.first << ", " << p.second << "}";
}


int main() {
    int n;
    cin >> n;
    vector<mint> pow2(n+1, 1);
    for (int i = 0; i < n; ++i) {
        pow2[i+1] = pow2[i]+pow2[i];
    }
    vector<pair<ll, ll>> v(n);
    vector<ll> cnt(n, 1);
    map<pair<ll, ll>, vector<int>> m;
    int p = 0, q = 0;
    for (int i = 0; i < n; ++i) {
        cin >> v[i].first >> v[i].second;
        ll g = __gcd(v[i].first, v[i].second);
        if(g){
            v[i].first /= g; v[i].second /= g;
        }
        if(v[i].first == 0 && v[i].second != 0){
            p++;
            cnt[i] = 0;
        }else if(v[i].second == 0 && v[i].first != 0) {
            q++;
            cnt[i] = 0;
        }else {
            if(v[i].first < 0) v[i].first = -v[i].first, v[i].second = -v[i].second;
            m[v[i]].emplace_back(i);
        }
    }
    mint ans = 1;
    int anss = 0;
    for (int i = 0; i < n; ++i) {
        if(!v[i].first && !v[i].second){
            anss++;
            continue;
        }
        if(!m.count(v[i])) continue;
        pair<ll, ll> co = (v[i].second < 0 ? pair<ll, ll>{-v[i].second, v[i].first} : pair<ll, ll>{v[i].second, -v[i].first});
        auto a = m.find(v[i]), b = m.find(co);
        mint val = -mint(1);
        if(a != m.end()){
            val += pow2[a->second.size()];
            m.erase(a);
        }else val += 1;
        if(b != m.end()){
            val += pow2[b->second.size()];
            m.erase(b);
        }else val += 1;
        ans *= val;
    }
    ans *= pow2[p]+pow2[q]-mint(1);
    ans += pow2[!!anss]-mint(1);
    cout << (ans-mint(1)).val << "\n";
    return 0;
}