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:
#!/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][1] += 1
            elif 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():
        if k[0] == 0 or k[1] == 0:
            ans *= func(v)
        else:
            ans *= func(v) * (num_zero + 1)
        ans %= MOD

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


def main():
    solve()


if __name__ == '__main__':
    main()

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 or B == 0:
            num_zero += 1
        else:
            g = gcd(abs(A), abs(B))
            if 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 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

    if num_zero:
        ans *= (num_zero + 1)

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


def main():
    solve()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# ベクトルを既約分数にしてなおかつ方向を第一象限か第二象限に集める

from collections import defaultdict
from math import gcd
N = int(input())
MOD = 10**9 + 7
d = defaultdict(lambda: [0, 0])
zeros = 0
for _ in range(N):
    x, y = map(int, input().split())
    if x == 0 and y == 0:
        zeros += 1
    elif x == 0:
        d[(0, 0)][0] += 1
    elif y == 0:
        d[(0, 0)][1] += 1
    else:
        if y < 0:
            x = -x
            y = -y
        g = gcd(abs(x), abs(y))
        x //= g
        y //= g
        if x < 0:
            d[(y, -x)][0] += 1
        else:
            d[(x, y)][1] += 1
ans = 1
print(d)
for k, v in d.items():
    ans *= pow(2, v[0], MOD)+pow(2, v[1], MOD)-1
    ans %= MOD
ans = (ans + zeros - 1) % MOD  # 各ベクトル対の組から一つも選ばないパターンを引いてる
print(ans)

Submission status: Wrong Answer

Solution code:

import sys, io, os, re
import bisect
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor, ceil
from copy import copy, deepcopy
from collections import deque, defaultdict
from fractions import gcd
from functools import reduce

def array1(n): return [0] * n
def array2(n, m): return [[0] * m for x in range(n)]
def array3(n, m, l): return [[[0] * l for y in xrange(m)] for x in xrange(n)]

n1 = lambda: int(sys.stdin.readline().strip())
nn = lambda: list(map(int, sys.stdin.readline().strip().split()))
f1 = lambda: float(sys.stdin.readline().strip())
fn = lambda: list(map(float, sys.stdin.readline().strip().split()))
s1 = lambda: sys.stdin.readline().strip()
sn = lambda: list(sys.stdin.readline().strip().split())
nl = lambda n: [n1() for _ in range(n)]
fl = lambda n: [f1() for _ in range(n)]
sl = lambda n: [s1() for _ in range(n)]
nm = lambda n: [nn() for _ in range(n)]
fm = lambda n: [fn() for _ in range(n)]
sm = lambda n: [sn() for _ in range(n)]

mod = 1000000007

N = n1()
(A, B) = ([], [])
for i in range(N):
    a, b = nn()
    g = gcd(a, b)
    if g != 0: a //= g; b //=g
    A.append(a)
    B.append(b)

d = defaultdict(int)
for i in range(N):
    d[(A[i], B[i])] += 1

ans = 1

n = 0
if (0, 0) in d:
    n = d.pop((0, 0))

while len(d) > 0:
    #print(d, ans)
    (x, y), n1 = d.popitem()
    if y < 0: x *= -1; y *= -1

    n2 = 0
    if (y, -x) in d: n2 += d.pop((y, -x))
    if (-y, x) in d: n2 += d.pop((-y, x))

    ans = (ans * ((pow(2,n1,mod) -1 + pow(2,n2,mod) - 1) % mod + 1)) % mod

print(ans-1+n)

Submission status: Wrong Answer

Solution code:

import sys, io, os, re
import bisect
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor, ceil
from copy import copy, deepcopy
from collections import deque, defaultdict
from fractions import gcd
from functools import reduce

def array1(n): return [0] * n
def array2(n, m): return [[0] * m for x in range(n)]
def array3(n, m, l): return [[[0] * l for y in xrange(m)] for x in xrange(n)]

