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 sys,bisect,string,math,time,functools,random,fractions
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1):
#h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(n,base=2):
    rt=[]
    for tb in range(base**n):s=[tb//(base**bt)%base for bt in range(n)];rt+=[s]
    return rt
def gcd(x,y):
    if y==0:return x
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)
 
YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
FourNb=[(-1,0),(1,0),(0,1),(0,-1)];EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('WENS',FourNb));cursol=dict(zip('LRUD',FourNb))
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()
 
class Tree:
    def __init__(self,inp_size=None,ls=None,init=True,index=0):
        self.LCA_init_stat=False
        self.ETtable=[]
        if init:
            if ls==None:
                self.stdin(inp_size,index=index)
            else:
                self.size=len(ls)+1
                self.edges,_=GI(self.size,self.size-1,ls,index=index)
        return
 
    def stdin(self,inp_size=None,index=1):
        if inp_size==None:
            self.size=int(input())
        else:
            self.size=inp_size
        self.edges,_=GI(self.size,self.size-1,index=index)
        return
    
    def listin(self,ls,index=0):
        self.size=len(ls)+1
        self.edges,_=GI(self.size,self.size-1,ls,index=index)
        return
 
    def __str__(self):
        return  str(self.edges)
 
    def dfs(self,x,func=lambda prv,nx,dist:prv+dist,root_v=0):
        q=deque()
        q.append(x)
        v=[-1]*self.size
        v[x]=root_v
        while q:
            c=q.pop()
            for nb,d in self.edges[c]:
                if v[nb]==-1:
                    q.append(nb)
                    v[nb]=func(v[c],nb,d)
        return v
 
    def EulerTour(self,x):
        q=deque()
        q.append(x)
        self.depth=[None]*self.size
        self.depth[x]=0
        self.ETtable=[]
        self.ETdepth=[]
        self.ETin=[-1]*self.size
        self.ETout=[-1]*self.size
        cnt=0
        while q:
            c=q.pop()
            if c<0:
                ce=~c
            else:
                ce=c
                for nb,d in self.edges[ce]:
                    if self.depth[nb]==None:
                        q.append(~ce)
                        q.append(nb)
                        self.depth[nb]=self.depth[ce]+1
            self.ETtable.append(ce)
            self.ETdepth.append(self.depth[ce])
            if self.ETin[ce]==-1:
                self.ETin[ce]=cnt
            else:
                self.ETout[ce]=cnt
            cnt+=1
        return
    
    def LCA_init(self,root):
        self.EulerTour(root)
        self.st=SparseTable(self.ETdepth,init_func=min,init_idl=inf)
        self.LCA_init_stat=True
        return
    
    def LCA(self,root,x,y):
        if self.LCA_init_stat==False:
            self.LCA_init(root)
        xin,xout=self.ETin[x],self.ETout[x]
        yin,yout=self.ETin[y],self.ETout[y]
        a=min(xin,yin)
        b=max(xout,yout,xin,yin)
        id_of_min_dep_in_et=self.st.query_id(a,b+1)
        return self.ETtable[id_of_min_dep_in_et]
 
class SparseTable: # O(N log N) for init, O(1) for query(l,r)
    def __init__(self,ls,init_func=min,init_idl=float('inf')):
        self.func=init_func
        self.idl=init_idl
        self.size=len(ls)
        self.N0=self.size.bit_length()
        self.table=[ls[:]]
        self.index=[list(range(self.size))]
        self.lg=[0]*(self.size+1)
        
        for i in range(2,self.size+1):
            self.lg[i]=self.lg[i>>1]+1
 
        for i in range(self.N0):
            tmp=[self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) for j in range(self.size)]
            tmp_id=[self.index[i][j] if self.table[i][j]==self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) else self.index[i][min(j+(1<<i),self.size-1)] for j in range(self.size)]
            self.table+=[tmp]
            self.index+=[tmp_id]
    
    # return func of [l,r)
    def query(self,l,r):
        if r>self.size:r=self.size
        #N=(r-l).bit_length()-1
        N=self.lg[r-l]
        return self.func(self.table[N][l],self.table[N][max(0,r-(1<<N))])
    
    # return index of which val[i] = func of v among [l,r)
    def query_id(self,l,r):
        if r>self.size:r=self.size
        #N=(r-l).bit_length()-1
        N=self.lg[r-l]
        a,b=self.index[N][l],self.index[N][max(0,r-(1<<N))]
        if self.table[0][a]==self.func(self.table[N][l],self.table[N][max(0,r-(1<<N))]):
            b=a
        return b
    
    def __str__(self):
        return str(self.table[0])
 
    def print(self):
        for i in self.table:
            print(*i)
 
