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:
def examA():
    S = {0:"pon",1:"pon",2:"hon",3:"bon",4:"hon",5:"hon",6:"pon",7:"hon",8:"pon",9:"hon"}
    N = SI()
    ans = S[int(N[-1])]
    print(ans)
    return

def examB():
    K = I()
    S = SI()
    N = len(S)
    if N<=K:
        ans = S
    else:
        ans = S[:K]+"..."
    print(ans)
    return

def examC():
    A, B, H, M = LI()
    a = abs(H*30 - M*5.5)
    deg = min(360-a,a)*math.pi/180
    #print(deg)
    ans = (A**2 + B**2 - 2*A*B*math.cos(deg))**(0.5)
    print(ans)
    return

def examD():

    N, M = LI()
    V = [[]for _ in range(N)]
    for _ in range(M):
        a, b = LI()
        a -= 1; b -= 1
        V[a].append(b)
        V[b].append(a)

    ans = [-1]*N

    def bfs(n, e, fordfs):
        # 点の数、スタートの点、有向グラフ
        W = [-1] * n
        # 各点の状態量、最短距離とか,見たかどうかとか
        W[e] = 0
        que = deque()
        que.append(e)
        while que:
            now = que.popleft()
            nowW = W[now]
            for ne in fordfs[now]:
                if W[ne] == -1:
                    W[ne] = now
                    que.append(ne)
        return W
    ans = bfs(N,0,V)
    for a in ans:
        if a==-1:
            print("No")
            return
    print("Yes")
    for v in ans[1:]:
        print(v+1)
    return

