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>

const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

#define ALL(x) (x).begin(), (x).end()

ll gcd(ll a, ll b)
{
    return b ? gcd(b, a % b) : a;
}
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };

ll powmod(ll n, ll x)
{
    vector<ll> vll(32);
    vll[0] = n;
    FOR(i, 1, 32)
    {
        vll[i] = (vll[i - 1] * vll[i - 1]) % MOD;
    }
    ll ret = 1;
    int cnt = 0;
    while (x > 0) {
        if (x & 1) {
            ret = (ret * vll[cnt]) % MOD;
        }
        x >>= 1;
        cnt++;
    }
    return ret;
}

int main()
{
    int n;
    cin >> n;
    map<pair<ll, ll>, int> mplli;
    int zero = 0;
    REP(i, n)
    {
        ll a, b;
        cin >> a >> b;
        if (a == 0 && b == 0) {
            zero++;
            continue;
        }
        if (a < 0) {
            a *= -1;
            b *= -1;
        }
        if (a == 0 && b != 0)
            b = 1;
        if (b == 0 && a != 0)
            a = 1;
        ll g = gcd(abs(a), abs(b));
        a /= g;
        b /= g;
        mplli[{ a, b }]++;
    }
    ll ans = 1;
    set<pair<ll, ll>> spll;
    spll.insert({ 0, 0 });
    for (auto i = mplli.begin(); i != mplli.end(); i++) {
        if (spll.find(i->first) != spll.end())
            continue;
        pair<ll, ll> pll;
        if ((i->first.second) < 0)
            pll = { -(i->first).second, (i->first).first };
        else
            pll = { (i->first).second, -(i->first).first };
        int p = i->second;
        int q = mplli[pll];
        ans = (ans * (powmod(2, p) + powmod(2, q) - 1 + MOD)) % MOD;
        spll.insert(i->first);
        spll.insert(pll);
    }
    cout << (ans + zero - 1 + MOD) % MOD << endl;
}