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 <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
//#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

ll mpow(ll x, ll n){ //x^n(mod M)
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}

void solve()
{
    int n;
    scanf("%d", &n);
    int i;
    int cnt0 = 0;
    map<pair<ll, ll>, pair<int, int> > z;
    for (i = 0; i < n; i++) {
        ll x, y;
        scanf("%lld%lld", &x, &y);
        if (x == 0 && y == 0) {
            cnt0++;
        }
        else {
            if (y == 0) {
                z[make_pair(1, 0)].first++;
            }
            else if (x == 0) {
                z[make_pair(1, 0)].second++;
            }
            else {
                if (x < 0) {
                    x = -x; y = -y;
                }
                int flag = 0;
                if (y < 0) {
                    flag = 1;
                    y = -y;
                }
                ll d = gcd(x, y);
                x /= d; y /= d;
                if (flag == 0) {
                    z[make_pair(x, y)].first++;
                }
                else {
                    z[make_pair(y, x)].second++;
                }
            }
        }
    }

    ll ans = 1;
    auto it = z.begin();
    for (; it != z.end(); ++it) {
        int a = it->second.first;
        int b = it->second.second;
        
        ll tmp = (mpow(2, a) + mpow(2, b) - 1 + MOD) % MOD;
        ans = ans * tmp % MOD;
    }
    ans = (ans + cnt0 - 1 +MOD) % MOD;
    printf("%lld\n", ans);

    return;
}


int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}