def examE():
    def gcd(x, y):
        if y == 0:
            return x
        while (y != 0):
            x, y = y, x % y
        return x
    N = I()
    D = defaultdict(int)
    for i in range(N):
        A = LI()
        if A[0]<0 and A[1]<0:
            A = [-A[0],-A[1]]
        if A[0]<0:
            k = gcd(-A[0],A[1])
            V = [A[0] // k, A[1] // k]
        elif A[1]<0:
            k = gcd(A[0],-A[1])
            V = [A[0] // k, A[1] // k]
        else:
            k = gcd(A[0],A[1])
            V = [A[0]//k,A[1]//k]
        D[(V[0], V[1])] += 1
    ans = 1
    #print(D)
    C = deepcopy(D)
    for (a,b),d in C.items():
        if D[(a,b)]==0:
            continue
        if D[(-b,a)]>0:
            ans *= (pow(2,d,mod)-1 + pow(2,D[(-b,a)])-1 + 1)
            D[(-b,a)] = 0
        elif D[(b,-a)]>0:
            ans *= (pow(2,d,mod)-1 + pow(2,D[(b,-a)])-1 + 1)
            D[(b,-a)] = 0
        else:
            ans *= pow(2,d,mod)
        ans %= mod
        #print(ans,a,b,d)
    ans = (ans+mod-1)%mod
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examE()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Submission status: Runtime Error

Solution code:
import sys
input=sys.stdin.readline
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
from math import gcd
n=N()
mod=10**9+7
az=0
bz=0
zz=0
l=LL(n)
ans=1
import collections
d=collections.defaultdict(int)
for a,b in l:
    if a==0 and b==0:
        zz+=1
    elif a==0:
        az+=1
    elif b==0:
        ab+=1
    elif a<0 and b<0:
        a=-a
        b=-b
        x=gcd(a,b)
        d[(a//x,b//x)]+=1
    elif a<0:
        a=-a
        x=gcd(a,b)
        d[(-a//x,b//x)]+=1
    elif b<0:
        b=-b
        x=gcd(a,b)
        d[(-a//x,b//x)]+=1
    else:
        x=gcd(a,b)
        d[(a//x,b//x)]+=1
pow2=[1]*(n+1)
t=1
for i in range(1,n+1):
    t*=2
    t%=mod
    pow2[i]=t
ans*=(1+(pow2[az]-1)+(pow2[bz]-1))
for a,b in list(d.keys()):
    if a>0 and b>0:
        x=d[(a,b)]
        y=d[(-b,a)]
        ans*=(1+(pow2[x]-1)+(pow2[y]-1))
        ans%=mod
    else:
        if not (b,-a) in d:
            ans*=pow2[d[(a,b)]]
            ans%=mod
print(ans-1)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする


def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)

def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    d=dict()
    m=10**18+1
    for i in range(N):
        A, B = map(int, input().split())
        if B==0:
            d[m]=d.get(m,0)+1
        else:
            t=float(A/B)
            d[t]=d.get(t,0)+1
        

    ks=set(d.keys())
    alis=[]
    tot=1
    for i, k in enumerate(ks):
        if d[k]==-1:
            continue
        if d[k]==m:
            ik=0
        elif d[k]==0.0:    
            ik=m
        else:
            ik=-1.0/k

        if ik in ks:
            d1,d2=d[k],d[ik]
            tot*=(pow(2,d1,mod)-1)+(pow(2,d2,mod)-1)+1
            d[ik]=-1
        else:
            tot*=pow(2,d[k],mod)
    
        

    print(tot-1)




if __name__ == "__main__":
    main()

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()
        dic[a/b] += 1
        dic1[a/b] += 1
    ans = 1
    for e in dic:
        if e < 0:
            if dic1[-1/e] > 0:
                continue
        if e == 0:
            ans *= dic[e]
            ans %= mod
            continue
        n1 = pow(2,dic[e],mod)-1
        n2 = pow(2,dic1[-1/e],mod)-1
        if n1 == 0:
            ans *= (n2+1)
        elif n2 == 0:
            ans *= (n1+1)
        else:
            ans *= (n1+n2+1)
        ans %= mod
    print(ans-1)
    
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
from fractions import Fraction

N = int(input())

vec = [list(map(int,input().split())) for i in range(N)]

from collections import defaultdict

arg = defaultdict(int)
zero = 0
for v in vec:
    if v[0] == 0 and v[1] == 0:
        zero += 1
    elif v[1]==0:
        arg[float("inf")] += 1
        arg[0] += 1
    else:
        arg[Fraction(v[0],v[1])] += 1
        arg[Fraction(-v[1],v[0])] += 0

pair = []

ll = lambda : False

checked_list = defaultdict(ll)
for key in arg:
    if not checked_list[key]:
        if key==0:
            pair.append([arg[0],arg[float("inf")]])
            checked_list[float("inf")] = True
        elif key==float("inf"):
            pair.append([arg[0],arg[float("inf")]])
            checked_list[0] = True

        else:
            #print(key)
            pair.append([arg[key],arg[-1/key]])
            #print(pair)
            checked_list[-1/key] = True

mod = 1000000007

ans = 1

for p1,p2 in pair:
    ans *= pow(2,p1,mod) + pow(2,p2,mod) - 1
    ans %= mod

ans += zero
ans %= mod

print(ans-1)

Submission status: Runtime Error

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

import sys
sys.setrecursionlimit(300000)

MOD = 1000000007  # type: int

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

def solve(N: int, A: "List[int]", B: "List[int]"):
    s = {}
    for i in range(N):
        g = gcd(A[i], B[i])
        a, b = A[i] // g, B[i] // g
        k = (a, b)
        if not k in s:
            s[k] = 0
        s[k] += 1
    count = 0
    checked = set()
    cums = []
    #print(s)
    for (a, b), cnt in s.items():
        if (a, b) in checked:
            continue
        checked.add((a, b))
        tmp = 0
        if (-b, a) in s and (-b, a) not in checked:
            tmp += s[(-b, a)]
            checked.add((-b, a))
        if (b, -a) in s and (b, -a) not in checked:
            tmp += s[(b, -a)]
            checked.add((b, -a))
        if tmp > 0:
            cum = pow(2, cnt, MOD) + pow(2, tmp, MOD) - 1
            cum %= MOD
            cums.append(cum)
            count += cnt + tmp
    ret = pow(2, (N - count), MOD)
    for cum in cums:
        ret *= cum
        ret %= MOD
    ret -= 1
    ret %= MOD
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]"
    B = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, A, B)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def examA():
    S = {0:"pon",1:"pon",2:"hon",3:"bon",4:"hon",5:"hon",6:"pon",7:"hon",8:"pon",9:"hon"}
    N = SI()
    ans = S[int(N[-1])]
    print(ans)
    return

def examB():
    K = I()
    S = SI()
    N = len(S)
    if N<=K:
        ans = S
    else:
        ans = S[:K]+"..."
    print(ans)
    return

def examC():
    A, B, H, M = LI()
    a = abs(H*30 - M*5.5)
    deg = min(360-a,a)*math.pi/180
    #print(deg)
    ans = (A**2 + B**2 - 2*A*B*math.cos(deg))**(0.5)
    print(ans)
    return

def examD():

    N, M = LI()
    V = [[]for _ in range(N)]
    for _ in range(M):
        a, b = LI()
        a -= 1; b -= 1
        V[a].append(b)
        V[b].append(a)

    ans = [-1]*N

    def bfs(n, e, fordfs):
        # 点の数、スタートの点、有向グラフ
        W = [-1] * n
        # 各点の状態量、最短距離とか,見たかどうかとか
        W[e] = 0
        que = deque()
        que.append(e)
        while que:
            now = que.popleft()
            nowW = W[now]
            for ne in fordfs[now]:
                if W[ne] == -1:
                    W[ne] = now
                    que.append(ne)
        return W
    ans = bfs(N,0,V)
    for a in ans:
        if a==-1:
            print("No")
            return
    print("Yes")
    for v in ans[1:]:
        print(v+1)
    return

def examE():
    def gcd(x, y):
        if y == 0:
            return x
        while (y != 0):
            x, y = y, x % y
        return x
    N = I()
    V = [[] for _ in range(N)]
    D = defaultdict(int)
    for i in range(N):
        A = LI()
        if A[0]<0 and A[1]<0:
            A = [-A[0],-A[1]]
        if A[0]<0:
            k = gcd(-A[0],A[1])
            V[i] = [-1,A[0] // k, A[1] // k]
        elif A[1]<0:
            k = gcd(A[0],-A[1])
            V[i] = [0, A[0] // k, A[1] // k]
        else:
            k = gcd(A[0],A[1])
            V[i] = [1,A[0]//k,A[1]//k]
        D[(V[i][1], V[i][2])] += 1
    ans = 1
    #print(D)
    C = deepcopy(D)
    for (a,b),d in C.items():
        if d==0:
            continue
        if D[(-b,a)]>0:
            ans *= (pow(2,d,mod)-1 + pow(2,D[(-b,a)])-1 + 1)
            C[(-b,a)] = 0
        elif D[(b,-a)]>0:
            ans *= (pow(2,d,mod)-1 + pow(2,D[(b,-a)])-1 + 1)
            C[(b,-a)] = 0
        else:
            ans *= pow(2,d,mod)
        #print(ans,a,b,d)
    ans -= 1
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examE()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする


def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)

def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    d=dict()
    m=10**18+1
    for i in range(N):
        A, B = map(int, input().split())
        if B==0:
            d[m]=d.get(m,0)+1
        else:
            t=A/B
            d[t]=d.get(t,0)+1
        

    ks=set(d.keys())
    alis=[]
    tot=1
    for i, k in enumerate(ks):
        if d[k]==-1:
            continue
        ik=-1.0/k
        if ik in ks:
            d1,d2=d[k],d[ik]
            tot*=(pow(2,d1,mod)-1)+(pow(2,d2,mod)-1)+1
            d[ik]=-1
        else:
            tot*=pow(2,d[k],mod)
    
        

    print(tot-1)




if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/python3
from math import gcd
import sys
input = lambda: sys.stdin.readline().strip()

n = int(input())
indet = 0
d = {}
for i in range(n):
    a, b = [int(x) for x in input().split()]
    if b < 0:
        a *= -1
        b *= -1
    if a == 0 and b == 0:
        indet += 1
    elif b == 0:
        p = (0, 0)
    else:
        g = gcd(a, b)
        p = (a // g, b // g)
    d[p] = d.get(p, 0) + 1

sizes = []
ignore = set()
for p, size in d.items():
    if p not in ignore:
        a, b = -p[1], p[0]
        if b < 0:
            a *= -1
            b *= -1
        if (a, b) in d:
            ignore.add((a, b))
            sizes.append((size, d[(a, b)]))
        else:
            sizes.append((size, 0))
M = 10**9 + 7
ans = 1
for n1, n2 in sizes:
    ans *= (pow(2, n1, M) + pow(2, n2, M) - 1)
    ans %= M
print((indet + ans - 1) % M)

Submission status: Runtime Error

Solution code:
from fractions import Fraction

N = int(input())

vec = [list(map(int,input().split())) for i in range(N)]

from collections import defaultdict

arg = defaultdict(int)
zero = 0
for v in vec:
    if v[0] == 0 and v[1] == 0:
        zero += 1
    elif v[1]==0:
        arg[float("inf")] += 1
        arg[0] += 1
    else:
        arg[Fraction(v[0],v[1])] += 1
        arg[-1/Fraction(v[0],v[1])] += 0

pair = []

ll = lambda : False

checked_list = defaultdict(ll)

for key in arg:
    if not checked_list[key]:
        if key==0:
            pair.append([arg[0],arg[float("inf")]])
            checked_list[float("inf")] = True
        else:
            #print(key)
            pair.append([arg[key],arg[-1/key]])
            #print(pair)
            checked_list[-1/key] = True

mod = 1000000007

ans = 1

for p1,p2 in pair:
    ans *= pow(2,p1,mod) + pow(2,p2,mod) - 1
    ans %= mod

ans += zero
ans %= mod

print(ans-1)

Submission status: Runtime Error

Solution code:
mod = 1000000007
from collections import defaultdict
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

N = int(input())
AB = [list(map(int,input().split())) for _ in range(N)]
d1 = defaultdict(lambda:0)
d2 = defaultdict(lambda:0)
for i in range(N):
    a,b = AB[i]
    a_ = abs(a)
    b_ = abs(b)
    d = gcd(a,b)
    a //= d
    b //= d
    if a < 0:
        a *= -1
        b *= -1
    if b>=0:
        d1[(a,b)] += 1
    else:
        d2[(a,b)] += 1
        d1[(-b,a)] += 0

ans = 1
for a,b in d1:
    x = d1[(a,b)]
    y = d2[(b,-a)]
    ans *= pow(2,x,mod)+pow(2,y,mod)-1
    ans %= mod
ans -= 1
print(ans)

Submission status: Runtime Error

Solution code:
mod = 1000000007
from collections import defaultdict

N = int(input())
AB = [list(map(int,input().split())) for _ in range(N)]
d1 = defaultdict(lambda:0)
d2 = defaultdict(lambda:0)
for i in range(N):
    a,b = AB[i]
    a_ = abs(a)
    b_ = abs(b)
    d = gcd(a,b)
    a //= d
    b //= d
    if a < 0:
        a *= -1
        b *= -1
    if b>=0:
        d1[(a,b)] += 1
    else:
        d2[(a,b)] += 1
        d1[(-b,a)] += 0

ans = 1
for a,b in d1:
    x = d1[(a,b)]
    y = d2[(b,-a)]
    ans *= pow(2,x,mod)+pow(2,y,mod)-1
    ans %= mod
ans -= 1
print(ans)

Submission status: Runtime Error

Solution code:
def main():
    N, = map(int, input().split())
    A = []
    B = []
    for _ in range(N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)

    MOD = 1000000007

    B_by_A = [1.0 * B[i] / A[i] for i in range(N)]
    A_by_B = [1.0 * A[i] / B[i] for i in range(N)]

    print(A_by_B)
    print(B_by_A)
    

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
mod = 10**9+7
n = int(input())
fish = {}
rish = {}
att = 0
for _ in range(n):
  a,b = map(int,input().split())
  if a*b != 0:
    try:
      fish[a/b] += 1
    except:
      fish[a/b] = 1
    rish[-b/a] = 1
  elif a == 0 and b == 0:
    att += 1
  elif a == 0:
    try:
      fish[0] = 1
    except:
      fish[0] = 1
    rish[10**20] = 1
  else:
    try:
      fish[10**20] = 1
    except:
      fish[10**20] = 1
    rish[0] = 1
#print(fish)
#print(rish)
double = [1]
for _ in range(3*10**5):
  double.append(double[-1]*2%mod)
ans = 1
for x in fish:
  if not fish[x]:
    #print('#',x)
    continue
  if x in rish:
    ans *= double[fish[x]] + double[fish[-1/x]] - 1
    ans %= mod
    fish[x] = 0
    fish[-1/x] = 0
  else:
    ans *= double[fish[x]]
    ans %= mod
  #print(ans)
ans = ans-1+att
ans %= mod
print(ans)

Submission status: Runtime Error

Solution code:
mod = 1000000007
eps = 10**-9


def main():
    import sys
    from math import gcd
    input = sys.stdin.buffer.readline

    N = int(input())
    cnt = {}
    for _ in range(N):
        a, b = map(int, input().split())
        if a < 0:
            a = -a
            b = -b
        g = gcd(abs(a), abs(b))
        x = (a // g, b // g)
        if x in cnt:
            cnt[x] += 1
        else:
            cnt[x] = 1

    ans = 1
    num = 0
    for x in cnt:
        if cnt[x] == 0:
            continue
        a, b = x
        if b > 0:
            y = (b, -a)
        else:
            y = (-b, a)
        if y in cnt:
            nx = cnt[x]
            ny = cnt[y]
            cnt[y] = 0
            ans = (ans * ((pow(2, nx, mod) - 1) + (pow(2, ny, mod) - 1) + 1)%mod)%mod
        else:
            num += cnt[x]
    ans = (ans * pow(2, num, mod))%mod
    ans = (ans - 1)%mod
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

def gcd(x, y):
    x = abs(x)
    y = abs(y)

    if x < y:
        x, y = y, x

    while y:
        x, y = y, x%y
        
    return x

N = int(input())
seen = dict()
for _ in range(N):
    a, b = map(int, input().split())
    if a < 0:
        a, b = -a,-b
    if b < 0:
        a, b = -b, a
        flip = 1
    else:
        flip = 0
    g = gcd(a,b)
    a//=g
    b//=g
    if (a,b) not in seen:
        seen[(a,b)] = [0,0]
    
    seen[(a,b)][flip] += 1

MOD = 10 ** 9 + 7
    
out = 1
for v in seen:
    a, b = seen[v]
    out *= (pow(2,a,MOD) + pow(2,b,MOD) - 1)
    out %= MOD
out -= 1
out %= MOD
print(out)

Submission status: Runtime Error

Solution code:
I cant solve the problem.