Buggy python submission (verdict: Time Limit Exceeded):
from fractions import Fraction
from collections import defaultdict


def inverse(key):
    if key == "inf":
        return Fraction(0, 1)

    if key == Fraction(0, 1):
        return "inf"

    return - Fraction(key.denominator, key.numerator)


mod = 10 ** 9 + 7
n = int(input())
fishes = defaultdict(int)

zero_zero = 0
for _ in range(n):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        zero_zero += 1
        continue

    elif b == 0:
        key = "inf"

    else:
        key = Fraction(a, b)

    fishes[key] += 1

ans = 1
counted_key = set()
for fish_key, count in fishes.items():
    if fish_key in counted_key:
        continue

    bad_pair = inverse(fish_key)
    if bad_pair in fishes:
        pair_count = fishes[bad_pair]
        pattern = pow(2, count, mod) + pow(2, pair_count, mod) - 1
        counted_key.add(bad_pair)

    else:
        pattern = pow(2, count, mod)

    ans = ans * pattern % mod

if zero_zero:
    ans += zero_zero

ans -= 1
print(ans % mod)


Fixed submission:
from collections import defaultdict
from math import gcd

mod = 10 ** 9 + 7
n = int(input())
fishes = defaultdict(int)
zero_zero = 0
zero = 0
inf = 0

for _ in range(n):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        zero_zero += 1

    elif a == 0:
        zero += 1

    elif b == 0:
        inf += 1

    else:
        div = gcd(a, b)
        a //= div
        b //= div
        if b < 0:
            a *= -1
            b *= -1
        key = (a, b)
        fishes[key] += 1


def get_bad_pair(fish):
    a, b = fish
    if a < 0:
        a *= -1
        b *= -1
    return (-b, a)


ans = 1
counted_key = set()
for fish_key, count in fishes.items():
    if fish_key in counted_key:
        continue

    bad_pair = get_bad_pair(fish_key)
    if bad_pair in fishes:
        pair_count = fishes[bad_pair]
        pattern = pow(2, count, mod) + pow(2, pair_count, mod) - 1
        counted_key.add(bad_pair)

    else:
        pattern = pow(2, count, mod)

    ans = ans * pattern % mod

ans *= pow(2, zero, mod) + pow(2, inf, mod) - 1
if zero_zero:
    ans += zero_zero

ans -= 1
print(ans % mod)

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import Fraction
from collections import defaultdict


def inverse(key):
    if key == "inf":
        return Fraction(0, 1)

    if key == Fraction(0, 1):
        return "inf"

    return - Fraction(key.denominator, key.numerator)


mod = 10 ** 9 + 7
n = int(input())
fishes = defaultdict(int)

zero_zero = 0
for _ in range(n):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        zero_zero += 1
        continue

    elif b == 0:
        key = "inf"

    else:
        key = Fraction(a, b)

    fishes[key] += 1

ans = 1
counted_key = set()
for fish_key, count in fishes.items():
    if fish_key in counted_key:
        continue

    bad_pair = inverse(fish_key)
    if bad_pair in fishes:
        pair_count = fishes[bad_pair]
        pattern = pow(2, count, mod) + pow(2, pair_count, mod) - 1
        counted_key.add(bad_pair)

    else:
        pattern = pow(2, count, mod)

    ans = ans * pattern % mod

if zero_zero:
    ans += zero_zero

ans -= 1
print(ans % mod)


Fixed submission:
from collections import defaultdict
from math import gcd

mod = 10 ** 9 + 7
n = int(input())
fishes = defaultdict(int)
zero_zero = 0
zero = 0
inf = 0

for _ in range(n):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        zero_zero += 1

    elif a == 0:
        zero += 1

    elif b == 0:
        inf += 1

    else:
        div = gcd(a, b)
        a //= div
        b //= div
        if b < 0:
            a *= -1
            b *= -1
        key = (a, b)
        fishes[key] += 1


def get_bad_pair(fish):
    a, b = fish
    if a < 0:
        a *= -1
        b *= -1
    return (-b, a)


ans = 1
counted_key = set()
for fish_key, count in fishes.items():
    if fish_key in counted_key:
        continue

    bad_pair = get_bad_pair(fish_key)
    if bad_pair in fishes:
        pair_count = fishes[bad_pair]
        pattern = pow(2, count, mod) + pow(2, pair_count, mod) - 1
        counted_key.add(bad_pair)

    else:
        pattern = pow(2, count, mod)

    ans = ans * pattern % mod

ans *= pow(2, zero, mod) + pow(2, inf, mod) - 1
if zero_zero:
    ans += zero_zero

ans -= 1
print(ans % mod)

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
from fractions import Fraction
import sys
input = sys.stdin.readline

mod = 1000000007
n = int(input())

a_per_b = defaultdict(int)
minus_b_per_a = defaultdict(int)

for _ in range(n):
    a, b = map(int, input().split())
    x = Fraction(a, b)
    y = -Fraction(b, a)
    a_per_b[x] += 1
    minus_b_per_a[y] += 1


def inverse(f):
    return Fraction(f.denominator, f.numerator)


ans = 1
calculated = set()
for key, count in a_per_b.items():
    if key in calculated:
        continue

    if key in minus_b_per_a:
        bad_count = minus_b_per_a[key]
        ans *= pow(2, count+bad_count, mod) - (pow(2, count, mod) - 1) * (pow(2, bad_count, mod) - 1) % mod
        ans %= mod
        calculated.add(-inverse(key))
    else:
        ans *= pow(2, count, mod)
        ans %= mod

print(ans - 1)


Fixed submission:
from collections import defaultdict
from math import gcd

mod = 10 ** 9 + 7
n = int(input())
fishes = defaultdict(int)
zero_zero = 0
zero = 0
inf = 0

for _ in range(n):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        zero_zero += 1

    elif a == 0:
        zero += 1

    elif b == 0:
        inf += 1

    else:
        div = gcd(a, b)
        a //= div
        b //= div
        if b < 0:
            a *= -1
            b *= -1
        key = (a, b)
        fishes[key] += 1


def get_bad_pair(fish):
    a, b = fish
    if a < 0:
        a *= -1
        b *= -1
    return (-b, a)


ans = 1
counted_key = set()
for fish_key, count in fishes.items():
    if fish_key in counted_key:
        continue

    bad_pair = get_bad_pair(fish_key)
    if bad_pair in fishes:
        pair_count = fishes[bad_pair]
        pattern = pow(2, count, mod) + pow(2, pair_count, mod) - 1
        counted_key.add(bad_pair)

    else:
        pattern = pow(2, count, mod)

    ans = ans * pattern % mod

ans *= pow(2, zero, mod) + pow(2, inf, mod) - 1
if zero_zero:
    ans += zero_zero

ans -= 1
print(ans % mod)