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



Sample input:
3
1 2
-1 1
2 -1


Sample output:
5

Submission status: Runtime Error

Solution code:
import collections
import fractions

n = int(input())
m = 0
mod = 10 ** 6 + 7
c = []
d = []
frac = {}
tmp = 0
for _ in range(n):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        tmp += 1
        m += 1
    try:
        if b == 0: frac[float('inf')] += 1
        else: frac[fractions.Fraction(a, b)] += 1
    except KeyError:
        if b == 0: frac[float('inf')] = 1
        else: frac[fractions.Fraction(a, b)] = 1
n -= tmp

for key, value in frac.items():
    if key > 0: continue
    try:
        if key == float('inf'):
            d.append(frac[fractions.Fraction(0)])
        else:
            d.append(frac[-1 / key])
        c.append(value)
    except KeyError:
        continue

ans = pow(2, n - sum(c) - sum(d), mod)
for i, j in zip(c, d):
    tmp = (pow(2, i, mod) + pow(2, j, mod) - 1)
    ans = (ans * (pow(2, i, mod) + pow(2, j, mod) - 1)) % mod
ans -= 1 + m

print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd
from fractions import Fraction
from numpy import sign
N=int(input())
d={}
mod = 10**9+7
d={}
zeros = 0
b_zero = 0
a_zero = 0
for i in range(N):
    a, b = map(int,input().split(' '))
    a, b = map(lambda x:x//gcd(a,b),[a,b])
    if a == b == 0:
        zeros += 1
    elif a == 0:
        a_zero += 1
    elif b == 0:
        b_zero += 1
    else:
        h,t=sorted([Fraction(a,b),Fraction(-b,a)])
        key = str(h)+'/'+str(t)
        d.setdefault(key,[0,0])
        if a*b > 0:
            d[key][0] += 1
        else:
            d[key][1] += 1
ans = 1
for  v in d.values():
    h,t=sorted(v)
    if h>0:
        ans *= pow(2,h,mod) + pow(2,t,mod) -1
    else:
        ans *= pow(2,t,mod)
    ans %=mod
ans += pow(2,a_zero,mod) + pow(2,b_zero,mod) + zeros -3
print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3

import sys
# import time
import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n = ii()
    theta = [0] * n
    zero_zero_cnt = 0
    for i in range(n):
        a, b = mi()
        if a == 0 and b == 0:
            zero_zero_cnt += 1
        elif a == 0:
            theta[i] = 90.0 if b > 0 else -90.0
        else:
            theta[i] = math.degrees(math.atan(b / a))
    theta.sort()
    # print(theta)

    eps = 10 ** (-4)
    compressed_theta = []
    cnt_theta = []
    prev = inf
    for i in range(n):
        if prev - eps <= theta[i] <= prev + eps:
            cnt_theta[-1] += 1
            prev = theta[i]
        else:
            compressed_theta.append(theta[i])
            cnt_theta.append(1)
            prev = theta[i]

    pairs = []
    no_pair_ind = set(range(len(compressed_theta)))
    for i, dg in enumerate(compressed_theta):
        l_ind = bisect_left(theta, dg - 90 - eps)
        r_ind = bisect_right(theta, dg - 90 + eps)
        if l_ind != r_ind:
            assert(r_ind == l_ind + 1)
            pairs.append((cnt_theta[l_ind], cnt_theta[i]))
            no_pair_ind.remove(l_ind)
            no_pair_ind.remove(i)
    
    num_of_no_pairs = sum([cnt_theta[ind] for ind in no_pair_ind])

    ans = pow(2, num_of_no_pairs, mod)
    for k, l in pairs:
        ans = (ans * (1 + pow(2, k, mod) - 1 + pow(2, l, mod) - 1)) % mod
    ans -= 1

    ans += zero_zero_cnt
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, cos, radians, pi, sin, gcd
from operator import mul
from functools import reduce
from operator import mul


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]

mod = 1000000007

n = I()
D = defaultdict(int)
A = []
B = []
F = []
pow2 = [1] * (n + 1)
for i in range(1, n + 1):
    pow2[i] = pow2[i - 1] * 2 % mod

