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;
//T+N
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

struct Frac {
    ll a, b;
    Frac() {}
    Frac(ll _a, ll _b) {
        a = _a;
        b = _b;
        ll g = __gcd(a, b);
        a /= g;
        b /= g;
        if(b < 0) {
            a *= -1;
            b *= -1;
        }
    }
    bool operator <(const Frac &other) const {
        if(a == other.a) {
            return b < other.b;
        }
        return a < other.a;
    }
    bool operator ==(const Frac &other) const {
        return a == other.a && b == other.b;
    }
    bool operator !=(const Frac &other) const {
        return a != other.a || b != other.b;
    }
};

map<Frac, ll> cnt;

ll fpow(ll x, ll p) {
    if(p == 0) {return 1;}
    ll ans = fpow(x, p / 2);
    ans = (ans * ans) % mod;
    if(p & 1) {
        return (ans * x) % mod;
    } else {
        return ans;
    }
}

const ll MAX_N = 2e5 + 10;
Frac arr[MAX_N];

Frac inv(Frac a) {
    return Frac(-a.b, a.a);
}

ll cnt1, cnt2;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll n;
    cin >> n;
    int bcnt = 0;
    ll cnta = 0, cntb = 0;
    for(ll i = 0; i < n; i ++) {
        ll a, b;
        cin >> a >> b;
        if(a == b && b == 0) {continue;}
        if(a == 0) {
            cnta ++;
        } else if(b == 0) {
            cntb ++;
        } else {
            arr[bcnt ++] = Frac(a, b);
            cnt[arr[i]] ++;
        }
    }
    ll ans = 1;
    sort(arr, arr + bcnt);
    for(ll i = 0; i < bcnt; i ++) {
        if(i == 0 || arr[i] != arr[i - 1]) {
            ll now = fpow(2, cnt[arr[i]]) + fpow(2, cnt[inv(arr[i])]) - 1;
            fix(now);
            cnt[arr[i]] = 0;
            cnt[inv(arr[i])] = 0;
            ans = (ans * now) % mod;
        }
    }
    ll now = fpow(2, cnta) + fpow(2, cntb) - 1;
    fix(now);
    ans --;
    fix(ans);
    cout << ans << endl;
    return 0;
}