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;
typedef long long lint;
typedef vector<lint> vlint;

#define inf 1e+9
#define endl "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define rep_rev(i, n) for (int i = n-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()

#define pb push_back
#define eb emplace_back
#define Size(c) (int)(c).size()

#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))

template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

template <class T, class S> inline bool chmax(T &a, S b) {
    if(a < b) {a = b;return 1;} return 0;
}
template <class T, class S> inline bool chmin(T &a, S b) {
    if(a > b) {a = b;return 1;} return 0;
}
template <class T>
void line(vector<T> &x){for (auto&& xi : x) cin >> xi;}

inline void IN(void){ return;}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){ cin >> first; IN(rest...); return;}

#define INT(...) int __VA_ARGS__; IN (__VA_ARGS__)
#define LINT(...) lint __VA_ARGS__; IN (__VA_ARGS__)
#define STR(...) string __VA_ARGS__; IN(__VA_ARGS__)

template <class T> void UNIQUE(vector<T> &x) {
    sort(all(x)); x.erase(unique(all(x)), x.end());
}
template <class T> void print_vec(T first, T end){
    for (auto i = first; i < end - 1; i++) cout << *i << " ";
    cout << *(end-1) << endl;
}

template<class... T>
void debug_print(T... args){
    vector<lint> tmp = initializer_list<lint>{args...};
    print_vec(all(tmp));
}
template<class T>
void print(T a){ cout << a << endl;}

vector<string> Yes = {"No", "Yes"};
vector<string> YES = {"NO", "YES"};

int ord(char x){ return (int)(x - 'a');}
char chr(lint x){ return (char)(x + (lint)('a'));}
lint mod = 1e9+7;
// lint mod = 

lint sum(vlint a){lint ret = 0; for(auto&& v:a) ret += v; return ret;}
lint vmini(vlint a, lint &index){
    lint ret = LLONG_MAX;
    rep(i, Size(a)){ if (chmin(ret, a[i])) index = i;}
    return ret;
}
lint vmaxi(vlint a, lint &index){
    lint ret = -LLONG_MAX;
    rep(i, Size(a)){ if (chmax(ret, a[i])) index = i;}
    return ret;
}

lint vmin(vlint a){
    lint ret = LLONG_MAX; for (auto && v : a) chmin(ret, v); return ret;
}
lint vmax(vlint a){
    lint ret = -LLONG_MAX; for (auto && v : a) chmax(ret, v); return ret;
}

void convert(vlint &x){
  if (x[1] < 0){
    x[0] *= -1; x[1] *= -1;
  }
  if (x[0] == 0 && x[1] == 0) return;
  else if (x[0] == 0){
    x[1] = 1; return;
  }
  else if (x[1] == 0){
    x[0] = 1; return;
  }
  lint y = __gcd(x[0], x[1]);
  x[0] /= y;
  x[1] /= y;
}

int main(){
    LINT(n);
    vector<vlint> ab(n, vlint(2));
    rep(i, n) cin >> ab[i][0] >> ab[i][1];
    lint mod = 1e9+7;
    vlint Ex2(n+1, 1);
    rep(i, n){
      Ex2[i+1] = Ex2[i] * 2 % mod;
    }
    map<lint, map<lint, lint>> fish;
    map<lint, map<lint, lint>> count;
    for (auto&& p : ab){
      convert(p);
      fish[p[0]][p[1]] ++;
      count[p[0]][p[1]] = 0;
    }
    lint ans = 0;
    vector<vlint> check = {{0, 0}};
    for (auto&& [a, w] : fish){
      for (auto&& [b, cnt] : w){
        if (cnt == 0) continue;
        if (a == 0 && b == 0){
          ans++; continue;
        }
        else if (a == 0 || b == 0 && count[b][a] == 0){
          if (fish[b][a] == 0){
            check[0][0] += cnt; continue;
          }
          check.pb({cnt, fish[b][a]});
          count[b][a] = 1;
        }
        else if (a < 0 && count[b][-a] == 0){
          if (fish[b][-a] == 0){
            check[0][0] += cnt; continue;
          }
          check.pb({cnt, fish[b][-a]});
          count[b][-a] = 1;
        }
        else if (count[-b][a] == 0){
          if (fish[-b][a] == 0){
            check[0][0] += cnt; continue;
          }
          check.pb({cnt, fish[-b][a]});
          count[-b][a] = 1;
        }
        count[a][b] = 1;
      }
    }
    if (ans == 0) ans = 1; 
    for (auto&& v : check){
      ans *= ((Ex2[v[0]] - 1) + (Ex2[v[1]] - 1) + 1)%mod;
      ans %= mod;
    }
    ans --; if (ans < 0) ans += mod;
    print(ans);
}