n1 = lambda: int(sys.stdin.readline().strip())
nn = lambda: list(map(int, sys.stdin.readline().strip().split()))
f1 = lambda: float(sys.stdin.readline().strip())
fn = lambda: list(map(float, sys.stdin.readline().strip().split()))
s1 = lambda: sys.stdin.readline().strip()
sn = lambda: list(sys.stdin.readline().strip().split())
nl = lambda n: [n1() for _ in range(n)]
fl = lambda n: [f1() for _ in range(n)]
sl = lambda n: [s1() for _ in range(n)]
nm = lambda n: [nn() for _ in range(n)]
fm = lambda n: [fn() for _ in range(n)]
sm = lambda n: [sn() for _ in range(n)]

mod = 1000000007

N = n1()
(A, B) = ([], [])
for i in range(N):
    a, b = nn()
    g = gcd(a, b)
    if g != 0: a //= g; b //=g
    A.append(a)
    B.append(b)

d = defaultdict(int)
for i in range(N):
    d[(A[i], B[i])] += 1

ans = 1
while len(d) > 0:
    #print(d, ans)
    (x, y), n1 = d.popitem()
    #d.pop((x, y))
    if y < 0: x *= -1; y *= -1

    n2 = 0
    if (y, -x) in d: n2 += d.pop((y, -x))
    if (-y, x) in d: n2 += d.pop((-y, x))

    ans = (ans * ((pow(2,n1,mod) -1 + pow(2,n2,mod) - 1) % mod + 1)) % mod

print(ans-1)

Submission status: Wrong Answer

Solution code:
import sys, io, os, re
import bisect
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor, ceil
from copy import copy, deepcopy
from collections import deque, defaultdict
from fractions import gcd
from functools import reduce

def array1(n): return [0] * n
def array2(n, m): return [[0] * m for x in range(n)]
def array3(n, m, l): return [[[0] * l for y in xrange(m)] for x in xrange(n)]

n1 = lambda: int(sys.stdin.readline().strip())
nn = lambda: list(map(int, sys.stdin.readline().strip().split()))
f1 = lambda: float(sys.stdin.readline().strip())
fn = lambda: list(map(float, sys.stdin.readline().strip().split()))
s1 = lambda: sys.stdin.readline().strip()
sn = lambda: list(sys.stdin.readline().strip().split())
nl = lambda n: [n1() for _ in range(n)]
fl = lambda n: [f1() for _ in range(n)]
sl = lambda n: [s1() for _ in range(n)]
nm = lambda n: [nn() for _ in range(n)]
fm = lambda n: [fn() for _ in range(n)]
sm = lambda n: [sn() for _ in range(n)]

mod = 1000000007

N = n1()
(A, B) = ([], [])
for i in range(N):
    a, b = nn()
    #if a < 0: a *= -1; b *= -1
    g = gcd(a, b)
    #if g < 0: g *= -1
    if g != 0: a //= g; b //=g
    A.append(a)
    B.append(b)

d = defaultdict(int)
for i in range(N):
    d[(A[i], B[i])] += 1

ans = 1
while len(d) > 0:
    #print(d, ans)
    (x, y), n1 = list(d.items())[0]
    d.pop((x, y))
    if y < 0: x *= -1; y *= -1

    n2 = 0
    if (y, -x) in d: n2 += d.pop((y, -x))
    if (-y, x) in d: n2 += d.pop((-y, x))

    ans = (ans * ((pow(2,n1,mod) -1 + pow(2,n2,mod) - 1) % mod + 1)) % mod

print(ans-1)

Submission status: Wrong Answer

Solution code:
import sys, io, os, re
import bisect
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor, ceil
from copy import copy, deepcopy
from collections import deque, defaultdict
from fractions import gcd
from functools import reduce

def array1(n): return [0] * n
def array2(n, m): return [[0] * m for x in range(n)]
def array3(n, m, l): return [[[0] * l for y in xrange(m)] for x in xrange(n)]

