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: Wrong Answer

Solution code:
def numba_compile(numba_config):
    import os, sys
    if sys.argv[-1] == "ONLINE_JUDGE":
        from numba import njit
        from numba.pycc import CC
        cc = CC("my_module")
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature)(func)
            cc.export(func.__name__, signature)(func)
        cc.compile()
        exit()
    elif os.name == "posix":
        exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
        for func, _ in numba_config:
            globals()[func.__name__] = vars()[func.__name__]
    else:
        from numba import njit
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature, cache=True)(func)
        print("compiled!", file=sys.stderr)

import sys
import numpy as np
mod = 10**9+7
def pow_mod(base, exp):  # [pow_mod, "i8(i8,i8)"],
    # mod はグローバル変数を参照
    exp %= mod - 1
    res = 1
    while exp:
        if exp % 2:
            res = res * base % mod
        base = base * base % mod
        exp //= 2
    return res

def solve(N, AB):
    n = 0
    na = nb = nab = 0
    Cnt = {}
    for a, b in zip(AB[::2], AB[1::2]):
        if (a, b) == (0, 0):
            nab += 1
        elif a == 0:
            na += 1
        elif b == 0:
            nb += 1
        else:
            ab_fr = a * pow_mod(b, -1) % mod
            n += 1
            if ab_fr in Cnt:
                Cnt[ab_fr] += 1
            else:
                Cnt[ab_fr] = 1
            inv = -pow_mod(ab_fr, -1) % mod
            if inv not in Cnt:
                Cnt[inv] = 0
    ans = (pow_mod(2, na) + pow_mod(2, nb) - 1) % mod
    A = []
    for ab_fr, cnt in Cnt.items():
        cnt2 = Cnt[(-pow_mod(ab_fr, -1))%mod]
        p = pow_mod(2, cnt)
        p2 = pow_mod(2, cnt2)
        A.append(ans * (p + p2 - 1) % mod)
    A.sort()
    for a in A[::2]:
        ans = ans * a % mod
    ans += nab - 1
    return ans % mod

numba_compile([
    [pow_mod, "i8(i8,i8)"],
    [solve, "i8(i8,i8[:])"],
])

def main():
    N = int(sys.stdin.buffer.readline())
    m = np.array(sys.stdin.buffer.read().split(), dtype=np.int64)
    ans = solve(N, m)
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
def numba_compile(numba_config):
    import os, sys
    if sys.argv[-1] == "ONLINE_JUDGE":
        from numba import njit
        from numba.pycc import CC
        cc = CC("my_module")
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature)(func)
            cc.export(func.__name__, signature)(func)
        cc.compile()
        exit()
    elif os.name == "posix":
        exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
        for func, _ in numba_config:
            globals()[func.__name__] = vars()[func.__name__]
    else:
        from numba import njit
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature, cache=True)(func)
        print("compiled!", file=sys.stderr)

import sys
import numpy as np
mod = 10**9+7
def pow_mod(base, exp):  # [pow_mod, "i8(i8,i8)"],
    # mod はグローバル変数を参照
    exp %= mod - 1
    res = 1
    while exp:
        if exp % 2:
            res = res * base % mod
        base = base * base % mod
        exp //= 2
    return res

def solve(N, AB):
    n = 0
    na = nb = nab = 0
    Cnt = {}
    for a, b in zip(AB[::2], AB[1::2]):
        if (a, b) == (0, 0):
            nab += 1
        elif a == 0:
            na += 1
        elif b == 0:
            nb += 1
        else:
            ab_fr = a * pow_mod(b, -1) % mod
            n += 1
            if ab_fr in Cnt:
                Cnt[ab_fr] += 1
            else:
                Cnt[ab_fr] = 1
            inv = -pow_mod(ab_fr, -1) % mod
            if inv not in Cnt:
                Cnt[inv] = 0
    ans = (pow_mod(2, na) + pow_mod(2, nb) - 1) % mod
    A = []
    for ab_fr, cnt in Cnt.items():
        cnt2 = Cnt[(-pow_mod(ab_fr, -1))%mod]
        p = pow_mod(2, cnt)
        p2 = pow_mod(2, cnt2)
        A.append(ans * (p + p2 - 1) % mod)
    A.sort()
    for a in A[::2]:
        ans = ans * a % mod
    if nab == 0:
        ans -= 1
    return ans % mod

