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# (.NET Core 3.1.201) (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_168
{
    class E
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            var pairs = new Dictionary<long, Dictionary<long, int>>();
            for(int i = 0; i < n; i++)
            {
                long[] ab = ReadLongs();
                long a = ab[0];
                long b = ab[1];
                if (Abs(a) > 0 && Abs(b) > 0)
                {
                    long gcd = GCD(Abs(a), Abs(b));
                    a  /= gcd;
                    b /= gcd;
                }
                else
                {
                    if (a == 0&&Abs(b)>0)
                    {
                        b = 1;
                    }
                    if (b == 0&&Abs(a)>0)
                    {
                        a = 1;
                    }
                }
                if (a < 0)
                {
                    a *= -1;
                    b *= -1;
                }
                if (!pairs.ContainsKey(a))
                {
                    pairs.Add(a, new Dictionary<long, int>());
                }
                if (!pairs[a].ContainsKey(b))
                {
                    pairs[a].Add(b, 0);
                }
                pairs[a][b]++;
            }

            long mask = 1000000000 + 7;
            long[] pow2s = new long[n + 5];
            pow2s[0] = 1;
            for(int i = 1; i < n + 5; i++)
            {
                pow2s[i] = pow2s[i - 1] * 2;
                pow2s[i] %= mask;
            }

            long res = 0;
            if (pairs.ContainsKey(0) && pairs[0].ContainsKey(0))
            {
                res += pairs[0][0];
            }
            long others = 1;
            var used = new Dictionary<long, HashSet<long>>();
            used.Add(0, new HashSet<long>());
            used[0].Add(0);
            foreach (long a in pairs.Keys)
            {
                foreach(long b in pairs[a].Keys)
                {
                    if (used.ContainsKey(a) && used[a].Contains(b))
                    {
                        continue;
                    }

                    if (pairs.ContainsKey(-b) && pairs[-b].ContainsKey(a))
                    {
                        others *= (pow2s[pairs[a][b]] + pow2s[pairs[-b][a]] - 1 + mask) % mask;

                        if (!used.ContainsKey(a))
                        {
                            used.Add(a, new HashSet<long>());
                        }
                        used[a].Add(b);
                        if (!used.ContainsKey(-b))
                        {
                            used.Add(-b, new HashSet<long>());
                        }
                        used[-b].Add(a);
                    }
                    else if (pairs.ContainsKey(b) && pairs[b].ContainsKey(-a))
                    {
                        others *= (pow2s[pairs[a][b]] + pow2s[pairs[b][-a]] - 1 + mask) % mask;

                        if (!used.ContainsKey(a))
                        {
                            used.Add(a, new HashSet<long>());
                        }
                        used[a].Add(b);
                        if (!used.ContainsKey(b))
                        {
                            used.Add(b, new HashSet<long>());
                        }
                        used[b].Add(-a);
                    }
                    else
                    {
                        others *= pow2s[pairs[a][b]];
                    }
                    others %= mask;
                }
            }
            others = (others - 1 + mask) % mask;
            res += others;
            res %= mask;
            WriteLine(res);
        }

        static long GCD(long a, long b)
        {
            if (b > a)
            {
                long temp = b;
                b = a;
                a = temp;
            }
            long c = b;
            do
            {
                c = a % b;
                a = b;
                b = c;
            } while (c > 0);
            return a;
        }

        static long LCM(long a, long b)
        {
            long c = GCD(a, b);
            return a * b / c;
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}