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;

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}

#include <iostream>
#include <vector>
struct ModInt {
    long long value;
    static const long long mod; // mod must be a prime number

    ModInt(long long v = 0) : value(v % mod) {}

    ModInt pow(long long n) const {
        long long x = value, res = 1;
        while(n > 0) {
            if(n & 1) {
                res = res * x % mod;
            }
            x = x * x % mod;
            n >>= 1;
        }
        return ModInt(res);
    }

    ModInt inverse() const {
        return pow(mod - 2);
    }

    ModInt operator-() const {
        return ModInt((mod - value) % mod);
    }

    ModInt& operator+=(const ModInt& a) {
        value += a.value;
        value %= mod;
        return *this;
    }

    ModInt& operator-=(const ModInt& a) {
        value += (-a).value;
        value %= mod;
        return *this;
    }

    ModInt& operator*=(const ModInt& a) {
        value *= a.value;
        value %= mod;
        return *this;
    }

    ModInt& operator/=(const ModInt& a) {
        return (*this) *= a.inverse();
    }

    ModInt operator+(const ModInt& a) const {
        return ModInt(*this) += a;
    }

    ModInt operator-(const ModInt& a) const {
        return ModInt(*this) -= a;
    }

    ModInt operator*(const ModInt& a) const {
        return ModInt(*this) *= a;
    }

    ModInt operator/(const ModInt& a) const {
        return ModInt(*this) /= a;
    }

    bool operator==(const ModInt& a) const {
        return value == a.value;
    }

    bool operator!=(const ModInt& a) const {
        return value != a.value;
    }

    friend std::istream& operator>>(std::istream& is, ModInt& a) {
        long long v;
        is >> v;
        a = v;
        return is;
    }

    friend std::ostream& operator<<(std::ostream& os, const ModInt& a) {
        os << a.value;
        return os;
    }

    static ModInt factorial(int n) {
        static std::vector<ModInt> fact(1 << 18);
        if(fact.size() <= n) {
            fact.resize(n + 1);
        }
        if(n < 0) {
            return 0;
        }
        if(n == 0) {
            return 1;
        }
        if(fact[n] != 0) {
            return fact[n];
        }
        return fact[n] = factorial(n - 1) * n;
    }

    static ModInt combin(int n, int k) {
        if(n < 0 || k < 0 || n < k) {
            return 0;
        }
        return factorial(n) / (factorial(k) * factorial(n - k));
    }
};

const long long ModInt::mod = 1e9+7;
// const long long ModInt::mod = 998244353;
using mint = ModInt;

signed main(){
    ll n;
    cin >> n;
    vector<pair<ll,ll>> vp, vm;
    int zero = 0;

    map<pair<ll,ll>,int> mpp, mpm;
    REP(i, n){
        ll a, b;
        cin >> a >> b;
        if(a == 0 && b == 0){
            zero++;
            continue;
        }

        bool sgn = a < 0 ^ b < 0;
        a = abs(a);
        b = abs(b);
        ll g = __gcd(a,b);
        a /= g;
        b /= g;

        auto p = make_pair(a, b);

        if(sgn){
            mpm[p]++;
        }else{
            mpp[p]++;
        }
    }

    mint ans = 1;

    for(const auto& i : mpp){
        ll a = i.first.first, b = i.first.second;
        ll cp = i.second;
        auto p = make_pair(b, a);
        ll cm = mpm[p];
        mpm.erase(p);
        ans *= mint(2).pow(cp) + mint(2).pow(cm) - 1;
    }

    for(const auto& i : mpm){
        ans *= mint(2).pow(i.second);
    }

    ans += zero - 1;
    cout << ans << endl;

    return 0;
}