numba_compile([
    [pow_mod, "i8(i8,i8)"],
    [solve, "i8(i8,i8[:])"],
])

def main():
    N = int(sys.stdin.buffer.readline())
    m = np.array(sys.stdin.buffer.read().split(), dtype=np.int64)
    ans = solve(N, m)
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
def numba_compile(numba_config):
    import os, sys
    if sys.argv[-1] == "ONLINE_JUDGE":
        from numba import njit
        from numba.pycc import CC
        cc = CC("my_module")
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature)(func)
            cc.export(func.__name__, signature)(func)
        cc.compile()
        exit()
    elif os.name == "posix":
        exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
        for func, _ in numba_config:
            globals()[func.__name__] = vars()[func.__name__]
    else:
        from numba import njit
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature, cache=True)(func)
        print("compiled!", file=sys.stderr)

import sys
import numpy as np
mod = 10**9+7
def pow_mod(base, exp):  # [pow_mod, "i8(i8,i8)"],
    # mod はグローバル変数を参照
    exp %= mod - 1
    res = 1
    while exp:
        if exp % 2:
            res = res * base % mod
        base = base * base % mod
        exp //= 2
    return res

def solve(N, AB):
    n = 0
    na = nb = 0
    Cnt = {}
    for a, b in zip(AB[::2], AB[1::2]):
        if (a, b) == (0, 0):
            pass
        elif a == 0:
            na += 1
        elif b == 0:
            nb += 1
        else:
            ab_fr = a * pow_mod(b, -1) % mod
            n += 1
            if ab_fr in Cnt:
                Cnt[ab_fr] += 1
            else:
                Cnt[ab_fr] = 1
            inv = -pow_mod(ab_fr, -1) % mod
            if inv not in Cnt:
                Cnt[inv] = 0
    ans = (pow_mod(2, na) + pow_mod(2, nb) - 1) % mod
    if n == 0:
        return ans
    A = []
    for ab_fr, cnt in Cnt.items():
        cnt2 = Cnt[(-pow_mod(ab_fr, -1))%mod]
        p = pow_mod(2, cnt)
        p2 = pow_mod(2, cnt2)
        A.append(ans * (p + p2 - 1) % mod)
    A.sort()
    for a in A[::2]:
        ans = ans * a % mod
    return (ans - 1) % mod

numba_compile([
    [pow_mod, "i8(i8,i8)"],
    [solve, "i8(i8,i8[:])"],
])

def main():
    N = int(sys.stdin.buffer.readline())
    m = np.array(sys.stdin.buffer.read().split(), dtype=np.int64)
    ans = solve(N, m)
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
def numba_compile(numba_config):
    import os, sys
    if sys.argv[-1] == "ONLINE_JUDGE":
        from numba import njit
        from numba.pycc import CC
        cc = CC("my_module")
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature)(func)
            cc.export(func.__name__, signature)(func)
        cc.compile()
        exit()
    elif os.name == "posix":
        exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
        for func, _ in numba_config:
            globals()[func.__name__] = vars()[func.__name__]
    else:
        from numba import njit
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature, cache=True)(func)
        print("compiled!", file=sys.stderr)

import sys
import numpy as np
mod = 10**9+7
def pow_mod(base, exp):  # [pow_mod, "i8(i8,i8)"],
    # mod はグローバル変数を参照
    exp %= mod - 1
    res = 1
    while exp:
        if exp % 2:
            res = res * base % mod
        base = base * base % mod
        exp //= 2
    return res

def solve(N, AB):
    n = 0
    na = nb = 0
    Cnt = {}
    for a, b in zip(AB[::2], AB[1::2]):
        if (a, b) == (0, 0):
            pass
        elif a == 0:
            na += 1
        elif b == 0:
            nb += 1
        else:
            ab_fr = a * pow_mod(b, -1) % mod
            n += 1
            if ab_fr in Cnt:
                Cnt[ab_fr] += 1
            else:
                Cnt[ab_fr] = 1
            inv = -pow_mod(ab_fr, -1) % mod
            if inv not in Cnt:
                Cnt[inv] = 0
    if n == 0:
        return 1
    ans = (pow_mod(2, na) + pow_mod(2, nb) - 1) % mod
    A = []
    for ab_fr, cnt in Cnt.items():
        cnt2 = Cnt[(-pow_mod(ab_fr, -1))%mod]
        p = pow_mod(2, cnt)
        p2 = pow_mod(2, cnt2)
        A.append(ans * (p + p2 - 1) % mod)
    A.sort()
    for a in A[::2]:
        ans = ans * a % mod
    return (ans - 1) % mod

