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)

#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(lint)(n);i++)
#define REP(i,n) for(int i=1;i<=(lint)(n);i++)
#define all(V) V.begin(),V.end()
typedef long long lint;
typedef std::pair<lint, lint> P;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;
constexpr double eps = 1e-9;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
lint mypow(lint a, lint b) {
	if (!b)return 1;
	if (b & 1)return mypow(a, b - 1) * a;
	lint memo = mypow(a, b >> 1);
	return memo * memo;
}
lint modpow(lint a, lint b, lint m) {
	if (!b)return 1;
	if (b & 1)return modpow(a, b - 1, m) * a % m;
	lint memo = modpow(a, b >> 1, m);
	return memo * memo % m;
}
template<typename T>
void printArray(std::vector<T>& vec) {
	rep(i, vec.size() - 1)std::cout << vec[i] << " ";
	std::cout << vec.back() << std::endl;
}
template<typename T>
void printArray(T l, T r) {
	T rprev = r;
	rprev--;
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
std::string to_string(std::vector<int>& vec) {
	std::string res = "[";
	rep(i, vec.size() - 1)res += std::to_string(vec[i]) + ", ";
	res += std::to_string(vec.back()) + "]";
	return res;
}
class Rational {
public:
	lint num, den;
	Rational() :num(0), den(1) {}
	Rational(lint p) :num(p), den(1) {}
	Rational(lint p, lint q) :num(p), den(q) {
		reduce();
	}
	void reduce() {
		if (den < 0) {
			num = -num; den = -den;
		}
		if (num == 0)den = 1;
		else {
			lint r = gcd(abs(num), abs(den));
			num /= r; den /= r;
		}
	}
	inline bool operator<(const Rational& rhs)const {
		return (long double)num/den<(long double)rhs.num/rhs.den;
		return num * rhs.den < rhs.num * den;
	}
	inline bool operator==(const Rational& rhs)const {
		return num==rhs.num&&den==rhs.den;
	}
	inline bool operator>(const Rational& rhs)const {
		return num * rhs.den > rhs.num * den;
	}
	inline Rational& operator+=(Rational rhs) {
		lint r = lcm(this->den, rhs.den);
		num *= r / this->den;
		rhs.num *= r / rhs.den;
		den = rhs.den = r;
		num += rhs.num;
		reduce();
		return *this;
	}
	inline Rational operator-() {
		return Rational(-num, den);
	}
	inline Rational& operator-=(Rational rhs) {
		lint r = lcm(this->den, rhs.den);
		num *= r / this->den;
		rhs.num *= r / rhs.den;
		den = rhs.den = r;
		num -= rhs.num;
		reduce();
		return *this;
	}
	inline Rational& operator*=(const Rational& rhs) {
		num *= rhs.num;
		den *= rhs.den;
		reduce();
		return *this;
	}
	inline Rational& operator/=(const Rational& rhs) {
		num *= rhs.den;
		den *= rhs.num;
		reduce();
		return *this;
	}
	template<typename T> Rational operator+(const T& rhs)const { return Rational(*this) += rhs; }
	template<typename T> Rational& operator+=(const T& rhs) { return operator+=(Rational(rhs)); }
	template<typename T> Rational operator-(const T& rhs)const { return Rational(*this) -= rhs; }
	template<typename T> Rational& operator-=(const T& rhs) { return operator-=(Rational(rhs)); }
	template<typename T> Rational operator*(const T& rhs)const { return Rational(*this) *= rhs; }
	template<typename T> Rational& operator*=(const T& rhs) { return operator*=(Rational(rhs)); }
	template<typename T> Rational operator/(const T& rhs)const { return Rational(*this) /= rhs; }
	template<typename T> Rational& operator/=(const T& rhs) { return operator/=(Rational(rhs)); }

	Rational inv() const{
		return Rational(den,num);
	}
};
std::ostream& operator<<(std::ostream& ofs, const Rational& x) {
	ofs << x.num << "/" << x.den;
	return ofs;
}
template<unsigned int modulo = 1000000007>
class ModInt {
	lint value;
public:
	ModInt() : value(0) {}
	template<typename T>
	ModInt(T value = 0) : value(value) {
		if (value < 0)value = -(lint)(-value % modulo) + modulo;
		this->value = value % modulo;
	}
	inline operator int()const { return value; }
	inline ModInt& operator+=(const ModInt& x) {
		value += x.value;
		if (value >= modulo)value -= modulo;
		return *this;
	}
	inline ModInt& operator++() {
		if (value == modulo - 1)value = 0;
		else value++;
		return *this;
	}
	inline ModInt operator-()const {
		return ModInt(0) -= *this;
	}
	inline ModInt& operator-=(const ModInt& x) {
		value -= x.value;
		if (value < 0)value += modulo;
		return *this;
	}
	inline ModInt& operator--() {
		if (value == 0)value = modulo - 1;
		else value--;
		return *this;
	}
	inline ModInt& operator*=(const ModInt& x) {
		value = value * x.value % modulo;
		return *this;
	}
	inline ModInt& operator/=(ModInt rhs) {
		int exp = modulo - 2;
		while (exp) {
			if (exp & 1)*this *= rhs;
			rhs *= rhs;
			exp >>= 1;
		}
		return *this;
	}
	template<typename T> ModInt operator+(const T& rhs)const { return ModInt(*this) += rhs; }
	template<typename T> ModInt& operator+=(const T& rhs) { return operator+=(ModInt(rhs)); }
	template<typename T> ModInt operator-(const T& rhs)const { return ModInt(*this) -= rhs; }
	template<typename T> ModInt& operator-=(const T& rhs) { return operator-=(ModInt(rhs)); }
	template<typename T> ModInt operator*(const T& rhs)const { return ModInt(*this) *= rhs; }
	template<typename T> ModInt& operator*=(const T& rhs) { return operator*=(ModInt(rhs)); }
	template<typename T> ModInt operator/(const T& rhs)const { return ModInt(*this) /= rhs; }
	template<typename T> ModInt& operator/=(const T& rhs) { return operator/=(ModInt(rhs)); }
};
template<unsigned int T>
std::istream& operator>>(std::istream& ist, ModInt<T>& x) {
	lint a;
	ist >> a;
	x = a;
	return ist;
}
int n;
int a0,b0,both0;
class myhash{
public:
	lint operator()(const Rational& r)const{
		auto hash1=std::hash<lint>{}(r.num);
		auto hash2=std::hash<lint>{}(r.den);
		decltype(hash1) seed = 0;
        seed ^= hash1 + 0x9e3779b9 + (seed << 6) + (seed >> 2);
        seed ^= hash2 + 0x9e3779b9 + (seed << 6) + (seed >> 2);
        return seed;
	}
};
std::unordered_map<Rational,int,myhash> mp;
std::unordered_set<Rational,myhash> d;
int main(){
	std::cin>>n;
	rep(i,n){
		lint a,b;
		std::cin>>a>>b;
		if(a==0&&b==0)both0++;
		else if(a==0)a0++;
		else if(b==0)b0++;
		else mp[Rational(a,b)]++;
	}
	ModInt<> ans=1;
	std::vector<Rational> vec;
	for(const auto& i:mp){
		if(d.find(i.first)!=d.end())continue;
		vec.emplace_back(i.first);
		d.insert(i.first);
		d.insert(-i.first.inv());
	}
	for(const Rational& i:vec){
		ans*=modpow(2,mp[i],1000000007)+modpow(2,mp[-i.inv()],1000000007)-1;
	}
	ans*=modpow(2,a0,1000000007)+modpow(2,b0,1000000007)-1;
	ans+=both0;
	ans-=1;
	std::cout<<ans<<std::endl;
	return 0;
}