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)

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define ll long long
#define INF 1<<31-1
#define LNF 9223372036854775807
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
//#define MOD 998244353
#define NUM 200010
 
void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int abs(int a){if(a<0)return -a;return a;}
int dup(int a,int d){if(a%d==0)return a/d;else return a/d+1;}
int mod(int a,int m){if(a<0)return a%m+m;else return a%m;}

void swapl(ll* a,ll* b){ll tmp=*a;*a=*b;*b=tmp;}
ll absl(ll a){if(a<0)return -a;return a;}
ll dupl(ll a,ll d){if(a%d==0)return a/d;else return a/d+1;}
ll modl(ll a,ll m){if(a<0)return a%m+m;else return a%m;}
ll signl(ll a) {return a==0 ? 0 : (a>0? 1 : -1);}

ll GCD(ll a,ll b){ll c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
ll LCM(ll a,ll b){return a*b/GCD(a,b);}

ll factorial(ll n, ll m) {return n < m ? 1 : n*factorial(n-1, m);}

int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}


typedef struct
{
    ll a;
    ll b;
} box;

int boxa_cmp(box *a, box *b){
    return (a->a - b->a != 0) ? (a->a - b->a) : (a->b - b->b);
}

int boxa_downll(const void*a, const void*b){return boxa_cmp((box*)a, (box*)b);}

ll pow2l(ll n){
    if (n == 0)
    {
        return 1;
    }
    return (2*pow2l(n-1)%MOD);
}

int main(){
    box p[200000];
    box m[200000];
    ll pn=0, mn=0, zn0=0 , zn1=0, zn2=0, n, k;
    ll a, b, gcdab;
    ll i, j, ans=0;
    ll u, v;

    scanf("%lld", &n);    
    
    for (i = 0; i < n; i++)
    {
        scanf("%lld%lld", &a, &b);

        if (signl(a) * signl(b) == 0) {
            if(a == 0 && b==0) zn0++;
            else if(a == 0) zn1++;
            else zn2++;
        }
        else if(signl(a) * signl(b) > 0) {
            a = absl(a), b = absl(b);
            gcdab = GCD(a, b);
            a /= gcdab;
            b /= gcdab;
            p[pn].a = a;
            p[pn].b = b;
            pn++;
        }
        else
        {
            a = absl(a), b = absl(b);
            gcdab = GCD(a, b);
            a /= gcdab;
            b /= gcdab;
            // uetohatigau
            m[mn].a = b;
            m[mn].b = a;    
            mn++;
        }
    }
    qsort(p,pn,sizeof(box), boxa_downll);
    qsort(m,mn,sizeof(box), boxa_downll);

    ans = (pow2l(zn2) + MOD - 1)%MOD;
    ans = (ans + pow2l(zn1)) % MOD;

    i=j=0;
    while(i < pn && j < mn){
        if(boxa_cmp(&p[i], &m[j]) == 0) {
            for (u = 1; i + u < pn; u++) if (boxa_cmp(&p[i], &p[i+u]) != 0) break;
            for (v = 1; j + v < mn; v++) if (boxa_cmp(&m[j], &m[j+v]) != 0) break;
            
            k = (MOD + pow2l(u) - 1)%MOD;
            k = (k + pow2l(v))%MOD;

            ans = ans * k % MOD;

            i += u;
            j += v;
        }
        else {
            ans = (ans*2)%MOD;

            if(boxa_cmp(p+i, m+j) < 0) i++;
            else j++;
        }
        
    }

    ans = ans*pow2l(pn-i)%MOD;
    ans = ans*pow2l(mn-j)%MOD;

    // 0,0 の場合
    ans = (ans + zn0) % MOD;

    ans = (MOD + ans - 1) % MOD;

    printf("%lld\n", ans);

    return 0;
}