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;

typedef long long ll;
typedef pair<ll,ll> P;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

const ll mod = 1000000007;
//const ll mod = 998244353;

const int MAX_N = 200010;
ll fact[MAX_N],fact_inv[MAX_N],inv[MAX_N];

ll pow_mod(ll a,ll b) {
    ll ret;
    if (b < 0) ret = pow_mod(a,mod+b-1);
    else if (b == 0) ret = 1;
    else if (b == 1) ret = a;
    else {
        ll c = pow_mod(a,b/2);
        if (b%2) ret = (c*c)%mod*a%mod;
        else ret = c*c%mod;
    }
    return ret;
}

void init(int x) {
    fact[0] = 1;fact[1] = 1;
    for (int i = 2;i <= x;++i) fact[i] = fact[i-1]*i%mod;
    fact_inv[x] = pow_mod(fact[x],-1);
    for (int i = x;i > 0;--i) fact_inv[i-1] = fact_inv[i]*i%mod;
    for (int i = 1;i <= x;++i) inv[i] = fact_inv[i]*fact[i-1]%mod;
}

ll combi(ll a, ll b) {
    return fact[a]*fact_inv[b]%mod*fact_inv[a-b]%mod;
}

int main() {
    int n,m = 0;
    cin >> n;
    init(n);
    map<P,int> mp;
    set<P> st;
    for (int i = 0;i < n;++i) {
        ll a,b;
        scanf("%lld%lld",&a,&b);
        if (a == 0 && b == 0) {
            n--;
            m++;
            continue;
        }
        ll g = gcd(abs(a),abs(b));
        a /= g;
        b /= g;
        if (a < 0 || (a == 0 && b < 0)) {
            a *= -1;
            b *= -1;
        }
        mp[make_pair(a,b)]++;
    }
    ll ans = pow_mod(2,n)-1,s = 1;
    for (auto p : mp) {
        P q = make_pair(p.first.second,-p.first.first);
        if (q.first < 0 || (q.first == 0 && q.second < 0)) {
            q.first *= -1;
            q.second *= -1;
        }
        if (mp.find(q) == mp.end() || st.find(p.first) != st.end()) continue;
        n -= p.second+mp[q];
        (ans -= (pow_mod(2,p.second)-1)*(pow_mod(2,mp[q])-1)%mod*(pow_mod(2,n)*s%mod)%mod) %= mod;
        st.insert(p.first);
        st.insert(q);
        (s *= (pow_mod(2,p.second+mp[q])-(pow_mod(2,p.second)-1)*(pow_mod(2,mp[q])-1)%mod)%mod) %= mod;
    }
    cout << (ans+m+mod)%mod << endl;
}