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: Runtime Error)

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define lint long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const lint inf=1e18+7;
const int MOD=1000000007;
struct Nums{
    long long n;
    vector<long long> kaijo;
    Nums(int N){
        n=N;
        kaijo.push_back(1);
        for(long long i=1;i<=n;i++){
            kaijo.push_back((kaijo[i-1]*i)%MOD);
        }
    }
    long myPow(long x, long n, long m){
        if(n == 0)
            return 1;
        if(n % 2 == 0)
            return myPow(x * x % m, n / 2, m);
        else
            return x * myPow(x, n - 1, m) % m;
    }
    long long modinv(long long a, long long m) {
        long long b = m, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        u %= m;
        if (u < 0) u += m;
        return u;
    }
    long long comb(long long N,long long K,long long rest){
        long long res=kaijo[N]*modinv(kaijo[K],rest)%rest;
        res*=modinv(kaijo[N-K],rest);
        res%=rest;
        return res;
    }
};


int gcd(int a,int b){
  if(b==0){
    return a;
  }
  else{
    return gcd(b,a%b);
  }
}
signed main(){
  int n;cin>>n;
  vector<int> a(n);
  vector<int> b(n);
  map<P,int> memo;
  Nums lib(n+5);
  rep(i,n){
      cin>>a[i]>>b[i];
      int ba=abs(a[i]);int bb=abs(b[i]);
    int g=gcd(ba,bb);
    P buf={a[i]/g,b[i]/g};
    memo[buf]+=1;
  }
  int res=0;
  int sum=n;
  for(auto it=memo.begin();it!=memo.end();++it){
      int buf=0;

      sum-=it->second;
      P mp=it->first;
      swap(mp.first,mp.second);
      mp.first*=-1;
      int cur=sum;
      auto it2=memo.find(mp);
      if(it2!=memo.end()){
          cur-=it2->second;
      }
      mp.first*=-1;
      mp.second*=-1;
      auto it3=memo.find(mp);
      if(it3!=memo.end()){
          cur-=it3->second;
      }
      buf=lib.myPow(2,it->second,MOD)-1;
      buf*=lib.myPow(2,cur,MOD);
      buf%=MOD;
      res+=buf;
      res%=MOD;
  }
  cout<<res<<"\n";
  return 0;
}