Problem p02679 (python)

Fixed submission:
n=int(input())

mod=10**9+7

#初期値が0の辞書
from collections import defaultdict
pp = defaultdict(lambda: 0) 
pm = defaultdict(lambda: 0) 

def seiki(x,y):
    tmp=gcd(x,y)
    return (x//tmp,y//tmp)

from math import gcd
zero=0
for _ in range(n):
    a,b=map(int,input().split())

    if a==0 and b==0:
        zero+=1
    elif a*b>0:
        tmp=seiki(abs(a),abs(b))
        pp[tmp]+=1
    elif a==0:
        pp[(1,0)]+=1
    elif b==0:
        pm[(1,0)]+=1
        pp[(1,0)]+=0
    else:
        tmp=seiki(abs(b),abs(a))
        pm[tmp]+=1
        pp[tmp]+=0
#print(pm)
#print(pp)
result=1
for key in pp.keys():
    pp_v=pp[key]
    pm_v=pm[key]
    result*=(pow(2,pm_v,mod)+pow(2,pp_v,mod)-1)
    result%=mod

print((result-1+zero)%mod)

Buggy submission (verdict: Runtime Error):
from flactions import gcd 
from collections import defaultdict

def to_irreducible(a, b):
    if a == 0:
        return [0, 1]
    GCD = gcd(a, b)
    return [a//GCD, b//GCD]

MOD = 10**9 + 7
N = int(input())
daiichi_dict = defaultdict(int)
daini_dict = defaultdict(int)
zero_cases = 0

for i in range(N):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        zero_cases += 1
    elif a * b >=0 and b != 0:
        a, b = to_irreducible(abs(a), abs(b))
        daiichi_dict[(a,b)] += 1
    else:
        a, b = to_irreducible(abs(b), abs(a))
        daini_dict[(a,b)] += 1
        daiichi_dict[(a,b)] += 0


ans = 1 
for key, value_daiichi in daiichi_dict.items():
    value_daini = daini_dict[key]
    ans *= (2**value_daiichi + 2**value_daini -1)
    ans %= MOD
print((ans+zero_cases-1) % MOD)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(2147483647)


n=int(input())

mod=10**9+7

#初期値が0の辞書

pp = {} 
pm = {} 

from fractions import gcd
zero=0
for _ in range(n):
    a,b=map(int,input().split())

    if a*b!=0:
        tmp=gcd(a,b)
        a=a//tmp
        b=b//tmp

        if a*b>0:
            if (a,b) in pp:
                pp[(a,b)]+=1
            else:
                pp[(a,b)]=1
        else:
            if (a,b) in pm:
                pm[(a,b)]+=1
            else:
                pm[(a,b)]=1

    elif a==0 and b==0:
        zero+=1
    else:
        if (a,b) in pp:
            pp[(a,b)]+=1
        else:
            pp[(a,b)]=1

            

#print(pp_k,pm_k)
result=1
for key in pp.keys():
    pp_v=pp[key]
    a,b=key[0],key[1]
    pm_v=pm[(-1*b,a)]+pm[(b,-1*a)]
    if pm_v>0:
        result=result*((2**pp_v-1)+(2**pm_v-1)+1)
    else:
        result=result*(2**pp_v)

for key in pm.keys():
    pm_v=pm[key]
    a,b=key[0],key[1]
    pp_v=pp[(-1*b,a)]+pp[(b,-1*a)]

    if pp_v==0:
        result=result*(2**pm_v)

print(result-1+zero)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(2147483647)


n=int(input())

mod=10**9+7

#初期値が0の辞書
from collections import defaultdict
pp = defaultdict(lambda: 0) 
pm = defaultdict(lambda: 0) 

from fractions import gcd

for _ in range(n):
    a,b=map(int,input().split())
    tmp=gcd(a,b)
    a=a//tmp
    b=b//tmp

    if a*b>0:
        pp[(a,b)]+=1
    else:
        pm[(a,b)]+=1
            
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = mod #割る数
N = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

#print(pp_k,pm_k)
result=1
for key in pp.keys():
    pp_v=pp[key]
    a,b=key[0],key[1]
    pm_v=pm[(-1*b,a)]+pm[(b,-1*a)]
    result=result*((2**pp_v-1)+(2**pm_v-1)+1)

for key in pm.keys():
    pm_v=pm[key]
    a,b=key[0],key[1]
    pp_v=pp[(-1*b,a)]+pp[(b,-1*a)]

    if pp_v==0:
        result=result*(2**pm_v)

print(result-1)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(2147483647)


n=int(input())

mod=10**9+7

pp={}
pp_k=set([])

pm={}
pm_k=set([])

from fractions import gcd


for _ in range(n):
    a,b=map(int,input().split())
    tmp=gcd(a,b)
    a=a//tmp
    b=b//tmp

    if a*b>0:
        if (a,b) in pp_k:
            pp[(a,b)]+=1
        else:
            pp[(a,b)]=1
            pp_k.add((a,b))
    else:
        if (a,b) in pm_k:
            pm[(a,b)]+=1
        else:
            pm[(a,b)]=1
            pm_k.add((a,b))

result=pow(2,n,mod)-1

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = mod #割る数
N = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

#print(pp_k,pm_k)
for item in pp_k:

    tmp=0

    a,b=item[0],item[1]
    cnt_pp=pp[item]
    aa=-1*a
    bb=b
    cnt_pm=0
    hoge=(bb,aa)
    #print(hoge)
    if hoge in pm_k:
        #print("Yes")
        cnt_pm+=pm[hoge]
    aa=a
    bb=-1*b
    hoge=(bb,aa)
    if hoge in pm_k:
        cnt_pm+=pm[hoge]
    #print(item,cnt_pm)
    if cnt_pm>0:
        tmp+=pow(2,max(0,n-cnt_pm-cnt_pp),mod)*(pow(2,cnt_pp,mod)-1)*(pow(2,cnt_pp,mod)-1)
        #print(pow(2,max(0,n-cnt_pm-cnt_pp),mod),(pow(2,cnt_pp,mod)-1),(pow(2,cnt_pp,mod)-1))
        result-=tmp

print(result%mod)

Buggy submission (verdict: Runtime Error):
n=int(input())

mod=10**9+7

pp={}
pp_k=set([])

pm={}
pm_k=set([])

from fractions import gcd


for _ in range(n):
    a,b=map(int,input().split())
    tmp=gcd(a,b)
    a=a//tmp
    b=b//tmp

    if a*b>0:
        if (a,b) in pp_k:
            pp[(a,b)]+=1
        else:
            pp[(a,b)]=1
            pp_k.add((a,b))
    else:
        if (a,b) in pm_k:
            pm[(a,b)]+=1
        else:
            pm[(a,b)]=1
            pm_k.add((a,b))

result=pow(2,n,mod)-1

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = mod #割る数
N = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

#print(pp_k,pm_k)
for item in pp_k:

    tmp=0

    a,b=item[0],item[1]
    cnt_pp=pp[item]
    aa=-1*a
    bb=b
    cnt_pm=0
    hoge=(bb,aa)
    #print(hoge)
    if hoge in pm_k:
        #print("Yes")
        cnt_pm+=pm[hoge]
    aa=a
    bb=-1*b
    hoge=(bb,aa)
    if hoge in pm_k:
        cnt_pm+=pm[hoge]
    #print(item,cnt_pm)
    if cnt_pm>0:
        tmp+=pow(2,max(0,n-cnt_pm-cnt_pp),mod)*(pow(2,cnt_pp,mod)-1)*(pow(2,cnt_pp,mod)-1)
        #print(pow(2,max(0,n-cnt_pm-cnt_pp),mod),(pow(2,cnt_pp,mod)-1),(pow(2,cnt_pp,mod)-1))
        result-=tmp

print(result%mod)