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 <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <stack>
#include <complex>
#include <functional>
#include <tuple>

using namespace std;

#define Rep(i,a,b) for(ll i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")

using ll = long long;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右下左上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, 1, 0, -1, -1, 1, 1, -1 };

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

    void Cout(long long x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const T& x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; ++i) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }

    // 標準入出力
    struct inp {
        std::size_t szi, szj;
        inp(std::size_t _szi = 1, std::size_t _szj = 1) : szi(_szi), szj(_szj) {}
        template <typename T> operator T () const { T a; std::cin >> a; return a; }
        template <typename T> operator std::vector<T>() const { std::vector<T> a(szi); for (std::size_t i = 0; i < szi; ++i) std::cin >> a[i]; return a; }
        template <typename T> operator std::vector<std::vector<T>>() const {
            std::vector<std::vector<T>> a(szi, std::vector<T>(szj));
            for (std::size_t i = 0; i < szi; ++i) for (std::size_t j = 0; j < szj; ++j) cin >> a[i][j]; return a;
        }
    };
    inp inp1;

    ll modpow(ll a, ll n) {
        ll result = 1;
        ll base = a;
        ll mask = 1;
        while (mask <= n) {
            if (n & mask) (result *= base) %= mod;
            mask <<= 1;
            (base *= base) %= mod;
        }
        return result;
    }

    // 素因数分解 O(√N)
    template <typename T>
    std::vector<T> Factorize2Vector(T x) {
        if (x <= 1) return std::vector<T>();
        std::vector<T> r; T x0 = x;
        while (x % 2 == 0)
            x /= 2, r.push_back(2);
        for (long long f = 3; f * f <= x0; f += 2)
            while (x % f == 0)
                x /= f, r.push_back(f);
        if (x > 1) r.push_back(x);
        return r;
    }
}

int main() {

    int n = inp1;
    vector<ll> a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];
    rep(i, n) {
        ll ta = abs(a[i]);
        ll tb = abs(b[i]);
        auto facts = Factorize2Vector(tb);
        for (auto v : facts) {
            if (ta % v == 0) {
                ta /= v;
                tb /= v;
            }
        }
        
        a[i] = a[i] / abs(a[i]) * ta;
        b[i] = b[i] / abs(b[i]) * tb;
    }
    rep(i, n) cout << a[i] << " " << b[i] << endl;

    map<pair<ll, ll>, ll> mp;

    ll ans = 0LL;
    ll out_num = 0LL;
    rep(i, n) {
        ll out = mp[{a[i], b[i]}];
        ll select = i + 1 - out;
        ll add = 0LL;
        add += modpow(2, select - 2);
        ll tmp = modpow(2, i + 1) - add;
        add = add + 1 - out_num;
        out_num = tmp;
        ans %= mod;

        ++mp[{-b[i], a[i]}];
        ++mp[{b[i], -a[i]}];
    }

    Cout(ans);

    return 0;
}