n1 = lambda: int(sys.stdin.readline().strip())
nn = lambda: list(map(int, sys.stdin.readline().strip().split()))
f1 = lambda: float(sys.stdin.readline().strip())
fn = lambda: list(map(float, sys.stdin.readline().strip().split()))
s1 = lambda: sys.stdin.readline().strip()
sn = lambda: list(sys.stdin.readline().strip().split())
nl = lambda n: [n1() for _ in range(n)]
fl = lambda n: [f1() for _ in range(n)]
sl = lambda n: [s1() for _ in range(n)]
nm = lambda n: [nn() for _ in range(n)]
fm = lambda n: [fn() for _ in range(n)]
sm = lambda n: [sn() for _ in range(n)]

mod = 1000000007

N = n1()
(A, B) = ([], [])
for i in range(N):
    a, b = nn()
    if a < 0: a *= -1; b *= -1
    g = gcd(a, b)
    if g < 0: g *= -1
    if g != 0: a //= g; b //=g
    A.append(a)
    B.append(b)

d = defaultdict(int)
for i in range(N):
    d[(A[i], B[i])] += 1

ans = 1
while len(d) > 0:
    #print(d, ans)
    (x, y), n1 = list(d.items())[0]
    d.pop((x, y))
    if y < 0: x *= -1; y *= -1
    if (y, -x) in d:
        n2 = d.pop((y, -x))
        ans = (ans * ((2**n1 -1 + 2**n2 - 1) % mod + 1)) % mod
    else:
        ans = (ans * (2**n1 % mod)) % mod

print(ans-1)

Submission status: Wrong Answer

Solution code:
n=int(input(""))
lista=[]
nn=0

listb=[]
for i in range(n):
    listin=input("").split(" ")
    lista+=[[int(listin[0]),int(listin[1])]]
    if( lista[i][0]==0 and lista[i][1]==0):
        nn+=1
        listb+=[1]
    else:
        listb+=[0]
k=0
n-=nn

if (n==0):
    print(0)
else:
    s=0
    t=0
    d=n
    ss=1
    while(k<n):
        
        t=0
        if(listb[k]==1):
            k+=1
            continue
        s=1
        listb[k]=1
        for i in range(k+1,n):
            if(lista[k][0]*lista[i][0]+lista[k][1]*lista[i][1]==0):
                listb[i]=1
                t+=1
            elif(lista[k][0]*lista[i][1]==lista[k][1]*lista[i][0]):
                listb[i]=1
                s+=1
        
        
        
        if(t==0):
            k+=1
            continue
        d=d-s-t
        
        ss*=(2**s+2**t-1)
        ss%=1000000007
     
        k+=1
    sss=1
    for i in range(d):
        sss*=2
        if(i%10==0):
            sss%=1000000007
    
    ss*=sss
    ss%=1000000007
    ss-=1
    if(ss==-1):
        ss=1000000006
    print(ss)

Submission status: Wrong Answer

Solution code:
n=int(input(""))
lista=[]
nn=0

listb=[]
for i in range(n):
    listin=input("").split(" ")
    lista+=[[int(listin[0]),int(listin[1])]]
    if( lista[i][0]==0 and lista[i][1]==0):
        nn+=1
        listb+=[1]
    else:
        listb+=[0]
k=0
n-=nn
print(lista)
if (n==0):
    print(0)
else:
    s=0
    t=0
    d=n
    ss=1
    while(k<n):
        
        t=0
        if(listb[k]==1):
            k+=1
            continue
        s=1
        listb[k]=1
        for i in range(k+1,n):
            if(lista[k][0]*lista[i][0]+lista[k][1]*lista[i][1]==0):
                listb[i]=1
                t+=1
            elif(lista[k][0]*lista[i][1]==lista[k][1]*lista[i][0]):
                listb[i]=1
                s+=1
        
        
        
        if(t==0):
            k+=1
            continue
        d=d-s-t
        
        ss*=(2**s+2**t)
        ss%=1000000007
     
        k+=1
    for i in range(d):
        ss*=2
        if(i%10==0):
            ss%=1000000007
    ss%=1000000007
    ss-=1
    if(ss==-1):
        ss=1000000006
    print(ss)

