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;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

template<class T>inline bool chmax(T &a, const T &b) { if (b > a) { a = b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

template<int mod>
class ModInt {
    private:
        long long val;
    public:
        ModInt(const long long v = 0) : val(v%mod) { if (val < 0) val += mod; }
        ModInt(const ModInt &v) : val(v.val) {}
        ModInt &operator=(const long long v) { val = v; return *this; }
        ModInt &operator=(const ModInt &v) { if (this != &v) val = v.val; return *this; }
        ModInt operator+() const { return ModInt(val); }
        ModInt operator-() const { return ModInt(-val); }
        ModInt operator+(const ModInt &v) const { return ModInt(*this) += v; }
        ModInt operator-(const ModInt &v) const { return ModInt(*this) -= v; }
        ModInt operator*(const ModInt &v) const { return ModInt(*this) *= v; }
        ModInt operator/(const ModInt &v) const { return ModInt(*this) /= v; }
        ModInt &operator+=(const ModInt &v) { val += v.val; if (val >= mod) val -= mod; return *this; }
        ModInt &operator-=(const ModInt &v) { val -= v.val; if (val < 0) val += mod; return *this; }
        ModInt &operator*=(const ModInt &v) { val *= v.val; if (val >= mod) val %= mod; return *this; }
        ModInt &operator/=(const ModInt &v) { val *= v.inverse(); if (val >= mod) val %= mod; return *this; }
        ModInt &operator++() { ++val; if (val >= mod) val -= mod; return *this; }
        ModInt &operator--() { --val; if (val < 0) val += mod; return *this; }
        ModInt operator++(int) { ModInt tmp(*this); operator++(); return tmp; }
        ModInt operator--(int) { ModInt tmp(*this); operator--(); return tmp; }
        bool operator==(const ModInt &v) const { return val == v.val; }
        bool operator!=(const ModInt &v) const { return !(*this == v); }
        friend istream &operator>>(istream &s, ModInt &v) { long long tmp; s >> tmp; v = ModInt(tmp); return s; }
        friend ostream &operator<<(ostream &s, const ModInt &v) { return s << v.val; }
        ModInt inverse() const {
            long long n = val, res = 1;
            while (n > 1) {
                res *= (mod - mod / n);
                res %= mod;
                n = mod % n;
            }
            return ModInt(res);
        }
        friend ModInt modpow(ModInt v, long long n) {
            ModInt res(1);
            for ( ; n>0; n>>=1) {
                if (n & 1) res *= v;
                v *= v;
            }
            return res;
        }
};

long long gcd(long long a, long long b) {
    if (a < b) std::swap(a, b);
    if (b == 0) return a;

    while (b > 0) {
        long long buf = b;
        b = a%b;
        a = buf;
    }
    return a;
}

void solve() {
    int n;
    cin >> n;
    vector<pair<ll, ll>> ab(n);
    for (int i=0; i<n; ++i) {
        cin >> ab.at(i).first >> ab.at(i).second;
    }

    for (int i=0; i<n; ++i) {
        if (ab.at(i).first < 0 && ab.at(i).second < 0) {
            ab.at(i).first = -ab.at(i).first;
            ab.at(i).second = -ab.at(i).second;
        } else if (ab.at(i).first >= 0 && ab.at(i).second < 0) {
            ab.at(i).first = -ab.at(i).first;
            ab.at(i).second = -ab.at(i).second;
        }
        ll g = gcd(abs(ab.at(i).first), ab.at(i).second);
        if (g == 0) continue;
        ab.at(i).first /= g;
        ab.at(i).second /= g;
    }

    map<pair<ll, ll>, ll> p, m;
    for (int i=0; i<n; ++i) {
        p[make_pair(ab.at(i).first, ab.at(i).second)]++;
        if (ab.at(i).first >= 0) m[make_pair(-ab.at(i).second, ab.at(i).first)]++;
        else m[make_pair(ab.at(i).second, -ab.at(i).first)]++;
    }

    map<pair<ll, ll>, ll> pa;
    for (auto iter=p.begin(); iter!=p.end(); ++iter) {
        ll x = iter->second;
        ll y = m[iter->first];
        if (y == 0) continue;
        pa[make_pair(min(x, y), max(x, y))]++;
    }

    ModInt<MOD> res(1);
    ll cnt = n;
    for (auto iter=pa.begin(); iter!=pa.end(); ++iter) {
        auto pp = iter->first;
        ll x = pp.first, y = pp.second;
        ll c = iter->second;
        c /= 2;
        for (int i=0; i<c; ++i) {
            res *= modpow(ModInt<MOD>(2), x) + modpow(ModInt<MOD>(2), y) - 1;
        }
        cnt -= (x + y) * c;
    }
    res *= modpow(ModInt<MOD>(2), cnt);
    cout << res - 1 << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}