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: Accepted)

#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<lint,lint> 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;
    }
};

lint gcd(lint a,lint b){
  if(b==0){
    return a;
  }
  else{
    return gcd(b,a%b);
  }
}
signed main(){
  lint n;cin>>n;
  vector<lint> a(n);
  vector<lint> b(n);
  map<P,lint> memo;
  Nums lib(n+5);
  lint cnt0=0;
  lint a0=0;lint b0=0;
  rep(i,n){
      cin>>a[i]>>b[i];
      if(a[i]==0&&b[i]==0){
          cnt0++;
          continue;
      }
      if(a[i]==0){
          ++a0;
          continue;
      }
      if(b[i]==0){
          ++b0;
          continue;
      }
    lint ba=abs(a[i]);lint bb=abs(b[i]);
    lint g=gcd(ba,bb);
    if(a[i]<0){
        a[i]*=-1;b[i]*=-1;
    }
    P buf={a[i]/g,b[i]/g};
    memo[buf]+=1;
  }
  lint res=1;
  for(auto it=memo.begin();it!=memo.end();++it){
      lint buf=0;
      P mp;
      if(it->second==0){
          continue;
      }
      mp.first=(it->first).second;
      mp.second=(it->first).first;
      
      if(mp.first<0){
          mp.first*=-1;
          //mp.second*=1;
      }
      else{
          mp.second*=-1;
      }
      lint cur=0;
      auto it2=memo.find(mp);
      if(it2!=memo.end()){
          cur+=it2->second;
          it2->second=0;
      }
      /*
      mp.first*=-1;
      mp.second*=-1;
      auto it3=memo.find(mp);
      if(it3!=memo.end()){
          cur+=it3->second;
          it3->second=0;
      }*/
      buf=lib.myPow(2,it->second,MOD);
      buf+=lib.myPow(2,cur,MOD)-1+MOD;
      buf%=MOD;
      res*=buf;
      res%=MOD;
      it->second=0;
  }
  res*=lib.myPow(2,a0,MOD)+lib.myPow(2,b0,MOD)-1;
  res%=MOD;
  res+=cnt0+MOD-1;
  res%=MOD;
  cout<<res<<"\n";
  return 0;
}