Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10**9 + 7
P = 7 ** 21 + 52


def F(a, b):
    return (a * pow(b, P-2, P)) % P


def main():
    from collections import Counter
    import sys
    input = sys.stdin.buffer.readline
    N = int(input())
    T = [[int(i) for i in input().split()] for j in range(N)]
    A = []
    cnt_zero = [0, 0]  # 片方が0のとき
    p = 0  # 両方0
    cA = Counter()
    for a, b in T:
        if a == 0 and b == 0:
            p += 1
        elif a == 0:
            cnt_zero[0] += 1
        elif b == 0:
            cnt_zero[1] += 1
        else:
            A.append((F(a, b), -F(b, a) % P))
            cA[F(a, b)] += 1

    used = set()
    ans = 1
    ans *= pow(2, cnt_zero[0], MOD) - 1 + pow(2, cnt_zero[1], MOD) - 1 + 1
    for a, b in A:
        if a in used or b in used:
            continue
        ans *= pow(2, cA[a], MOD) - 1 + pow(2, cA[b], MOD) - 1 + 1
        ans %= MOD
        used.add(a)
        used.add(b)
    print((ans + p - 1) % MOD)


if __name__ == '__main__':
    main()


Fixed submission:
MOD = 10**9 + 7
P = 7 ** 21 + 52


def F(a, b):
    return (a * pow(b, P-2, P)) % P


def main():
    from collections import Counter
    import sys
    input = sys.stdin.buffer.readline
    N = int(input())
    T = [[int(i) for i in input().split()] for j in range(N)]
    cnt_zero = [0, 0]  # 片方が0のとき
    p = 0  # 両方0
    cA = Counter()
    B = []
    used = set()
    for a, b in T:
        if a == 0 and b == 0:
            p += 1
        elif a == 0:
            cnt_zero[0] += 1
        elif b == 0:
            cnt_zero[1] += 1
        else:
            x = F(a, b)
            y = -F(b, a) % P
            cA[x] += 1
            if x not in used and y not in used:
                B.append((x, y))
                used.add(x)
                used.add(y)

    ans = 1
    ans *= pow(2, cnt_zero[0], MOD) - 1 + pow(2, cnt_zero[1], MOD) - 1 + 1
    for a, b in B:
        ans *= pow(2, cA[a], MOD) - 1 + pow(2, cA[b], MOD) - 1 + 1
        ans %= MOD
    print((ans + p - 1) % MOD)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import Fraction as F
MOD = 10**9 + 7


def main(N, T):
    A = []
    cnt_zero = [0, 0]  # 片方が0のとき
    p = 0  # 両方0
    cA = {}
    for a, b in T:
        if a == 0 and b == 0:
            p += 1
        elif a == 0:
            cnt_zero[0] += 1
        elif b == 0:
            cnt_zero[1] += 1
        else:
            A.append((F(a, b), F(b, a)))
            if F(a, b) not in cA.keys():
                cA[F(a, b)] = 0
            if -F(b, a) not in cA.keys():
                cA[-F(b, a)] = 0
            cA[F(a, b)] += 1

    used = set()
    ans = 1
    ans *= pow(2, cnt_zero[0], MOD) - 1 + pow(2, cnt_zero[1], MOD) - 1 + 1
    for a, b in A:
        if a in used or -b in used:
            continue
        ans *= pow(2, cA[a], MOD) - 1 + pow(2, cA[-b], MOD) - 1 + 1
        ans %= MOD
        used.add(a)
        used.add(-b)
    print((ans + p - 1) % MOD)


if __name__ == '__main__':

    N = int(input())
    T = [[int(i) for i in input().split()] for j in range(N)]
    main(N, T)


Fixed submission:
MOD = 10**9 + 7
P = 7 ** 21 + 52


def F(a, b):
    return (a * pow(b, P-2, P)) % P