Submission status: Wrong Answer

Solution code:
n=int(input(""))
lista=[]
nn=0

listb=[]
for i in range(n):
    listin=input("").split(" ")
    lista+=[[int(listin[0]),int(listin[1])]]
    if( lista[i][0]==0 and lista[i][1]==0):
        nn+=1
        listb+=[1]
    else:
        listb+=[0]
k=0
n-=nn
if (n==0):
    print(0)
else:
    s=0
    t=0
    d=n
    ss=1
    while(k<d):
        
        t=0
        if(listb[k]==1):
            break
        s=1
        for i in range(k,n):
            if(lista[k][0]*lista[i][0]+lista[k][1]*lista[i][1]==0):
                listb[k]=1
                t+=1
            elif(lista[k][0]*lista[i][1]==lista[k][1]*lista[i][0]):
                listb[k]=1
                s+=1
        
        d=d-s-t
        if(t==0):
            break
        
        ss*=(2**s+2**t)
        ss%=1000000007
     
        k+=1
    for i in range(d):
        ss*=2
        if(i%10==0):
            ss%=1000000007
    ss%=1000000007
    ss-=1
    if(ss==-1):
        ss=1000000006
    print(ss)

Submission status: Wrong Answer

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    import fractions
    import math
    from collections import Counter
    n = int(readline())
    counter = Counter()
    a0, b0 = 0, 0
    lonely = 0

    for i in range(n):
        a, b = map(int, readline().split())
        if a == 0 and b == 0:
            lonely += 1
        elif a == 0:
            a0 += 1
        elif b == 0:
            b0 += 1
        else:
            fr = fractions.Fraction(a, b)
            counter[(fr.numerator, fr.denominator)] += 1

    ans = 1  # 最後に
    keys = list(counter.keys())
    for key in keys:
        nm1, dn1 = key[0], key[1]
        cnt1 = counter[(nm1, dn1)]
        nm2, dn2 = -(nm1 // abs(nm1)) * dn1, abs(nm1)
        cnt2 = counter[(nm2, dn2)]
        ans = ans * ((pow(2, cnt1, MOD) - 1) + (pow(2, cnt2, MOD) - 1) + 1)
        ans %= MOD
        counter[(nm1, dn1)] = 0
        counter[(nm2, dn2)] = 0

    ans *= pow(2, a0, MOD)
    ans %= MOD
    ans *= pow(2, b0, MOD)
    ans %= MOD
    ans += lonely
    ans -= 1
    ans %= MOD

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    import fractions
    import math
    from collections import Counter
    n = int(readline())
    counter = Counter()
    a0, b0 = 0, 0

    for i in range(n):
        a, b = map(int, readline().split())
        if a == 0 and b == 0:
            n -= 1
        elif a == 0:
            a0 += 1
        elif b == 0:
            b0 += 1
        else:
            fr = fractions.Fraction(a, b)
            counter[(fr.numerator, fr.denominator)] += 1

    ans = 1  # 最後に
    keys = list(counter.keys())
    for key in keys:
        nm1, dn1 = key[0], key[1]
        cnt1 = counter[(nm1, dn1)]
        nm2, dn2 = -(nm1 // abs(nm1)) * dn1, abs(nm1)
        cnt2 = counter[(nm2, dn2)]
        ans = ans * ((pow(2, cnt1, MOD) - 1) + (pow(2, cnt2, MOD) - 1) + 1)
        ans %= MOD
        counter[(nm1, dn1)] = 0
        counter[(nm2, dn2)] = 0

    ans *= pow(2, a0, MOD)
    ans %= MOD
    ans *= pow(2, b0, MOD)
    ans %= MOD
    ans -= 1
    ans %= MOD

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
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)
            cA[x] += 1
            if x not in used and y % P 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()

Submission status: Wrong Answer

Solution code:
MOD = 10**9 + 7
P = 998244353


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


def main():
    from collections import Counter
    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()

Submission status: Wrong Answer

Solution code:
MOD = 10**9 + 7
P = 998244353


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()

Submission status: Wrong Answer

Solution code:
MOD = 10**9 + 7
P = 998244353


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)))
            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()

