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

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

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var N = Sarray()[0];
            var zz = 0L;
            var zx = 0L;
            var xz = 0L;
            var dct = new Dictionary<(long l, long r), (long p, long m)>();
            for (var i = 0; i < N; ++i)
            {
                var (A, B) = Slice2<long>();
                //0を含む場合
                if (0 == A * B)
                {
                    if (A == 0 && B == 0)//どう組み合わせても0になる。単品で使う
                        ++zz;
                    else if (A == 0)//(0,i),(0,0)とは組み合わせれない。他とはいける
                        ++xz;
                    else
                        ++zx;
                }
                else
                {
                    //Ai*Aj+Bi*Bj=0→Ai/Bi+Bj/Aj=0。
                    //最大公約数で割ればいい感じに扱える
                    var gcd = Gcd(Abs(A), Abs(B));
                    A /= gcd; B /= gcd;
                    if (0 < A * B)//Ai/Bi側
                    {
                        var t = (Abs(A), Abs(B));
                        if (!dct.ContainsKey(t)) dct[t] = (0, 0);
                        dct[t] = (dct[t].p + 1, dct[t].m);
                    }
                    else//Bj/Aj側
                    {
                        var t = (Abs(B), Abs(A));
                        if (!dct.ContainsKey(t)) dct[t] = (0, 0);
                        dct[t] = (dct[t].p, dct[t].m + 1);
                    }
                }
            }
            //Aiを使うときはAjを使わない。Ajを使うときはAiを使わない
            var nb = 1L;//空集合を含む
            foreach (var d in dct)
            {
                var t = ModPow(2, d.Value.p, Mod) + ModPow(2, d.Value.m, Mod) - 1;//空集合が重複なので-1
                nb = (nb * t + Mod) % Mod;
            }
            var nzx = ModPow(2, zx, Mod) * nb;//空集合を含む
            var nxz = ModPow(2, xz, Mod) * nb;//空集合を含む
                                              //nbのみを2回、空集合を2回カウントしているので減らす
            var ans = zz + nzx + nxz - nb - 1;
            WriteLine(ans);
        }
        static long Gcd(long x, long y) => y == 0 ? x : Gcd(y, x % y);
        static long ModPow(long a, long n, long mod)
        {
            var res = 1L;
            while (0 < n)
            {
                if (n % 2 != 0) res = res * a % mod;
                a = a * a % mod;
                n >>= 1;
            }
            return res;
        }
        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}