def main():
    from collections import Counter
    import sys
    input = sys.stdin.buffer.readline
    N = int(input())
    T = [[int(i) for i in input().split()] for j in range(N)]
    cnt_zero = [0, 0]  # 片方が0のとき
    p = 0  # 両方0
    cA = Counter()
    B = []
    used = set()
    for a, b in T:
        if a == 0 and b == 0:
            p += 1
        elif a == 0:
            cnt_zero[0] += 1
        elif b == 0:
            cnt_zero[1] += 1
        else:
            x = F(a, b)
            y = -F(b, a) % P
            cA[x] += 1
            if x not in used and y not in used:
                B.append((x, y))
                used.add(x)
                used.add(y)

    ans = 1
    ans *= pow(2, cnt_zero[0], MOD) - 1 + pow(2, cnt_zero[1], MOD) - 1 + 1
    for a, b in B:
        ans *= pow(2, cA[a], MOD) - 1 + pow(2, cA[b], MOD) - 1 + 1
        ans %= MOD
    print((ans + p - 1) % MOD)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10**9 + 7


def main():
    from fractions import Fraction as F
    N = int(input())
    A = []
    cnt_zero = [0, 0]  # 片方が0のとき
    p = 0  # 両方0
    cA = {}
    for _ in range(N):
        a, b = (int(i) for i in input().split())
        if a == 0 and b == 0:
            p += 1
        elif a == 0:
            cnt_zero[0] += 1
        elif b == 0:
            cnt_zero[1] += 1
        else:
            A.append((F(a, b), F(b, a)))
            if F(a, b) not in cA.keys():
                cA[F(a, b)] = 0
            if -F(b, a) not in cA.keys():
                cA[-F(b, a)] = 0
            cA[F(a, b)] += 1

    used = set()
    ans = 1
    ans *= pow(2, cnt_zero[0], MOD) - 1 + pow(2, cnt_zero[1], MOD) - 1 + 1
    for a, b in A:
        if a in used or -b in used:
            continue
        ans *= pow(2, cA[a], MOD) - 1 + pow(2, cA[-b], MOD) - 1 + 1
        ans %= MOD
        used.add(a)
        used.add(-b)
    print((ans + p - 1) % MOD)


if __name__ == '__main__':
    main()


Fixed submission:
MOD = 10**9 + 7
P = 7 ** 21 + 52


def F(a, b):
    return (a * pow(b, P-2, P)) % P


def main():
    from collections import Counter
    import sys
    input = sys.stdin.buffer.readline
    N = int(input())
    T = [[int(i) for i in input().split()] for j in range(N)]
    cnt_zero = [0, 0]  # 片方が0のとき
    p = 0  # 両方0
    cA = Counter()
    B = []
    used = set()
    for a, b in T:
        if a == 0 and b == 0:
            p += 1
        elif a == 0:
            cnt_zero[0] += 1
        elif b == 0:
            cnt_zero[1] += 1
        else:
            x = F(a, b)
            y = -F(b, a) % P
            cA[x] += 1
            if x not in used and y not in used:
                B.append((x, y))
                used.add(x)
                used.add(y)

    ans = 1
    ans *= pow(2, cnt_zero[0], MOD) - 1 + pow(2, cnt_zero[1], MOD) - 1 + 1
    for a, b in B:
        ans *= pow(2, cA[a], MOD) - 1 + pow(2, cA[b], MOD) - 1 + 1
        ans %= MOD
    print((ans + p - 1) % MOD)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10**9 + 7


def main():
    from fractions import Fraction as F
    from collections import Counter

    N = int(input())
    A = []
    cnt_zero = [0, 0]  # 片方が0のとき
    p = 0  # 両方0
    cA = Counter()
    for _ in range(N):
        a, b = (int(i) for i in input().split())
        if a == 0 and b == 0:
            p += 1
        elif a == 0:
            cnt_zero[0] += 1
        elif b == 0:
            cnt_zero[1] += 1
        else:
            A.append((F(a, b), F(b, a)))
            cA[F(a, b)] += 1

    used = set()
    ans = 1
    ans *= pow(2, cnt_zero[0], MOD) - 1 + pow(2, cnt_zero[1], MOD) - 1 + 1
    for a, b in A:
        if a in used or -b in used:
            continue
        ans *= pow(2, cA[a], MOD) - 1 + pow(2, cA[-b], MOD) - 1 + 1
        ans %= MOD
        used.add(a)
        used.add(-b)
    print((ans + p - 1) % MOD)