Submission status: Wrong Answer

Solution code:
MOD = 10**9 + 7
P = 998244353


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)))
            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()

Submission status: Wrong Answer

Solution code:
MOD = 10**9 + 7
P = 998244353


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


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)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

N = int(input().strip())
AB_list = [list(map(int, input().rstrip().split())) for i in range(N)]

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

#-----
fish = {}
cnt_A0_B0 = 0
cnt_A0_Bj = 0
cnt_Ai_B0 = 0
mod = 10**9 + 7


for a,b in AB_list:
    if a == b == 0:
        cnt_A0_B0 += 1
    
    elif (a == 0):
        cnt_A0_Bj += 1
    
    elif (b == 0):
        cnt_Ai_B0 += 1
    
    else:
        g = gcd( abs(a) , abs(b) )
        
        a //= g
        b //= g
        
        if a < 0:
            a *= (-1)
            b *= (-1)
        
        fish.setdefault( (a,b) , 0 )
        fish[ (a,b) ] += 1


ans = 1
used = set()

# multiple the number of pattern, where fish (A != 0) and (B != 0)
for key_a, key_b in fish:
    if (key_a, key_b) not in used:
        
        if key_b >= 0:
            key_reverse = (key_b, -key_a)
        else:
            key_reverse = (-key_b, key_a)
        
        if key_reverse in fish:
            ans *= ( (2**fish[(key_a, key_b)] - 1) + (2**fish[key_reverse] - 1) + 1 ) % mod
            ans %= mod
            
            used.add( key_reverse )
        
        else:
            ans *= ( 2**fish[(key_a, key_b)] ) % mod
            ans %= mod


# multiple the number of pattern, where fish A=0 or B=0
ans *= ( (2**cnt_A0_Bj - 1) + (2**cnt_Ai_B0 - 1) + 1 ) % mod
ans %= mod

# Add the number of pattern, where fish (A,B)=(0,0)
ans += cnt_A0_B0
ans %= mod

# Minus the number of pattern, where no fish selected
ans -= 1

print(ans)

Submission status: Wrong Answer

Solution code:
from math import gcd
MOD = 1000_000_007

N = int(input())

Fish = {}
zeros = 0

for i in range(N):
  A, B = map(int,input().split()) 
  if A == 0 and B == 0:
    zeros += 1
    continue
  
  G = gcd(abs(A), abs(B))
  A, B = A // G, B // G
  if A < 0:
    A *= -1
    B *= -1
  elif A == 0:
    B = 1
    
  if (A, B) not in Fish:
    Fish[(A, B)] = 1
  else:
    Fish[(A, B)] += 1

#print(Fish)
done_set = set()

ans = 1
for (a, b) in Fish.keys():
  #print(a,b)
  if b > 0:
    c = b
    d = -a
  elif b == 0:
    c = 0
    d = 1
  else: 
    c, d = -b, a
  
  #print(done_set)
  #print((a,b), (c,d), done_set)
  if (a, b) in done_set or (c, d) in done_set: 
    continue
  #print((a,b), Fish[(a,b)])
  #print((c,d), Fish[(c,d)])
  if (c, d) not in Fish.keys():
    
    ans *= pow(2, Fish[(a,b)], MOD)
  else:
    ans *= (1 + (pow(2, Fish[(a,b)], MOD)-1) + (pow(2, Fish[(c,d)], MOD)-1))  
    done_set.add((c,d))
  ans %= MOD
  
  #print(done_set, ans)
  done_set.add((a,b))
  
ans += pow(2, zeros, MOD)
ans -= 2
ans %= MOD
#print(zeros)
print(ans)

Submission status: Wrong Answer

Solution code:
from math import gcd
MOD = 1000_000_007

N = int(input())

Fish = {}
zeros = 0

