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: Wrong Answer)

#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>
#include <boost/rational.hpp>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

const ll mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  std::vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

ll N;
ll A[200010], B[200010];
std::map<P, ll> mp;
std::map<ll, ll> mp0;
std::set<P> uniq;
mint two[200010];

ll gcd( ll a, ll b )
{
  return b ? gcd(b,a%b) : a;
}

P ortho( const P &p )
{
  ll a = p.first, b = p.second;
  ll p1 = b, p2 = -a;

  if( p2 < 0 )
  {
    p1 *= -1;
    p2 *= -1;
  }

  return P( p1, p2 );
}

ll cnt[2];
ll cnt0;

int main()
{
  std::cin >> N;

  rep( i, N )
    std::cin >> A[i] >> B[i];

  mint ans = 1;

  rep( i, N )
  {
    if( !A[i] && !B[i] )
    {
      cnt0 += 1;

      continue;
    }

    if( !A[i] )
    {
      cnt[0] += 1;

      continue;
    }

    if( !B[i] )
    {
      cnt[1] += 1;

      continue;
    }

    ll g = gcd(llabs(A[i]),llabs(B[i]));
    A[i] /= g;
    B[i] /= g;

    if( B[i] < 0 )
    {
      ++mp[P(-A[i], -B[i])];
    }
    else
      ++mp[P(A[i], B[i])];
  }

  two[0] = 1;

  rep( i, N+5 )
    two[i+1] = two[i]*2;

  itr( it, mp )
  {
    ll a = (it->first).first, b = (it->first).second;

    if( !uniq.count( it->first ) && !uniq.count( ortho(it->first) ) )
      uniq.emplace( it->first );
  }

  for( auto rat : uniq )
  {
    ll a = rat.first, b = rat.second;

    //std::cout << rat << ' ' << ortho(rat) << std::endl;

    //std::cout << mp[rat] << ' ' << mp[ortho(rat)] << std::endl;

    if( !mp.count(ortho(rat)) )
      ans *= two[mp[rat]];
    else
      ans *= mint(1)+two[mp[rat]]-1+two[mp[ortho(rat)]]-1;
  }

  ans *= mint(1)+two[cnt[0]]-1+two[cnt[1]]-1;

  ans += mint(cnt0);

  std::cout << ans.x-1 << std::endl;

  return 0;
}