Problem p02679 (python)

Fixed submission:
import math

n = int(input())
mod = 10**9+7
d = {}

zero = 0
for i in range(n):
    a,b = map(int,input().split())
    if a == 0 and b == 0:
        zero += 1
    else:
        g = math.gcd(a,b)
        a //= g
        b //= g
        if b < 0:
            a = -a
            b = -b
        if b == 0 and a == -1:
            a = 1
        if a > 0:
            if (a,b) in d:
                d[(a,b)][0] += 1
            else:
                d[(a,b)] = [1,0]
        else:
            if (b,-a) in d:
                d[(b,-a)][1] += 1
            else:
                d[(b,-a)] = [0,1]
ans = 1
for (a,b),(c,d) in d.items():
    count = (pow(2,c,mod)+pow(2,d,mod)-1)%mod
    ans *= count
    ans %= mod


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

Buggy submission (verdict: Runtime Error):
import math

n = int(input())
mod = 10**9+7
d = {}
l = []
s = set()
zero = 0
for i in range(n):
    a,b = map(int,input().split())
    if a == 0 and b == 0:
        zero += 1
    elif a == 0:
        s1 = (0,1)
        s2 = (1,0)
    elif b == 0:
        s1 = (1,0)
        s2 = (0,1)
    else:
        
        g = math.gcd(a,b)
        if b > 0:
            a //= g
            b //= g
            s1 = (a,b)
            if a > 0:
                
                s2 = (-b,a)
            else: 
                
                s2 = (b,-a)
        else:
            a //= g
            b //= g
            s1 = (-a,-b)
            if a < 0:
                
                s2 = (b,-a)
            else:
                
                s2 = (-b,a)
    if s1 in d:
        d[s1] += 1
    else:
        d[s1] = 1
    if s1 in s:
        continue
    else:
        if s2 in d:
            l.append([s1,s2])
            s.add(s1)
            s.add(s2)
    
ans = 1
for a,b in l:
    count = (pow(2,d[a],mod)+pow(2,d[b],mod)-1)%mod
    ans *= count
    ans %= mod
for i,j in d.items():
    if i in s:
        continue
    else:
        ans *= pow(2,j,mod)
        ans %= mod

print(ans+zero-1)

Buggy submission (verdict: Runtime Error):
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()

Buggy submission (verdict: Runtime Error):
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()

Buggy submission (verdict: Runtime Error):

n = int(input())
mod = 10**9+7
l1 = []
l2 = []
l3 = []
for i in range(n):
    a,b = map(int,input().split())
    s1 = -b/a
    s2 = a/b
    if s2 in l1:
        l3[l1.index(s2)] += 1
    else:
        l1.append(s2)
        l2.append(-1)
        l3.append(1)
        if s1 in l1:
            ind = l1.index(s1)
            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)

Buggy submission (verdict: Runtime Error):
def main():
    import sys
    input = sys.stdin.readline
    n = int(input())
    mod = 10**9+7
    d = {}
    l1 = []
    l2 = []
    for i in range(n):
        a,b = map(int,input().split())
        s1 = -b/a
        s2 = a/b
        if s2 in d:
            d[s2] += 1
        else:
            l1.append(s2)
            l2.append(-1)
            d[s2] = 1
            if s1 in d:
                ind = l1.index(s1)
                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 = d[l1[i]]
            c2 = d[l1[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()