for i in range(N):
  A, B = map(int,input().split()) 
  if A == 0 and B == 0:
    zeros += 1
    break
  
  G = gcd(abs(A), abs(B))
  A, B = A // G, B // G
  if A < 0:
    A *= -1
    B *= -1
  elif A == 0:
    B = 1
    
  if (A, B) not in Fish:
    Fish[(A, B)] = 1
  else:
    Fish[(A, B)] += 1

#print(Fish)
done_set = set()

ans = 1
for (a, b) in Fish.keys():
  #print(a,b)
  if b > 0:
    c = b
    d = -a
  elif b == 0:
    c = 0
    d = 1
  else: 
    c, d = -b, a
  
  #print(done_set)
  #print((a,b), (c,d), done_set)
  if (a, b) in done_set or (c, d) in done_set: 
    continue
  #print((a,b), Fish[(a,b)])
  #print((c,d), Fish[(c,d)])
  if (c, d) not in Fish.keys():
    
    ans *= pow(2, Fish[(a,b)], MOD)
  else:
    ans *= (1 + (pow(2, Fish[(a,b)], MOD)-1) + (pow(2, Fish[(c,d)], MOD)-1))  
    done_set.add((c,d))
  ans %= MOD
  
  #print(done_set, ans)
  done_set.add((a,b))
  
ans += pow(2, zeros, MOD)
ans -= 2
ans %= MOD

print(ans)

Submission status: Wrong Answer

Solution code:
from math import gcd
MOD = 1000_000_007

N = int(input())

Fish = {}
zeros = 0

for i in range(N):
  A, B = map(int,input().split())
  G = gcd(abs(A), abs(B))
  if A == 0 and B == 0:
    zeros += 1
    break
  A, B = A // G, B // G
  if A < 0:
    A *= -1
    B *= -1
  elif A == 0:
    B = 1
    
  if (A, B) not in Fish:
    Fish[(A, B)] = 1
  else:
    Fish[(A, B)] += 1

#print(Fish)
done_set = set()

ans = 1
for (a, b) in Fish.keys():
  #print(a,b)
  if b > 0:
    c = b
    d = -a
  elif b == 0:
    c = 1
    d = 0
  else: 
    c, d = -b, a
  
  #print(done_set)
  #print((a,b), (c,d), done_set)
  if (a, b) in done_set or (c, d) in done_set: 
    continue
  #print(a,b) 
  #print((a,b), Fish[(a,b)])
  if (c, d) not in Fish.keys():
    
    ans *= pow(2, Fish[(a,b)], MOD)
  else:
    ans *= (1 + (pow(2, Fish[(a,b)], MOD)-1) + (pow(2, Fish[(c,d)], MOD)-1))  
    done_set.add((c,d))
  ans %= MOD
  
  #print(done_set, ans)
  done_set.add((a,b))
  
ans += pow(2, zeros, MOD)
ans -= 2
ans %= MOD

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from math import gcd


def main():
    mod = 10 ** 9 + 7
    worst_iwashi_count = 0
    ans = 1
    d = defaultdict(int)
    N = int(input())
    for _ in range(N):
        a, b = map(int, input().split())
        if a == 0 and b == 0:
            worst_iwashi_count += 1
        elif a == 0:
            d[(0, -1)] += 1
        elif b == 0:
            d[(1, 0)] += 1
        else:
            g = gcd(abs(a), abs(b))
            if a * b > 0:
                d[(abs(a // g), abs(b // g))] += 1
            else:
                d[(abs(a // g), -abs(b // g))] += 1
    done_set = set()
    for a, b in list(d):
        if (a, b) in done_set:
            continue
        x = d[(a, b)]
        done_set.add((a, b))
        if b >= 0:
            y = d[(b, -a)]
            done_set.add((b, -a))
        else:
            y = d[(-b, a)]
            done_set.add((-b, a))
        ans *= 2 ** x + 2 ** y - 1
        ans %= mod
    ans += worst_iwashi_count
    print(ans % mod)


if __name__ == '__main__':
    main()