#numba_compile([
#    [pow_mod, "i8(i8,i8)"],
#    [solve, "i8(i8,i8[:])"],
#])

def main():
    N = int(sys.stdin.buffer.readline())
    m = np.array(sys.stdin.buffer.read().split(), dtype=np.int64)
    ans = solve(N, m)
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
def numba_compile(numba_config):
    import os, sys
    if sys.argv[-1] == "ONLINE_JUDGE":
        from numba import njit
        from numba.pycc import CC
        cc = CC("my_module")
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature)(func)
            cc.export(func.__name__, signature)(func)
        cc.compile()
        exit()
    elif os.name == "posix":
        exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
        for func, _ in numba_config:
            globals()[func.__name__] = vars()[func.__name__]
    else:
        from numba import njit
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature, cache=True)(func)
        print("compiled!", file=sys.stderr)

import sys
import numpy as np
mod = 10**9+7
def pow_mod(base, exp):  # [pow_mod, "i8(i8,i8)"],
    # mod はグローバル変数を参照
    exp %= mod - 1
    res = 1
    while exp:
        if exp % 2:
            res = res * base % mod
        base = base * base % mod
        exp //= 2
    return res

def solve(N, AB):
    n = 0
    na = nb = 0
    Cnt = {}
    for a, b in zip(AB[::2], AB[1::2]):
        if (a, b) == (0, 0):
            pass
        elif a == 0:
            na += 1
        elif b == 0:
            nb += 1
        else:
            ab_fr = a * pow_mod(b, -1) % mod
            n += 1
            if ab_fr in Cnt:
                Cnt[ab_fr] += 1
            else:
                Cnt[ab_fr] = 1
            inv = -pow_mod(ab_fr, -1) % mod
            if inv not in Cnt:
                Cnt[inv] = 0
    if n == 0:
        return 1
    ans = (pow_mod(2, na) + pow_mod(2, nb) - 1) % mod
    A = []
    for ab_fr, cnt in Cnt.items():
        cnt2 = Cnt[(-pow_mod(ab_fr, -1))%mod]
        p = pow_mod(2, cnt)
        p2 = pow_mod(2, cnt2)
        A.append(ans * (p + p2 - 1) % mod)
    A.sort()
    for a in A[::2]:
        ans = ans * a % mod
    return (ans - 1) % mod

numba_compile([
    [pow_mod, "i8(i8,i8)"],
    [solve, "i8(i8,i8[:])"],
])

def main():
    N = int(sys.stdin.buffer.readline())
    m = np.array(sys.stdin.buffer.read().split(), dtype=np.int64)
    ans = solve(N, m)
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


# 有理数クラス
class MyFraction:

    def __init__(self, a, b):
        assert b != 0, "分母が0です"

        if b < 0:
            a, b = -a, -b
        if a == 0:
            b = 1

        g = math.gcd(a, b)
        self.numerator = a // g
        self.denominator = b // g

    def __str__(self):
        return "{0}/{1}".format(self.numerator, self.denominator)


def main():
    N = NI()
    AB = defaultdict(int)
    Y, Z = 0, 0
    for i in range(N):
        a, b = NMI()
        if a == b == 0:
            Z += 1
            continue
        if b == 0:
            Y += 1
            continue

        if str(MyFraction(a, b)) in AB:
            AB[str(MyFraction(a, b))] += 1
        else:
            AB[str(MyFraction(a, b))] = 1

    C = defaultdict(lambda: ())
    ans = 1
    flag = True
    for ab, k in list(AB.items()):
        a, b = ab.split("/")
        a = int(a)
        b = int(b)
        if a > 0:
            if str(MyFraction(-b, a)) in AB:
                t = AB[str(MyFraction(-b, a))]
            else:
                t = 0
        elif a < 0:
            if str(MyFraction(b, -a)) in AB:
                continue
            t = 0
        else:
            flag = False
            t = Y
        C[(a, b)] = (k, t)

    for k, t in list(C.values()):
        tmp = pow(2, k, MOD) + pow(2, t, MOD) - 1
        ans = ans * tmp % MOD

    if flag:
        print(Y)
        tmp = pow(2, Y, MOD)
        ans = ans * tmp % MOD
    print((ans + Z - 1)%MOD)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