class Comb:
    def __init__(self,n,mo=10**9+7):
        self.fac=[0]*(n+1)
        self.inv=[1]*(n+1)
        self.fac[0]=1
        self.fact(n)
        for i in range(1,n+1):
            self.fac[i]=i*self.fac[i-1]%mo
            self.inv[n]*=i
            self.inv[n]%=mo
        self.inv[n]=pow(self.inv[n],mo-2,mo)
        for i in range(1,n):
            self.inv[n-i]=self.inv[n-i+1]*(n-i+1)%mo
        return
    
    def fact(self,n):
        return self.fac[n]
        
    def invf(self,n):
        return self.inv[n]
 
    def comb(self,x,y):
        if y<0 or y>x:
            return 0
        return self.fac[x]*self.inv[x-y]*self.inv[y]%mo

def dijkstra(edge,st):
    # edge=[[(v_to,dist_to_v),...],[],...]
    # initialize: def: d=dist(st,i), prev=[previous vertex in minimum path], q[]
    n=len(edge)
    d=[(0 if st==i else inf) for i in range(n)]
    prev=[0]*n
    q=[(j,i) for i,j in enumerate(d)]
    heapify(q)
    v=[False]*n
    # calc
    while q:
        dist,cur=heappop(q)
        if v[cur]:
            continue
        v[cur]=True
        for dst,dist in edge[cur]:
            alt=d[cur]+dist
            if alt<d[dst]:
                d[dst]=alt
                prev[dst]=cur
                heappush(q,(alt,dst))
    return d,prev


show_flg=False
show_flg=True
ans=0

n=I()
ans=pow(2,n,mo)-1

dp=[[0]*2 for i in range(n+1)]
dp[0][1]=1
m=defaultdict(int)
L=10**19
for i in range(n):
    a,b=LI()

    g=gcd(a,b)
    x,y=a//g,b//g
    if y<0:
        x*=-1
        y*=-1

    m[x*L+y]+=1
    u,v=-y,x
    if v<0:
        u*=-1
        v*=-1
    kp=x*L+y
    kq=u*L+v
    p=m[x*L+y]
    q=0
    if kq in m:
        q=m[kq]
    dp[i+1][0]=sum(dp[i])
    ng=1
    #ng*=pow(2,p-1,mo)
    ng*=(pow(2,q,mo)-1)
    ng*=pow(2,i-(p-1)-q,mo)
    dp[i+1][1]=sum(dp[i])-ng%mo
    
    #show(a,b,g,(x,y),x*L+y,ng)

print('DP',dp)
ans=sum(dp[n])-1

print(ans)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
from fractions import Fraction


N = int(input())

AB = [tuple(map(int, input().split())) for _ in range(N)]

MOD = 10**9 + 7

from collections import defaultdict

d = defaultdict(int)
ans = 1
cnt_00 = 0
for a,b in AB:
    if a == 0 and b == 0:
        cnt_00 += 1 
    elif a == b:
        d[1] += 1
    else:
        d[Fraction(a,b)] += 1




ans = 1
ks = list(d.keys())
for k in ks:
    if d[k] == 0:
        continue
    
    elif k == 1 or k == -1:

        num = pow(2,d[1]) + pow(2, d[-1])-1
        ans *= num
        ans %= MOD
        d[1] = 0
        d[-1] = 0

    else:

        num = pow(2, d[k]) + pow(2,d[Fraction(-1, k)])-1
        ans *= num
        ans %= MOD
        d[k] = 0
        d[Fraction(-1, k)] = 0
        



