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 <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
#define pb push_back
#define all(c) (c).begin(), (c).end()
//#define debug(x) cout << #x << " : " << x << endl
//#define part cout << "----------------------------------\n";
#define mp make_pair
#include <iostream>

#define fastinput                     \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

LL POW(LL x, LL y)
{
    LL ans = 1;
    LL base = x;
    while (y)
    {
        if (y & 1)
        {
            ans *= base;
            ans %= MOD;
        }
        base = base * base;
        base %= MOD;
        y = y >> 1;
    }
    return ans;
}

int main()
{
    fastinput;
    LL n, i, j, k, t, temp, tc,mult,pos,neg;
    cin >> n;
    LL a[n + 1], b[n + 1];
    //zero case
    map<pair<LL, LL>, LL> freq;
    LL cnt_both = 0;
    LL neg_trouble = 0, pos_trouble = 0;
    set<pair<LL, LL>> s;
    for (i = 1; i <= n; i++)
    {
       // debug(i);
        cin >> a[i] >> b[i];
      //  debug(a[i]);
       // debug(b[i]);
        ///////////////////////////
        if (a[i] == 0 && b[i] == 0)
        {
            cnt_both++;
            continue;
        }
        /////////////////////

        if (b[i] == 0)
        {
            neg_trouble++;
        }
        else if (a[i] == 0)
        {
            pos_trouble++;
        }
        else
        {
            if (a[i] * b[i] > 0)
            {
                //positive
                LL hcf = __gcd((LL)fabs(a[i]), (LL)fabs(b[i]));
                LL num = fabs(a[i]) / hcf;
                LL denom = fabs(b[i]) / hcf;
                freq[{num, denom}]++;
              //  cout << "increenting for " << num << " " << denom << endl;
            }
            else
            {
                //negative
                LL hcf = __gcd((LL)fabs(a[i]), (LL)fabs(b[i]));
                LL num = -fabs(a[i]) / hcf;
                LL denom = fabs(b[i]) / hcf;
                freq[{num, denom}]++;
               // cout << "increenting for " << num << " " << denom << endl;
            }
        }
       // part;
    }

    LL other = 1;

    LL ans = cnt_both;
    for (auto x : freq)
    {
        //part;
        LL num = x.first.first;
        LL denom = x.first.second;
        LL num_abs = fabs(num);
        LL denom_abs = fabs(denom);
        LL parity = 1;
        if (num * denom < 0)
        {
            parity = -1;
        }
        if (s.find({num, denom}) == s.end())
        {

            pos = x.second;
            neg = 0;
            LL num_com = (-parity) * denom_abs;
            LL denom_com = num_abs;
            if (freq.find({num_com, denom_com}) == freq.end())
            {
                neg = 0;
            }
            else
            {
                neg = freq[{num_com, denom_com}];
            }

            s.insert({num, denom});
            s.insert({num_com, denom_com});
           // debug(num);
            //debug(denom);
            //debug(num_com);
           // debug(denom_com);
           // debug(pos);
           // debug(neg);
            mult = (((POW(2, pos) + POW(2, neg)) % MOD) - 1) % MOD + 100000*MOD;
            mult %= MOD;
            if(mult<0)
            {
                LL tr=4/0;
            }
            //debug(mult);
            other *= mult;
            other %= MOD;
        }
        else
        {
           // cout << "skipping \n";
           // debug(num);
           // debug(denom);
        }

       // part;
    }

    ////////////////////////
    pos=pos_trouble;
    neg=neg_trouble;
    //debug(pos_trouble);
   // debug(neg_trouble);
    mult = (((POW(2, pos) + POW(2, neg)) % MOD) - 1) % MOD + 1000*MOD;
    mult %= MOD;
   // debug(mult);
    other *= mult;
    other %= MOD;
    //////////////////////

    other = ((other - 1) % MOD + MOD) % MOD;
    ans = (cnt_both + other) % MOD;
    //debug(ans);
    cout<<ans<<endl;

    return 0;
}