if __name__ == '__main__':
    main()


Fixed submission:
MOD = 10**9 + 7
P = 7 ** 21 + 52


def F(a, b):
    return (a * pow(b, P-2, P)) % P


def main():
    from collections import Counter
    import sys
    input = sys.stdin.buffer.readline
    N = int(input())
    T = [[int(i) for i in input().split()] for j in range(N)]
    cnt_zero = [0, 0]  # 片方が0のとき
    p = 0  # 両方0
    cA = Counter()
    B = []
    used = set()
    for a, b in T:
        if a == 0 and b == 0:
            p += 1
        elif a == 0:
            cnt_zero[0] += 1
        elif b == 0:
            cnt_zero[1] += 1
        else:
            x = F(a, b)
            y = -F(b, a) % P
            cA[x] += 1
            if x not in used and y not in used:
                B.append((x, y))
                used.add(x)
                used.add(y)

    ans = 1
    ans *= pow(2, cnt_zero[0], MOD) - 1 + pow(2, cnt_zero[1], MOD) - 1 + 1
    for a, b in B:
        ans *= pow(2, cA[a], MOD) - 1 + pow(2, cA[b], MOD) - 1 + 1
        ans %= MOD
    print((ans + p - 1) % MOD)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
MOD = 10**9 + 7


def main():
    N = int(input())
    AB = {tuple(sorted(int(i) for i in input().split())) for j in range(N)}
    cnt = 0
    ban = set()
    bannum = 0
    for a, b in AB:
        if (a, b) in ban:
            continue
        ban1 = (-a, b)
        ban2 = (a, -b)
        if ban1 in AB and ban2 in AB:
            ban.add(ban1)
            ban.add(ban2)
            cnt += 1
            bannum += 3*pow(2, N-3, MOD)
            bannum %= MOD
        elif ban1 in AB:
            ban.add(ban1)
            cnt += 1
            bannum += pow(2, N-2, MOD)
            bannum %= MOD
        elif ban2 in AB:
            ban.add(ban2)
            bannum += pow(2, N-2, MOD)
            bannum %= MOD
            cnt += 1
    if (-1, 1) in AB:
        add = 1
        for a, b in AB:
            if a == b:
                bannum += pow(2, N-2, MOD)
                bannum %= MOD
                add += 1
        cnt += add
    # cntは選んではいけないペアの数
    v = cnt
    ans = pow(2, N, MOD) - 1
    ans -= bannum
    ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
MOD = 10**9 + 7
P = 7 ** 21 + 52


def F(a, b):
    return (a * pow(b, P-2, P)) % P


def main():
    from collections import Counter
    import sys
    input = sys.stdin.buffer.readline
    N = int(input())
    T = [[int(i) for i in input().split()] for j in range(N)]
    cnt_zero = [0, 0]  # 片方が0のとき
    p = 0  # 両方0
    cA = Counter()
    B = []
    used = set()
    for a, b in T:
        if a == 0 and b == 0:
            p += 1
        elif a == 0:
            cnt_zero[0] += 1
        elif b == 0:
            cnt_zero[1] += 1
        else:
            x = F(a, b)
            y = -F(b, a) % P
            cA[x] += 1
            if x not in used and y not in used:
                B.append((x, y))
                used.add(x)
                used.add(y)

    ans = 1
    ans *= pow(2, cnt_zero[0], MOD) - 1 + pow(2, cnt_zero[1], MOD) - 1 + 1
    for a, b in B:
        ans *= pow(2, cA[a], MOD) - 1 + pow(2, cA[b], MOD) - 1 + 1
        ans %= MOD
    print((ans + p - 1) % MOD)


if __name__ == '__main__':
    main()