ans = 1
cnt1 = 0
cnt2 = 0
for i in range(n):
    a, b = LI()
    flg = 0
    if a * b < 0:
        flg = 1
    if a == 0 and b == 0:
        continue
    a = abs(a)
    b = abs(b)
    g = gcd(a, b)
    a = a // g
    b = b // g
    A += [a]
    B += [b]
    F += [flg]
    if a == 0:
        cnt1 += 1
    elif b == 0:
        cnt2 += 1
    else:
        D[(flg, a, b)] += 1

visited = defaultdict(int)
for j in range(n):
    fi, ai, bi = F[j], A[j], B[j]
    if ai == 0 or bi == 0:
        continue
    if visited[(fi, ai, bi)]:
        continue
    visited[(fi, ai, bi)] = 1
    visited[(fi ^ 1, bi, ai)] = 1
    ans = ans * (pow2[D[(fi, ai, bi)]] + pow2[D[(fi ^ 1, bi, ai)]] - 1) % mod

print(ans * (pow2[cnt1] + pow2[cnt2] - 1) % mod - 1)

Submission status: Runtime Error

Solution code:
import math
import itertools

n = int(input())

vectors = dict()
for i in range(n):
    a, b = map(int, input().split())
    gcd = math.gcd(a, b)

    key = (0, 0)
    if a * b < 0:
        key = (abs(b) // gcd, abs(a) // gcd)
        if key not in vectors:
            vectors[key] = (0, 1)
        else:
            vectors[key] = (vectors[key][0], vectors[key][1]+1)
    else:
        key = (abs(a) // gcd, abs(b) // gcd)
        if key not in vectors:
            vectors[key] = (1, 0)
        else:
            vectors[key] = (vectors[key][0]+1, vectors[key][1])


mod = 1000000007
# total = (pow(2, len(vectors)) - 1) % mod

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

total = 1
for vec in vectors.values():

    total *= (1 + (2**(vec[0])-1 if vec[0] > 0 else 0)
              + (2**(vec[1])-1 if vec[1] > 0 else 0)) % mod

print(total- 1)

Submission status: Runtime Error

Solution code:
import collections
import fractions

n = int(input())
m = 0
mod = 10 ** 6 + 7
c = []
d = []
frac = {}

for _ in range(n):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        n -= 1
        m += 1
    try:
        if b == 0: frac[float('inf')] += 1
        else: frac[fractions.Fraction(a, b)] += 1
    except KeyError:
        if b == 0: frac[float('inf')] = 1
        else: frac[fractions.Fraction(a, b)] = 1

for key, value in frac.items():
    if key > 0: continue
    try:
        if key == float('inf'):
            d.append(frac[fractions.Fraction(0)])
        else:
            d.append(frac[-1 / key])
        c.append(value)
    except KeyError:
        continue

ans = pow(2, n - sum(c) - sum(d), mod)
for i, j in zip(c, d):
    tmp = (pow(2, i, mod) + pow(2, j, mod) - 1)
    ans = (ans * (pow(2, i, mod) + pow(2, j, mod) - 1)) % mod
ans -= 1 + m

print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter,defaultdict
import sys
input = sys.stdin.readline

n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
mod = 1000000007

zero = sum([1 for a,b in ab if (a == 0 and b== 0)])
adivb = [float('inf') if (b == 0 and a != 0) else a / b for a, b in ab]
bdiva = [float('inf') if (a == 0 and b != 0) else -b / a for a, b in ab]

adb, bda = Counter(adivb), Counter(bdiva)
cntadb, cnt = defaultdict(int), 0
for i in adb:
    if (i in bda) and (i >= 0):
        cntadb[i] += 2 ** bda[i] + 2 ** adb[i] - 1
        cnt += bda[i] + adb[i]
ans = 1
for i in cntadb:
    ans *= cntadb[i]
print((ans * 2 ** (n - cnt - zero) + zero - 1) % mod)

Submission status: Runtime Error

Solution code:
import sys
from collections import defaultdict as dd
from math import gcd
input = sys.stdin.readline
N = int(input())
mod = 10 ** 9 + 7
d = dd(int)
a = [tuple(map(int, input().split())) for _ in range(N)]
z = 0
for x, y in a:
  g = gcd(abs(x), abs(y))
  x //= g
  y //= g
  if y < 0:
    x, y = -x, -y
  elif y == 0:
    x = 1
    y = 0
  if (x, y) == (0, 0):
    N -= 1
    z += 1
    continue
  d[(x, y)] += 1
res = 1
u = 0
itr = list(d.keys())
#print(itr, d)
for x, y in itr:
  t = 0
  if (x, y) == (0, 1):
    t = d[(1, 0)]
  elif (x, y) == (1, 0):
    t = d[(0, 1)]
  else:
    t = d[(y * pow(-1, int(x < 0) + 1), abs(x))]
  if t == 0: u += d[(x, y)]
for x, y in itr:
  t = 0
  if (x, y) == (0, 1):
    t = d[(1, 0)]
  elif (x, y) == (1, 0):
    t = d[(0, 1)]
  else:
    t = d[(y * pow(-1, int(x < 0) + 1), abs(x))]
  #print(t, d, (x, y))
  if t:
    v = 0
    v += pow(2, d[(x, y)], mod) - 1
    v %= mod
    v += pow(2, t, mod) - 1
    v %= mod
    v += 1
    v %= mod
    res *= v
    res %= mod
    #print(res, v)
  d[(x, y)] = 0
#print(itr, u, res, z)
print(res * pow(2, u, mod) - 1 + z % mod)

Submission status: Runtime Error

Solution code:
import math


def main():

    mod = 1000000007
    N = int(input())

    A = [0]
    B = [0]

    for n in range(N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)

    calc = dict()

    for i in range(1, N + 1):
        r = math.gcd(A[i], B[i])
        m = 1
        if A[i] * B[i] < 0:
            m = -1

        k1 = (m * abs(A[i] // r), abs(B[i] // r))
        k2 = (-m * abs(B[i] // r), abs(A[i] // r))
        if calc.get(k1):
            calc[k1][0] += 1
        elif not calc.get(k2):
            calc[k1] = [1, 0]

    for i in range(1, N + 1):
        r = math.gcd(A[i], B[i])
        m = 1
        if A[i] * B[i] < 0:
            m = -1

        k2 = (-m * abs(B[i] // r), abs(A[i] // r))
        if calc.get(k2):
            calc[k2][1] += 1

    count = 0
    for k, v in calc.items():
        if not v[0] * v[1] == 0:
            count += v[0] + v[1]

    ans = pow(2, N - count, mod)
    for k, v in calc.items():
        if not v[0] * v[1] == 0:
            comb = (pow(2, v[0]) + pow(2, v[1]) - 1)
            ans = (ans * comb) % mod

    for k, v in calc.items():
        print("{} {}".format(k, v))
    print(ans - 1)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9
    N=I()
    from math import gcd
    d={}
    for i in range(N):
        a,b=MI()
        if a*b!=0:
            g=gcd(abs(a),abs(b))
            a=a//g
            b=b//g
        elif (a,b)!=(0,0):
            assert 0
            if a==0:
                b=1
            else:
                a=1
            
        if (a,b) in d:
            d[(a,b)]+=1
        else:
            d[(a,b)]=1
        
    ans=1
    L=[]
    for k in d.keys():
        L.append((k,d[k]))

    temp0=0
    for i in range(len(L)):
        k=L[i][0]
        v=d[k]
        d[k]=0
        temp=pow(2,v)
        a,b=k
        if a*b!=0:
            if (-b,a) in d:
                v2=d[(-b,a)]
                if v2!=0:
                    temp+=pow(2,v2)-1
                    d[(-b,a)]=0
            if (b,-a) in d:
                v2=d[(b,-a)]
                if v2!=0:
                    temp+=pow(2,v2)-1
                    d[(b,-a)]=0
        elif (a,b)==(1,0) or (a,b)==(0,1):
            if (b,a) in d:
                v2=d[(b,a)]
                if v2!=0:
                    temp+=pow(2,v2)-1
                    d[(b,a)]=0
        else:
            temp0=v
            temp=1
        ans=(ans*temp)%mod
        
        


    ans=(ans-1+temp0)%mod
    print(ans)
        
        
            
            
    #せんぶ０の組みをひく
        
    

main()

Submission status: Runtime Error

Solution code:
import sys
from collections import defaultdict
dic1 = defaultdict(int)
dic2 = defaultdict(int)
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
mod = 10**9+7
def pow(n,p,mod=10**9+7): #繰り返し二乗法(nのp乗)
    res = 1
    while p > 0:
        if p % 2 == 0:
            n = n ** 2 % mod
            p //= 2
        else:
            res = res * n % mod
            p -= 1
    return res % mod
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
def lcm(a,b):
    return (a//gcd(a,b)*b)
def to_standard_form(a, b):
    if a == 0:
        return (0, 1)
    g = gcd(a, b)
    a //= g
    b //= g
    if a < 0:
        return (-a, -b)
    return (a, b)
n = int(readline())
zero = 0
for i in range(n):
    a,b= map(int,readline().split())
    if a == b == 0:
        zero += 1
        continue
    plamai = 1 if a*b > 0 else 0
    a,b = to_standard_form(a,b)
    if b <= 0:
        dic2[(a,b)] += 1
    else:
        dic1[(b,-a)] += 1
        dic2[(b,-a)] += 0

ans = zero
k = 1
for key,cnt in dic2.items():
    cnt2 = dic1[key]
    k = pow(2,cnt)+pow(2,cnt2)
    k = k*(x-1)%mod
print((ans+k-1)%mod)

Submission status: Runtime Error

Solution code:
import collections

def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)

mod=10**9+7
n=int(input())
dic=collections.defaultdict(0)
cnt=0
for _ in range(n):
  a,b=map(int,input().split())
  if a!=0 and b!=0:
    g=gcd(abs(a),abs(b))
    if (a>0 and b>0) or (a<0 and b<0):
      dic[(abs(a)//g,abs(b)//g)]+=1
    elif (a<0 and b>0) or (a>0 and b<0):
      dic[(-abs(a)//g,abs(b)//g)]+=1
  else:
    if a==0 and b==0:
      cnt+=1
    elif a==0:
      dic[(1,0)]+=1
    elif b==0:
      dic[(0,1)]+=1
ans=1
s=set()
for a,b in dic.keys():
  if (a,b) in s:
    continue
  s.add((a,b))
  if a!=0 and b!=0:
    if a>0:
      if (-b,a) in dic:
        s.add((-b,a))
        cnt1=dic[(a,b)]
        cnt2=dic[(-b,a)]
        ans*=(pow(2,cnt1,mod)+pow(2,cnt2,mod)-1)%mod
        ans%=mod
      else:
        ans*=pow(2,dic[(a,b)])
        ans%=mod
    elif a<0:
      if (b,-a) in dic:
        s.add((b,-a))
        cnt1=dic[(a,b)]
        cnt2=dic[(b,-a)]
        ans*=(pow(2,cnt1,mod)+pow(2,cnt2,mod)-1)%mod
        ans%=mod
      else:
        ans*=pow(2,dic[(a,b)],mod)
        ans%=mod
  else:
    if (b,a) in dic:
      s.add((b,a))
      cnt1=dic[(a,b)]
      cnt2=dic[(b,a)]
      ans*=(pow(2,cnt1,mod)+pow(2,cnt2,mod)-1)%mod
      ans%=mod
    else:
      ans*=pow(2,dic[(a,b)],mod)
      ans%=mod
print((ans+cnt-1)%mod)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
import sys
from fractions import Fraction

count = defaultdict(int)
N = int(sys.stdin.readline())

edges = defaultdict(list)
for i in range(N):
    A, B = [int(x) for x in sys.stdin.readline().split()]
    if B == 0:
        angle = "I"
    else:
        angle = Fraction(A, B)
    count[angle] += 1

ZERO = Fraction(0, 1)
pairs = {}
solos = []
for k1 in count:
    if k1 in pairs:
        continue
    if k1 == "I":
        if ZERO in count:
            pairs[ZERO] = k1
        continue

    for k2 in count:
        if k2 == ZERO:
            continue
        if k1 * k2 == -1:
            pairs[k2] = k1
            break
    else:
        solos.append(k1)
# print(pairs, solos)


def power(n):
    1000000007


result = 1
for p in pairs:
    # print("pair", p, count[p], pairs[p], count[pairs[p]])
    n = count[p]
    m = count[pairs[p]]
    result *= (2 ** n - 1) + (2 ** m - 1) + 1
for k in solos:
    # print("solo", k, count[k])
    result *= 2 ** count[k]

print(result - 1)

Submission status: Runtime Error

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, cos, radians, pi, sin, gcd
from operator import mul
from functools import reduce
from operator import mul


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]

mod = 1000000007

n = I()
D = defaultdict(int)
A = []
B = []
F = []
pow2 = [1] * (n + 1)
for i in range(1, n + 1):
    pow2[i] = pow2[i - 1] * 2 % mod

ans = 1
for i in range(n):
    a, b = LI()
    flg = 0
    if a * b < 0:
        flg = 1
    a = abs(a)
    b = abs(b)
    g = gcd(a, b)
    a = a // g
    b = b // g
    A += [a]
    B += [b]
    F += [flg]
    if a == 0 or b == 0:
        D[(0, a, b)] += 1
    else:
        D[(flg, a, b)] += 1

visited = defaultdict(int)
for j in range(n):
    fi, ai, bi = F[j], A[j], B[j]
    if ai == 0 or bi == 0:
        flg = ai = bi = 0
    if visited[(fi, ai, bi)]:
        continue
    visited[(fi, ai, bi)] = 1
    visited[(fi ^ 1, bi, ai)] = 1
    ans = ans * (pow2[D[(fi, ai, bi)]] + pow2[D[(fi ^ 1, bi, ai)]] - 1) % mod

print(ans - 1)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
import sys
from fractions import Fraction

count = defaultdict(int)
if 1:
    N = int(sys.stdin.readline())

    edges = defaultdict(list)
    for i in range(N):
        A, B = [int(x) for x in sys.stdin.readline().split()]
        if B == 0:
            angle = "I"
        else:
            angle = Fraction(A, B)
        count[angle] += 1

pairs = {}
solos = []
for k1 in count:
    if k1 in pairs:
        continue
    for k2 in count:
        if k1 * k2 == -1:
            pairs[k2] = k1
            break
    else:
        solos.append(k1)
print(pairs, solos)


def power(n):
    1000000007


result = 1
for p in pairs:
    print("pair", p, count[p], pairs[p], count[pairs[p]])
    n = count[p]
    m = count[pairs[p]]
    result *= (2 ** n - 1) + (2 ** m - 1) + 1
for k in solos:
    print("solo", k, count[k])
    result *= 2 ** count[k]

print(result - 1)

Submission status: Runtime Error

Solution code:
import collections
import fractions

n = int(input())
mod = 10 ** 6 + 7
c = []
d = []

frac = {}

for _ in range(n):
    a, b = map(int, input().split())
    try:
        if b == 0: frac[float('inf')] += 1
        else: frac[fractions.Fraction(a, b)] += 1
    except KeyError:
        if b == 0: frac[float('inf')] = 1
        else: frac[fractions.Fraction(a, b)] = 1

for key, value in frac.items():
    if -1 <= key < 1: continue
    try:
        if key == 0:
            d.append(frac[float('inf')])
        elif key == float('inf'):
            d.append(fractions.Fraction())
        else:
            d.append(frac[-1 / key])
        c.append(value)
    except KeyError:
        continue

ans = pow(2, n - sum(c) - sum(d), mod)
for i, j in zip(c, d):
    tmp = (pow(2, i, mod) + pow(2, j, mod) - 1)
    ans = (ans * (pow(2, i, mod) + pow(2, j, mod) - 1)) % mod
ans -= 1

print(ans)

Submission status: Runtime Error

Solution code:
import bisect
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
mod = 1000000007
x = []
y = []
ex = [0,0]
ex2 = 0
for i in range(n):
    if (a[i][0]==0 and a[i][1]==0):
        ex2 += 1
    elif (a[i][0]==0):
        ex[0] +=1
    elif (a[i][1]==0):
        ex[1] += 1
    elif (a[i][0]*a[i][1]>0):
        x.append(a[i][1]/a[i][0])
    else:
        y.append(-a[i][0]/a[i][1])
     
x.sort()
y.sort()
#print(x,y)
xl = 0
yl = 0
xu = []
yu = []
xn = 0
yn = 0
while (xl<len(x) and yl<len(y)):
    if (x[xl] > y[yl]):
        yl += 1
    elif (x[xl] < y[yl]):
        xl += 1
    else:
        #print(xl,yl,x,y)
        p = bisect.bisect_right(x,x[xl])
        q = bisect.bisect_right(y,y[yl])
        xn += (p-xl)
        yn += (q-yl)
        xu.append(p-xl)
        yu.append(q-yl)
        xl = p
        yl = q
xn += ex[0]
yn += ex[1]
xu.append(ex[0])
yu.append(ex[1])
#print(xn,yn,xu,yu)
ans = pow(2,n-xn-yn-ex2,mod)
#print(ans)
#if (n-xn-yn>0):
    #t = 1
    #for i in range(1,n-xn-yn+1):
        #t *= i
        #t %= mod
    #ans += t
for i in range(len(xu)):
    ans *= (pow(2,xu[i],mod)+pow(2,yu[i],mod)-1)
    ans %= mod

if (n-xn-yn-ex2==0 and xn==0):
    print(ans+ex2-1)
elif (n-xn-yu-ex2==0 and yn==0):
    print(ans+ex2-1)
elif (n-xn-yn-ex2==0):
    print(ans+ex2)
elif (ex2==0):
    print((ans-1)%mod)
else:
    print((ans-1+ex2)%mod)

Submission status: Runtime Error

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, cos, radians, pi, sin, gcd
from operator import mul
from functools import reduce
from operator import mul


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]

mod = 1000000007

n = I()
D = defaultdict(int)
A = []
B = []
F = []
pow2 = [1] * (n + 1)
for i in range(1, n + 1):
    pow2[i] = pow2[i - 1] * 2 % mod

ans = 1
for i in range(n):
    a, b = LI()
    flg = 0
    if a * b < 0:
        flg = 1
    a = abs(a)
    b = abs(b)
    g = gcd(a, b)
    a = a // g
    b = b // g
    A += [a]
    B += [b]
    F += [flg]
    D[(flg, a, b)] += 1

visited = defaultdict(int)
for j in range(n):
    fi, ai, bi = F[j], A[j], B[j]
    if visited[(fi, ai, bi)]:
        continue
    visited[(fi, ai, bi)] = 1
    visited[(fi ^ 1, bi, ai)] = 1
    ans = ans * (pow2[D[(fi, ai, bi)]] + pow2[D[(fi ^ 1, bi, ai)]] - 1) % mod

print(ans - 1)

Submission status: Runtime Error

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations, combinations_with_replacement
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    n = inp()
    dic = defaultdict(int)
    dic1 = defaultdict(int)
    for _ in range(n):
        a,b = inpm()
        if a != 0 and b == 0:
            a = 1
        elif a == 0 and b != 0:
            b = 1
        else:
            if not (a==0 and b==0):
                m = gcd(a,b)
                a //= m
                b //= m
        if a < 0 and b < 0:
            a = -a
            b = -b
        if a < 0 and b > 0:
            a = -a
            b = -b
        index = ' '.join([str(a),str(b)])
        dic[index] += 1
        dic1[index] += 1
    ans = 1
    dic2 = defaultdict(int)
    for e in dic:
        a,b = map(int,e.split())
        if a == 0 and b == 0:
            continue
        flag = 0
        if a == 0 and b == 1:
            rev = ' '.join([str(1),str(0)])
        elif a == 1 and b == 0:
            rev = ' '.join([str(0),str(1)])
        elif a > 0 and b > 0:
            rev = ' '.join([str(b),str(-a)])
        else:
            rev = ' '.join([str(-b),str(a)])
        if dic1[rev] > 0 and dic2[rev] == 0:
            dic2[rev] = 1
            dic2[e] = 1
            flag = 1
        if flag:
            continue
        n1 = pow(2,dic[e],mod)
        n2 = pow(2,dic1[rev],mod)
        if n1 == 0 and n2 != 0:
            ans *= n2
        elif n2 == 0 and n1 != 0:
            ans *= n1
        else n1 != 0 and n2 != 0:
            ans *= (n1+n2-1)
        ans %= mod
    print(ans-1+dic['0 0'])
    
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, cos, radians, pi, sin, gcd
from operator import mul
from functools import reduce
from operator import mul


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]

mod = 1000000007

n = I()
D = defaultdict(int)
A = []
B = []
F = []
ans = 1
for i in range(n):
    a, b = LI()
    flg = 0
    if a * b < 0:
        flg = 1
    a = abs(a)
    b = abs(b)
    g = gcd(a, b)
    a = a // g
    b = b // g
    A += [a]
    B += [b]
    F += [flg]
    D[(flg, a, b)] += 1

visited = defaultdict(int)
for j in range(n):
    fi, ai, bi = F[j], A[j], B[j]
    if visited[(fi, ai, bi)]:
        continue
    visited[(fi, ai, bi)] = 1
    visited[(fi ^ 1, bi, ai)] = 1
    ans = ans * (pow(2, D[(fi, ai, bi)], mod) + pow(2, D[(fi ^ 1, bi, ai)], mod) - 1) % mod

print(ans - 1)