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++ (Clang 10.0.0) (judge verdict: Accepted)

#define _USE_MATH_DEFINES
#include <set>
#include <array>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <vector>
#include <tuple>
#include <string>
#include <math.h>
#include <time.h>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <limits>
#include <climits>
#include <numeric>
#include <functional>
#include <iomanip>
#include <cmath>

#define lnd '\n'
// #define reverse(i, n) for(ll i = n-1; i >= 0; --i)
#define from(i, n) for (ll i = 0; i < n; ++i)
#define loop(i, n) for(ll i = 0; i < n; i++)
#define REPN(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(s) (s).begin(), (s).end()
#define rALL(s) (s).rbegin(), (s).rend()
#define sz(s) (int)(s).size()
#define mk make_pair
#define pb push_back
#define sqr(s) ((s) * (s))

using namespace std;

typedef long long ll;
typedef long long int lli;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int ui;

template <class T>
T GCD (T a, T b) {
  if(a == 0) return b;
  return GCD(b%a, a);
}

template <class T>
T LCM(T a, T b){
  return a*b/GCM(a,b);
}

template <class T>
T modpow(T x, T p){
    T res = 1;
    while(p > 0){
        if(p&1) res *= x;
        x *= x;
        p /= 2;
    }
    return res;
}

template <class T>
T modpow(T x, T p, ll mod){
    T res = 1;
    while(p > 0){
        if(p&1) res = (res*x)%mod;
        x = (x*x)%mod;
        p /= 2;
    }
    return res%mod;
}

template <class T>
void print(T a[], ll n){
    for (ll i = 0; i < n; i++) std::cout << a[i] << ' ';
    cout << endl;
}

template<class T>
void printc(T c){
    for(auto const& v: c) std::cout << v << ' ';
    cout << endl;
}

struct HASH{
  size_t operator()(const pair<long,long>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};

bool pair_sort(const pair<int, int> &p1, const pair<int,int> &p2){
    if(p1.first != p2.first) return p1.first < p2.first;
    else return p1.second < p2.second;
}

const int INF = std::numeric_limits<int>::max();
const ll M_INF = std::numeric_limits<ll>::min();
const ll LL_INF = std::numeric_limits<ll>::max();

void solution();
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solution();
    return 0;
}

ll result[200005] = {0};
void fact(ll n) {
   if (n >= 0) {
      result[0] = 1;
      for (ll i = 1; i <= n; ++i) {
         result[i] = i * result[i - 1];
      }
   }
}

void dfs(ll n, ll m, ll i, vector<ll> &v){
  if(i == n){
  }else{
    for(int k = 1; k <= m; k++){
      v.push_back(k);
      dfs(n, m, i+1, v);
      v.pop_back();
    }
  
  }
}

ld calcAngle(ld h, ld m)  
{  
    if (h == 12) h = 0;  
    if (m == 60) m = 0;  
   
    ld hour_angle = 0.5 * (h * 60 + m);  
    ld minute_angle = 6 * m;  
  
    ld d = M_PI/180;
    ld angle = fabs(hour_angle - minute_angle);    
    angle = min(360 - angle, angle);  
  
    return angle*d;  
}

void solution(){
  ll n;
  cin >> n;
  ll mod = 1e9+7;
  ll z = mod - 1;
  map<pair<ll, ll>, pair<ll, ll>> pairs;
  loop(i, n){
    ll a, b;
    cin >> a >> b;
    if(a == 0 && b == 0) { 
      z++; 
      continue;
    }else if(make_pair(a, b) < make_pair(0ll, 0ll)){
      a = -a, b = -b;
    }
    ll g = gcd(abs(a), abs(b));
    a = a/g;
    b = b/g;
    if(b > 0) pairs[{a, b}].first++;
    else pairs[{-b, a}].second++;
  }

  vector<ll> pw(200200, 0);
  pw[0] = 1;

  for (ll i = 1; i < 200200; i++) {
    pw[i] = (pw[i - 1] * 2) % mod;
  }
  ll ans = 1;
  for(auto p: pairs){
    ans = ans*(pw[p.second.first] + pw[p.second.second]-1)%mod;
  }

  cout << (z+ans)%mod << endl;
}