ans -=1
ans %= MOD
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 = []
for i in range(n):
    if (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
#print(xn,yn,xu,yu)
ans = pow(2,n-xn-yn,mod)
#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

print((ans-1)%mod)

Submission status: Runtime Error

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

def gcd(a, b):
    if a == 0:
        return b
    return gcd(b % a, a)
 
def main():
    n = int(readline())
    x, y  = [], []
    add = 0
    for i in range(n):
        a, b = map(int, readline().split())
        if a == 0 and b == 0:
            add += 1
            continue
        x.append(a)
        y.append(b)

    p = []
    index = 0
    for a, b in zip(x, y):
        cx = a
        cy = b
        if (-cx, -cy) > (cx, cy):
            cx = -cx
            cy = -cy
        g = gcd(abs(cx), abs(cy))
        cx /= g
        cy /= g
        p.append((cx, cy, 1, index))
        
        cx = b
        cy = -a
        if (-cx, -cy) > (cx, cy):
            cx = -cx
            cy = -cy
        g = gcd(abs(cx), abs(cy))
        cx /= g
        cy /= g
        p.append((cx, cy, 2, index))

        index += 1

    mod = 1000000007

    def GetValue(group):
        min1 = 10 ** 10
        min2 = 10 ** 10
        pow1 = 1
        pow2 = 1
        for g in group:
            _, __, t, i = g
            if t == 1:
                min1 = min(min1, i)
                pow1 = pow1 * 2 % mod
            else:
                min2 = min(min2, i)
                pow2 = pow2 * 2 % mod
        result = (pow1 + pow2 - 1 + mod) % mod
        if min1 > min2:
            result = 1
        #print group, result
        return result

    m = defaultdict(list)
    for t in p:
        x1, y1, _, __ = t
        m[(x1, y1)].append(t)

    result = 1
    for group in m.itervalues():
        result = result * GetValue(group) % mod 

    result = max(0, result - 1)

    print(result + add)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
import math
from collections import defaultdict
from bisect import bisect_left
from collections import Counter
sys.setrecursionlimit(10**8)
INF = float("inf")

MOD = 1000000007  # type: int


class UnionFind(object):
    def __init__(self, N):
        self.tree = list(range(N))

    def root(self, i):
        if self.tree[i] == i:
            return i
        else:
            self.tree[i] = self.root(self.tree[i])
            return self.tree[i]

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x != y:
            self.tree[x] = y


def solve(N: int, A: "List[int]", B: "List[int]"):
    # 直交するイワシは選べない
    # イワシをソートする
    abtheta = sorted(zip(A, B), key=lambda x: math.atan2(x[1], x[0]))
    # 順にイワシを見てグループを探す。二分探索で探す。
    uf = UnionFind(N)

    circle2 = abtheta*2

    end, end2 = 0, None
    for i in range(N):
        # イワシiと90度、180度、270度角度が異なるものはありますか
        # しゃくとりで
        a, b = abtheta[i]

        # 90度の関係にあるもの
        while end <= N+i:
            ai, bi = circle2[end]
            if ai*a+bi*b <= 0:
                break
            end += 1

        while ai*a+bi*b == 0:
            uf.unite(i, end % N)
            end += 1
            if end >= 2*N:
                break
            ai, bi = circle2[end]

        if end2 == None:
            end2 = end
            while True:
                ai, bi = circle2[end2]
                if ai*a + bi*b == 0:
                    end2 += 1
                else:
                    break

        # 180度のみなら別グループとして扱えば良いし、
        # 組み合わさるケースは別の点で検出できる

        # 270度の関係にあるもの
        while end2 <= N+i:
            ai, bi = circle2[end2]
            if ai*a+bi*b >= 0:
                break
            end2 += 1

        while ai*a+bi*b == 0:
            uf.unite(i, end2 % N)
            end2 += 1
            if end2 >= 2*N:
                break
            ai, bi = circle2[end2]

        if end == i + 1:
            end += 1

    # デフォルトディクトに変換する
    d = defaultdict(list)
    for i in range(N):
        d[uf.root(i)].append(abtheta[i])

    ans = 1
    for key in d:
        # 各グループをさらに二つに分類
        maru, batu = 1, 0
        a0, b0 = d[key][0]
        for a, b in d[key][1:]:
            if a0 * a + b0*b == 0:
                batu += 1
            else:
                maru += 1
        buf = pow(2, maru, MOD)
        buf += pow(2, batu, MOD)
        buf -= 1
        buf %= MOD
        ans *= buf

    # print(d)
    print((ans-1) % MOD)

    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:
from fractions import Fraction as fra
P=10**9+7

n=int(input())
G=[]
for index1 in range(n):
    a,b=map(int,input().split())
    if a<0 and b>0:
        G.append((-a,-b))
    elif a<0 and b<0:
        G.append((-a,-b))
    else:
        G.append((a,b))

D={}
S=set()
for i in range(n):
    x=G[i][0]
    y=G[i][1]
    if x==0:
        if y==0:
            if 'XY' in S:
                D['XY'][2]+=1
                continue
            else:
                D['XY']=[0,0,1]
                S.add('XY')
                continue
        else:
            if 'XY' in S:
                D['XY'][0]+=1
                continue
            else:
                D['XY']=[1,0,0]
                S.add('XY')
                continue
    else:
        if y==0:
            if 'XY' in S:
                D['XY'][1]+=1
                continue
            else:
                D['XY']=[0,1,0]
                S.add('XY')
                continue

    temp=fra(x,y)
    if y>0:
        temp_over=fra(y,-x)
    else:
        temp_over=fra(-y,x)
    if temp in S:
        D[temp][0]+=1
    elif temp_over in S:
        D[temp_over][1]+=1
    else:
        D[temp]=[1,0]
        S.add(temp)



def culc(List):
    return (pow(2,List[0],P)+pow(2,List[1],P)-1)%P



ans=1
if 'XY' in S:
    X=D['XY'][0]
    Y=D['XY'][1]
    XY=D['XY'][2]

    


while S:
    now=S.pop()
    obj=D[now]
    ans=(ans*culc(obj))%P


ans=(ans*culc([X,Y]))%P
ans=(ans+XY)%P

print((ans-1)%P)

Submission status: Runtime Error

Solution code:
def power_func(a, b, p=1000000007):
    if b == 0:
        return 1
    if b % 2 == 0:
        d = power_func(a, b // 2, p)
        return d * d % p
    if b % 2 == 1:
        return (a * power_func(a, b - 1, p)) % p
n = int(input())
A_B_dict = {}
for i in range(n):
    a, b = map(int,input().split())
    temp = a/b
    if temp in A_B_dict:
        A_B_dict[temp] += 1
    else:
        A_B_dict[temp] = 1
net_dict = {}
# if 0 in A_B_dict:
#     net_dict[0] = 2**A_B_dict[0]
for i in A_B_dict:
    if i == 0:
        net_dict[0] = power_func(2, A_B_dict[i])
    else:
        temp = -1/i
        if temp in A_B_dict:
            if i not in net_dict:
                net_dict[temp] = power_func(2, A_B_dict[i]) + power_func(2, A_B_dict[temp]) - 1
        else:
            net_dict[temp] = power_func(2,A_B_dict[i])
ans = 1
for k in net_dict.values():
    ans = (ans*k)
print((ans-1)%1000000007)

Submission status: Runtime Error

Solution code:
N = int(input())
MOD = 1000000007
d = {}
m = {}
for i in range(N):
  a, b = map(int, input().split())
  if -b/a in set(d.keys()):
    d[-b/a] += 1
  elif a/b in set(d.keys()):
    if a/b in set(m.keys()):
      m[a/b] += 1
    else:
      m[a/b] = 2      
  else:
    d[a/b] = 2
ans = 1
for v in d.values():
  ans = ans*v%MOD
for v in m.values():
  ans = ans+ans*(v-1)*0.5%MOD
print(ans-1)

Submission status: Runtime Error

Solution code:
from collections import deque
p = [1] * (n + 1)
for i in range(n):
    p[i + 1] = p[i] * 2 % mod
    
    
n = int(input())
a_list = []
b_list = deque()
p = [1] * (n + 1)
for i in range(n):
    p[i + 1] = p[i] * 2 % mod
mod = 10 ** 9 + 7
for _ in range(n):
    a, b = map(int, input().split())
    a_list.append((a * pow(b, mod - 2, mod)) % mod)
    b_list.append((b * pow(a, mod - 2, mod)) % mod)
count = n
out = 0
for aa in a_list:
    num = b_list.count((aa * (-1)) % mod)
    out += p[count - num - 1]
    out = out % mod
    count -= 1
    b_list.pop(0)
print(out)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
from fractions import Fraction


N = int(input())

AB = [tuple(map(int, input().split())) for _ in range(N)]

MOD = 10**9 + 7

from collections import defaultdict

d = defaultdict(int)
ans = 1
cnt_00 = 0
for a,b in AB:
    if a == 0 and b == 0:
        cnt_00 += 1 
    elif a == b:
        d[1] += 1
    else:
        d[Fraction(a,b)] += 1




ans = 1
ks = list(d.keys())
for k in ks:
    if d[k] == 0:
        continue
    
    elif k == 1 or k == -1:
        print("^^^", d[1], d[-1])
        num = pow(2,d[1]) + pow(2, d[-1])-1
        ans *= num
        ans %= MOD
        d[1] = 0
        d[-1] = 0

    else:

        num = pow(2, d[k]) + pow(2,d[Fraction(-1, k)])-1
        ans *= num
        ans %= MOD
        d[k] = 0
        d[Fraction(-1, k)] = 0
        



ans -=1
ans %= MOD
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
MOD = 1000000007

ans = 1
x_sardines = []
ver_sardines = []
hor_sardines  = []
zero_sardines  = []

for _ in range(n):
  ai, bi = map(int, input().split())
  if ai == 0 and bi != 0:
    ver_sardines.append((ai, bi))
  elif ai != 0 and bi == 0:
    hor_sardines.append((ai, bi))
  elif ai == 0 and bi == 0:
    zero_sardines.append((ai, bi))
  elif bi / ai > 0:
    x_sardines.append((ai, bi, 1))
  elif bi / ai < 0:
    x_sardines.append((- 1 * bi, ai, -1))

x_sardines.sort(key = lambda x: x[1] / x[0])

pai, pbi, ps = x_sardines[0]
p = 1 if ps == 1 else 0
n = 1 if ps == -1 else 0
for i, (ai, bi, s) in enumerate(x_sardines[1:]):
  if pai * bi - pbi * ai != 0:
    ans *= pow(2, p, MOD) + pow(2, n, MOD) - 1
    ans %= MOD
    p = 0
    n = 0
    
  if s == 1:
    p += 1
  elif s == -1:
    n += 1
  pai, pbi, ps = ai, bi, s

ans *= pow(2, p, MOD) + pow(2, n, MOD) - 1
ans %= MOD
  
v = len(ver_sardines)
h =  len(hor_sardines)
ans *= pow(2, v, MOD) + pow(2, h, MOD) - 1
ans %= MOD

z = len(zero_sardines)
ans += pow(2, z, MOD) - 1 
ans -= 1
ans %= MOD

print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
import math
ans = 1
PI = math.pi
MOD = 1000000007
N = int(input())
theta_list = []
for i in range(N):
    x, y = map(int, input().split())
    # r = math.sqrt(x**2 + y**2)
    theta = math.atan(y/x)
    theta_list += [theta]
    ans = (ans * 2) % MOD
    # if theta == PI / 2:
    #     theta_list += [theta-PI/2]
    # elif theta >= 0:
    #     theta_list += [theta]
    # else:
    #     theta_list += [theta + PI/2]
ans = (ans - 1) % MOD
counter = Counter()
for theta in theta_list:
    counter[str(theta)[:13]] += 1
items = counter.items()
visited = {}
for key, count in items:
    theta = float(key)
    if key == 0:
        continue
    elif theta > 0:
        theta -= PI/2
    elif theta < 0:
        theta += PI/2

    trg_key = str(theta)[:13]
    if visited.get(trg_key):
        continue
    visited[key] = True
    visited[trg_key] = True
    # print(counter[str(theta)[:13]] * count)
    ans = (ans - counter[str(theta)[:13]] * count * (N-1)) % MOD

# print(counter)
# print(theta_list)
print(ans)

Submission status: Runtime Error

Solution code:
import itertools as it
num=int(input())
fish=[]
for x in range(num):
  line=input().split()
  line=[int(i) for i in line]
  fish.append(line)
fnum=list(range(0,num))
for y in range(1,num+1):
  check=0
  print(fish[[0][0]])
#  for z in it.combinations(fnum,y):
  check+=fish[[0][0]]*fish[[0][0]]
  print(z)
  print(check)

Submission status: Runtime Error

Solution code:
import math
n= int(input())
s= []*n
k= [1]*n

for i in range(0,n):
    a,b =map(int,input().split())
    t= math.atan(a,b)
    if t in s:
        k[s.index(t)] += 1
    else:
        s.append(t)

for i in s:
    tempA= (i+90)% 360 
    tempB= (i+270)% 360
    if tempA in s:
        k[s.index(tempA)] += 1
    if tempB in s:
        k[s.index(tempB)] += 1

ans=1
kasanari=0
for i in k:
    ans *= i
    kasanari += (ans-1)
print((ans* pow(2,n-kasanari,1000000007))%1000000007)

Submission status: Runtime Error

Solution code:
from math import gcd
import sys
input = sys.stdin.readline

mod = 10**9 + 7
N = int(input())
cnt = {}
for i in range(N):
    A, B = map(int, input().split())
    neg = False
    if A < 0:
        neg ^= True
        A *= -1
    if B < 0:
        neg ^= True
        B *= -1
    g = gcd(A, B)
    sign = -1 if neg else 1
    A //= g
    B //= g
    frac = (-sign * A, B)
    if frac not in cnt:
        cnt[frac] = 0
    cnt[frac] += 1
ans = 1
used = set()
for frac, c in cnt.items():
    if frac in used:
        continue
    A, B = frac
    sign = 1
    if A < 0:
        A *= -1
        sign = -1
    bad = (B * -sign, A)
    if bad in cnt:
        b = cnt[bad]
        ans = ans * (pow(2, c, mod) + pow(2, b, mod) - 1) % mod
        used.add(bad)
    else:
        ans = ans * 2 % mod
print((ans - 1) % mod)

Submission status: Runtime Error

Solution code:
N = int(input())
A = []
B = []
C = {}
m = 1000000007
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
    if a/b in C.keys():
        C[a/b] +=1
    else: C[a/b] = 1
    
used = set()
ans = 1
for c in C.keys():
    if c in used: continue
    if -1/c in C.keys():
        used.add(-1/c)
        score = pow(2, C[c]) + pow(2, C[-1/c])- 1
        
        ans = (ans * score)%m

    else:
        
        ans = (ans*pow(2, C[c]))%m

print(ans-1)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from collections import deque
N=int(input())
MOD=1000000007

exist = defaultdict(int)
dup = defaultdict(float)
for _ in range(N):
    A,B=list(map(int,input().split()))
    rest =  -B/A
    corr = A/B
    if exist[rest] != 0:
        dup[rest]+=1
    exist[corr]=1

# a**n mod p
def power_func(a,n,p):
  bi=str(format(n,"b"))
  res=1
  for i in range(len(bi)):
    res=(res*res) %p
    if bi[i]=="1":
      res=(res*a) %p
  return res

ans = power_func(2,N,MOD) -1
for k,v in dup.items():
  minus = power_func(2,N-int(v)-1,MOD)
  ans -= minus
print(ans)

Submission status: Runtime Error

Solution code:
def main():
    import math
    import sys
    input = sys.stdin.readline
    n = int(input())
    mod = 10**9+7
    l1 = []
    l2 = []
    l3 = []
    for i in range(n):
        a,b = map(int,input().split())
        g = math.gcd(a,b)
        a //= g
        b //= g
        
        s2 = [a,b]
        if s2 in l1:
            l3[l1.index(s2)] += 1
        else:
            l1.append(s2)
            l2.append(-1)
            l3.append(1)
            if [-b,a] in l1:
                ind = l1.index([-b,a])
                l2[-1] = ind
                l2[ind] = len(l1)-1
            elif [b,-a] in l1:
                ind = l1.index([b,-a])
                l2[-1] = ind
                l2[ind] = len(l1)-1

    done = set()
    ans = 1
    for i in range(len(l2)):
        if l2[i] < 0:
            ans *= 2
            ans %= mod
        else:
            if l2[i] in done:
                continue
            c1 = l3[i]
            c2 = l3[l2[i]]
            count = (pow(2,c1,mod)+pow(2,c2,mod)-1)%mod
            ans *= count
            ans %= mod
            done.add(i)
            done.add(l2[i])

    print(ans-1)
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import math
N = int(input())
BOX = {}

I00 = 0
I10 = 0
I01 = 0
for i in range(N):
    A, B = input().split()
    A, B = int(A), int(B)
    A, B = A//math.gcd(A,B), B//math.gcd(A,B)

    if A == 0 and B == 0:
        I00 += 1
    elif A == 0:
        I01 += 1
    elif B == 0:
        I10 += 1
    else:
        M1, M2 = "-", "+"
        if A*B > 0:
            M1, M2 = "+", "-"
        A, B = abs(A), abs(B)

        C1 = M1+str(A)+'/'+str(B)
        C2 = M2+str(B)+'/'+str(A)

        if C1 not in BOX:
            BOX[C1] = [1, 0]
        else:
            BOX[C1][0] += 1

        if C2 not in BOX:
            BOX[C2] = [0, 1]
        else:
            BOX[C2][1] += 1

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

ANS = [0]
def comb(n):
    if len(ANS) > n:
        return ANS[n]
    c = len(ANS)
    while len(ANS) <= n:
        r = 0;
        for i in range(c):
            if i > 0:
                r += comb1(c, i)
        ANS.append(r+1)
        c += 1
    return ANS[n]

res = 1;
for k, v in BOX.items():
    if k[0] == '+':
        if v[0] == 0 or v[1] == 0:
            res *= (comb(v[0] + v[1]) + 1)
        else:
            res *= (1 + comb(v[0]) + comb(v[1]))

reigai = 1
if I01 > 0:
    reigai += comb(I01)
if I10 > 0:
    reigai += comb(I10)
print(res*reigai - 1 + I00)