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# (Mono-mcs 6.8.0.105) (judge verdict: Wrong Answer)

using System;
using System.Collections.Generic;
using static Assistant.Input;
using System.Linq;
using Assistant;

namespace ABC168E_2
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt;
            long[] A = new long[N];
            long[] B = new long[N];
            for (int i = 0; i < N; i++)
            {
                A[i] = ReadLong;
                B[i] = ReadLong;
            }

            long mod = 1000000007;

            Dictionary<string, int> P1 = new Dictionary<string, int>();
            Dictionary<string, int> P2 = new Dictionary<string, int>();
            int c00 = 0;
            int ca0 = 0;
            int c0a = 0;
            for (int i = 0; i < N; i++)
            {
                long a = A[i];
                long b = B[i];

                if (a == 0 && b == 0)
                {
                    c00++;
                }
                else if (a == 0) ca0++;
                else if (b == 0) c0a++;
                else
                {
                    long gcd = Gcd(a, b);
                    a /= gcd;
                    b /= gcd;

                    bool minus = false;
                    if (a < 0)
                    {
                        minus = true;
                        a = -a;
                    }
                    if (b < 0)
                    {
                        minus = !minus;
                        b = -b;
                    }

                    string s1 = (minus ? "" : "-") + a.ToString() + "/" + b.ToString();
                    string s2 = (minus ? "-" : "") + b.ToString() + "/" + a.ToString();
                    if (P1.ContainsKey(s1)) P1[s1]++;
                    else if (!P1.ContainsKey(s2))
                    {
                        P1.Add(s1, 1);
                    }
                    if (P2.ContainsKey(s2)) P2[s2]++;
                    else
                    {
                        P2.Add(s2, 1);
                    }
                }
            }

            //Console.WriteLine("P1");
            //foreach (var d in P1)
            //{
            //    Console.WriteLine(d);
            //}
            //Console.WriteLine("P2");
            //foreach (var d in P2)
            //{
            //    Console.WriteLine(d);
            //}

            long sum = 1;
            foreach (var d in P1)
            {
                string s = d.Key;

                long cand = 1;
                if (P2.ContainsKey(s))
                {
                    cand = (ModPow(2, d.Value, mod) + ModPow(2, P2[s], mod) - 1 + mod) % mod;
                }
                else
                {
                    cand = ModPow(2, d.Value, mod);
                }
                sum *= cand;
                sum %= mod;
            }

            sum *= ModPow(2, ca0, mod) * ModPow(2, c0a, mod) % mod;
            sum %= mod;

            sum *= ModPow(2, c00, mod);
            sum %= mod;

            Console.WriteLine(sum - 1);
        }

        /// <summary>
        /// 最大公約数
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static long Gcd(long a, long b)
        {
            if (a < b)
                // 引数を入替えて自分を呼び出す
                return Gcd(b, a);
            while (b != 0)
            {
                var remainder = a % b;
                a = b;
                b = remainder;
            }
            return a;
        }
        /// <summary>
        /// a^n (mod p)
        /// nが非常に大きい時に有効
        /// </summary>
        /// <param name="a"></param>
        /// <param name="n"></param>
        /// <param name="mod"></param>
        /// <returns></returns>
        public static long ModPow(long a, long n, long p)
        {
            if (n == 0) return 1;
            if (n == 1) return a % p;
            if (n % 2 == 1) return (a * ModPow(a, n - 1, p)) % p;

            long t = ModPow(a, n / 2, p);
            return (t * t) % p;
        }
    }


}

namespace Assistant
{
    static class Input
    {
        static List<string> line = new List<string>();
        static int index = 0;
        static String ReadNext()
        {
            if (line.Count <= index) line.AddRange(Console.ReadLine().Split());
            return line[index++];
        }
        public static int ReadInt => int.Parse(ReadNext());
        public static long ReadLong => long.Parse(ReadNext());
        public static int[] ReadInts => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static long[] NextLongs => Console.ReadLine().Split().Select(long.Parse).ToArray();
    }

    static class Debug
    {
        //drawmap
        //drawarray
    }
}