# 有理数クラス
class MyFraction:

    def __init__(self, a, b):
        assert b != 0, "分母が0です"

        if b < 0:
            a, b = -a, -b
        if a == 0:
            b = 1

        g = math.gcd(a, b)
        self.numerator = a // g
        self.denominator = b // g

    def __str__(self):
        return "{0}/{1}".format(self.numerator, self.denominator)


def main():
    N = NI()
    AB = defaultdict(int)
    Y, Z = 0, 0
    for i in range(N):
        a, b = NMI()
        if a == b == 0:
            Z += 1
            continue
        if b == 0:
            Y += 1
            AB["1/0"] += 1
            continue

        if str(MyFraction(a, b)) in AB:
            AB[str(MyFraction(a, b))] += 1
        else:
            AB[str(MyFraction(a, b))] = 1

    C = defaultdict(lambda: ())
    ans = 1
    for ab, k in list(AB.items()):
        a, b = ab.split("/")
        a = int(a)
        b = int(b)
        if a > 0 and b != 0:
            if str(MyFraction(-b, a)) in AB:
                t = AB[str(MyFraction(-b, a))]
            else:
                t = 0
        elif a < 0:
            if str(MyFraction(b, -a)) in AB:
                continue
            t = 0
        else:
            t = Y
        C[(a, b)] = (k, t)

    for k, t in list(C.values()):
        tmp = pow(2, k, MOD) + pow(2, t, MOD) - 1
        ans = ans * tmp % MOD

    print((ans + Z - 1)%MOD)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


# 有理数クラス
class MyFraction:

    def __init__(self, a, b):
        assert b != 0, "分母が0です"

        if b < 0:
            a, b = -a, -b
        if a == 0:
            b = 1

        g = math.gcd(a, b)
        self.numerator = a // g
        self.denominator = b // g

    def __str__(self):
        return "{0}/{1}".format(self.numerator, self.denominator)


def main():
    N = NI()
    AB = defaultdict(int)
    Y, Z = 0, 0
    for i in range(N):
        a, b = NMI()
        if a == b == 0:
            Z += 1
            continue
        if b == 0:
            Y += 1
            AB["1/0"] += 1
            continue

        if str(MyFraction(a, b)) in AB:
            AB[str(MyFraction(a, b))] += 1
        else:
            AB[str(MyFraction(a, b))] = 1

    C = defaultdict(lambda: ())
    ans = 1
    for ab, k in list(AB.items()):
        a, b = ab.split("/")
        a = int(a)
        b = int(b)
        if a > 0:
            if str(MyFraction(-b, a)) in AB:
                t = AB[str(MyFraction(-b, a))]
            else:
                t = 0
        elif a < 0:
            if str(MyFraction(b, -a)) in AB:
                continue
            t = 0
        else:
            t = Y
        C[(a, b)] = (k, t)

    for k, t in list(C.values()):
        tmp = pow(2, k, MOD) + pow(2, t, MOD) - 1
        ans = ans * tmp % MOD
        
    print((ans + Z - 1)%MOD)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


# 有理数クラス
class MyFraction:

    def __init__(self, a, b):
        assert b != 0, "分母が0です"

        if b < 0:
            a, b = -a, -b
        if a == 0:
            b = 1

        g = math.gcd(a, b)
        self.numerator = a // g
        self.denominator = b // g

    def __str__(self):
        return "{0}/{1}".format(self.numerator, self.denominator)


def main():
    N = NI()
    AB = defaultdict(int)
    Y, Z = 0, 0
    for i in range(N):
        a, b = NMI()
        if a == b == 0:
            Z += 1
            continue
        if b == 0:
            Y += 1
            continue

        if str(MyFraction(a, b)) in AB:
            AB[str(MyFraction(a, b))] += 1
        else:
            AB[str(MyFraction(a, b))] = 1

    C = defaultdict(lambda: ())
    ans = 1
    for ab, k in list(AB.items()):
        a, b = ab.split("/")
        a = int(a)
        b = int(b)
        if a > 0:
            if str(MyFraction(-b, a)) in AB:
                t = AB[str(MyFraction(-b, a))]
            else:
                t = 0
        elif a < 0:
            if str(MyFraction(b, -a)) in AB:
                continue
            t = 0
        else:
            t = Y
        C[(a, b)] = (k, t)

    for k, t in list(C.values()):
        tmp = pow(2, k, MOD) + pow(2, t, MOD) - 1
        ans = ans * tmp % MOD
    print((ans + Z - 1)%MOD)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict
from collections import deque
from fractions import Fraction

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    N = NI()
    AB = defaultdict(int)
    Y, Z = 0, 0
    for i in range(N):
        a, b = NMI()
        if a == b == 0:
            Z += 1
            continue
        if b == 0:
            Y += 1
            continue

        if Fraction(a, b) in AB:
            AB[Fraction(a, b)] += 1
        else:
            AB[Fraction(a, b)] = 1

    C = defaultdict(lambda: ())
    ans = 1
    for ab, k in list(AB.items()):
        a = ab.numerator
        b = ab.denominator
        if a > 0:
            if Fraction(-b, a) in AB:
                t = AB[Fraction(-b, a)]
            else:
                t = 0
        elif a < 0:
            if Fraction(b, -a) in AB:
                continue
            t = 0
        else:
            t = Y
        C[(a, b)] = (k, t)

    for k, t in list(C.values()):
        tmp = pow(2, k, MOD) + pow(2, t, MOD) - 1
        ans = ans * tmp % MOD
    print((ans + Z - 1)%MOD)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict
from collections import deque
from fractions import Fraction

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    N = NI()
    AB = defaultdict(int)
    Y, Z = 0, 0
    for i in range(N):
        a, b = NMI()
        if a == b == 0:
            Z += 1
            continue
        if b == 0:
            Y += 1
            continue
        AB[Fraction(a, b)] += 1
    C = defaultdict(lambda: ())
    ans = 1
    for ab, k in list(AB.items()):
        a = ab.numerator
        b = ab.denominator
        if a > 0:
            t = AB[Fraction(-b, a)]
        elif a < 0:
            if Fraction(b, -a) not in AB:
                ans = ans * 2 % MOD
            continue
        else:
            t = Y
        C[(a, b)] = (k, t)

    for k, t in list(C.values()):
        tmp = pow(2, k, MOD) + pow(2, t, MOD) - 1
        ans = ans * tmp % MOD
    print((ans + Z - 1)%MOD)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import defaultdict
from collections import deque
from fractions import Fraction

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    N = NI()
    AB = defaultdict(int)
    Y, Z = 0, 0
    for i in range(N):
        a, b = NMI()
        if a == b == 0:
            Z += 1
            continue
        if b == 0:
            Y += 1
            continue
        AB[Fraction(a, b)] += 1
    print(AB)
    C = defaultdict(lambda: ())
    for ab, k in list(AB.items()):
        a = ab.numerator
        b = ab.denominator
        if a > 0:
            t = AB[Fraction(-b, a)]
        elif a < 0:
            continue
        else:
            t = Y
        C[(a, b)] = (k, t)
    print(C)
    ans = 1
    for k, t in list(C.values()):
        tmp = pow(2, k, MOD) + pow(2, t, MOD) - 1
        ans = ans * tmp % MOD
    print(ans*2 + Z - 1)
    

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
from math import gcd
from collections import Counter

N = int(input())
mod = int(1e9+7)

zero = 0
P = {}
for i in range(N):
  a,b = list(map(int, input().split()))
  if a == 0 and b == 0:
    zero += 1
    continue
  g = gcd(a,b)
  a,b = a//g, b//g
  if b < 0:
    a,b = -a,-b
  if b == 0 and a < 0:
    a,b = -a,b  
  #rot90
  rot90 = a<=0
  if rot90:
    a,b = b,-a
  #add
  if not (abs(a),b) in P:
    P[(a,b)] = [0,0]
  if not rot90 :
    P[(a,b)][0] += 1
  else:
    P[(a,b)][1] += 1
    
ans = 1
for k,v in P.items():
  #print(k,v)
  s,t = v
  wk = 1 + pow(2,s,mod) - 1 + pow(2,t,mod) - 1
  ans *= wk
  ans %= mod
  
ans += zero
print(ans - 1)

Submission status: Wrong Answer

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

N = int(input())
zero = 0
d = defaultdict(lambda: [0, 0])
for i in range(N):
    x, y = map(int, input().split())
    if x == 0 and y == 0:
        zero += 1
        continue
    g = gcd(x, y)
    x //= g
    y //= g
    if y <= 0:
        x = -x
        y = -y
    rotate = x <= 0
    if rotate:
        x, y = y, -x
        d[(x, y)][0] += 1
    else:
        d[(x, y)][1] += 1

ans = 1
for v in d.values():
    now = 1
    now += (2 ** v[0] - 1) % MOD
    now += (2 ** v[1] - 1) % MOD
    ans *= now
    ans %= MOD
print((ans - 1 + zero) % MOD)

Submission status: Wrong Answer

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

N = int(input())
zero = 0
d = defaultdict(lambda: [0, 0])
for i in range(N):
    x, y = map(int, input().split())
    if x == 0 and y == 0:
        zero += 1
        continue
    g = gcd(x, y)
    x //= g
    y //= g
    if y < 0:
        x = -x
        y = -y
    if y == 0 and x < 0:
        x = -x
    rotate = x <= 0
    if rotate:
        x, y = y, -x
        d[(x, y)][0] += 1
    else:
        d[(x, y)][1] += 1

ans = 1
for v in d.values():
    now = 1
    now += (2 ** v[0] - 1) % MOD
    now += (2 ** v[1] - 1) % MOD
    ans *= now
    ans %= MOD
print(ans - 1 + zero)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from collections import defaultdict as d
n=int(input())
m=10**9+7
s=d(lambda:[0,0])
p=-1
for i in range(n):
    a,b=map(int,input().split())
    if a==b==0:p+=1
    else:
        g=gcd(a,b)
        a=a//g
        b=b//g
        if a<0 or a==0<b:
            a,b=-a,-b
            if b<0:s[(a,-b)][1]+=1
            else:s[(a,b)][0]+=1
q=1
for i in s:
    k,l=s[i]
    q=q*(pow(k,2,m)+pow(l,2,m)-1)%m
print((q+p)%m)

Submission status: Wrong Answer

Solution code:
N=int(input())
AB=[list(map(int,input().split())) for i in range(N)]
from collections import defaultdict
d=defaultdict(int)
d2=defaultdict(int)
a0=0
b0=0
from math import gcd
for a,b in AB:
    if a==b==0:
        pass
    elif a==0:
        a0+=1
    elif b==0:
        b0+=1
    else:
        if a<0:
            a,b=-a,-b
        g=gcd(a,b)
        a,b=a//g,b//g
        if b>0:
            d[(a,b)]+=1
        else:
            d2[(-b,a)]+=1
m=10**9+7
a=1
for k,v in d.items():
    if k in d2:
        a=a*(pow(2,v,m)+pow(2,d2[k],m)-1)%m
    else:
        a=a*pow(2,v,m)%m
for k,v in d2.items():
    if k not in d:
        a=a*pow(2,v,m)%m
print((a*(pow(2,a0,m)+pow(2,b0,m)-1)-1)%m)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
from fractions import Fraction
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


MOD = 1000000007


def func(v):
    ans = 1
    # 単独
    for i in range(4):
        ans += pow(2, v[i], MOD) - 1
        ans %= MOD

    # 0と3
    if v[0] and v[3]:
        ans += (v[0] * v[3]) * pow(2, (v[0] + v[3] - 2), MOD)

    # 1と2
    if v[1] and v[2]:
        ans += (v[1] * v[2]) * pow(2, (v[1] + v[2] - 2), MOD)

    return ans % MOD


def solve():
    N = int(input())

    num_zero = 0

    d = defaultdict(list)
    for _ in range(N):
        A, B = map(int, input().split())
        if A == 0 and B == 0:
            num_zero += 1
        else:
            g = gcd(abs(A), abs(B))
            if A == 0:
                k = (0, INF)
            elif B == 0:
                k = (INF, 0)
            elif A > 0 and B > 0:
                k = (A // g, B // g)
            elif A > 0 and B < 0:
                k = (-B // g, A // g)
            elif A < 0 and B > 0:
                k = (B // g, -A // g)
            else:
                k = (-A // g, -B // g)

            if len(d[k]) == 0:
                d[k] = [0, 0, 0, 0]

            if A == 0:
                d[k][0] += 1
            elif B == 0:
                d[k][0] += 1
            if A > 0 and B > 0:
                d[k][0] += 1
            elif A > 0 and B < 0:
                d[k][1] += 1
            elif A < 0 and B > 0:
                d[k][2] += 1
            else:
                d[k][3] += 1

    ans = 1
    for k, v in d.items():
        ans *= func(v)
        ans %= MOD

    print((ans + num_zero + MOD - 1) % MOD)


def main():
    solve()


if __name__ == '__main__':
    main()