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

import sys
sys.setrecursionlimit(300000)

MOD = 1000000007  # type: int

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

def solve(N: int, A: "List[int]", B: "List[int]"):
    s = {}
    for i in range(N):
        if A[i] == 0 and B[i] == 0:
            a, b = 0, 0
        elif A[i] == 0:
            a, b = 0, 1
        elif B[i] == 0:
            a, b = 1, 0
        else:
            g = gcd(A[i], B[i])
            a, b = A[i] // g, B[i] // g
        k = (a, b)
        if not k in s:
            s[k] = 0
        s[k] += 1
    count = 0
    checked = set()
    cums = []
    #print(s)
    for (a, b), cnt in s.items():
        if (a, b) in checked:
            continue
        checked.add((a, b))
        tmp = 0
        if a == 0 and b == 0:
            cum = cnt + 1
            cums.append(cum)
            count += cnt + tmp
        if (-b, a) in s and (-b, a) not in checked:
            tmp += s[(-b, a)]
            checked.add((-b, a))
        if (b, -a) in s and (b, -a) not in checked:
            tmp += s[(b, -a)]
            checked.add((b, -a))
        if tmp > 0:
            cum = pow(2, cnt, MOD) + pow(2, tmp, MOD) - 1
            cum %= MOD
            cums.append(cum)
            count += cnt + tmp
    #print(cums, count)
    ret = pow(2, (N - count), MOD)
    for cum in cums:
        ret *= cum
        ret %= MOD
    ret -= 1
    ret %= MOD
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]"
    B = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, A, B)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def gcd(a, b):
    while b: a, b = b, a % b
    return a

def main():
    md = 1000000007
    n = II()
    cnt = {}
    cnt[(0, 0)] = [0, 0]
    zero = 0
    for _ in range(n):
        a, b = MI()
        if a * b == 0:
            if a == b == 0:
                zero += 1
            elif a == 0:
                cnt[(0, 0)][0] += 1
            else:
                cnt[(0, 0)][1] += 1
            continue
        par = a * b > 0
        a = abs(a)
        b = abs(b)
        g = gcd(a, b)
        a //= g
        b //= g
        if par:
            cnt.setdefault((a, b), [0, 0])
            cnt[(a, b)][1] += 1
        else:
            cnt.setdefault((b, a), [0, 0])
            cnt[(b, a)][0] += 1
    # print(cnt)
    ans = 1
    for x, y in cnt.values():
        cur = pow(2, x, md) + pow(2, y, md) - 1
        ans = ans * cur % md
    if zero: ans += 1
    ans = (ans - 1) % md
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import bisect
import collections
import sys
import math
from fractions import Fraction

sys.setrecursionlimit(1000000)
ACMOD = 1000000007
INF = 1 << 62

MOD = 1000000007  # type: int


def solve(N: int, A: "List[int]", B: "List[int]"):
    ab = collections.defaultdict(lambda: [0, 0])  # [posi][nega]
    zeros = 0
    for i in range(N):
        if A[i] == B[i] == 0:
            zeros += 1
        elif A[i] == 0:
            ab[0][1] += 1
        elif A[i] * B[i] >= 0:
            ab[(abs(B[i]) / abs(A[i]))][0] += 1
        else:
            ab[(abs(A[i]) / abs(B[i]))][1] += 1

    # check B[i] ==0
    ans = 1 + zeros
    for x, y in ab.values():
        pattern = 1  # not select
        pattern += 2 ** x - 1
        pattern += 2 ** y - 1
        ans = ans * pattern % MOD
    print((ans - 1) % MOD)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]"
    B = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, A, B)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from math import gcd
from collections import Counter
n=int(input())

iw=[]
for i in range(n):
    ab=list(map(int, input().split( )))
    iw.append(ab)

for i in range(n):
    ai,bi=iw[i]
    if ai and bi:##互いに素にする
        g=gcd(ai,bi)
        iw[i][0]//=g;iw[i][1]//=g
    else:#どちらか0なら残りを1か0にする
        if ai:#biがゼロでaiが非ゼロ
            iw[i][0]=1
        elif bi:#aiがゼロでbiが非ゼロ
            iw[i][1]=1
    if bi<0:#biは正に設定
        iw[i][0]*=-1;iw[i][1]*=-1
    if bi==0 and ai<0:#biがゼロならaiは正かゼロ
        iw[i][0]*=-1
iw = [tuple(iwi) for iwi in iw]
C=Counter(iw)
ans=1
mod=10**9+7
#print(C)
#ai bi=0,0は別に処理が要る
tmp=0
if (0,0) in C:
    tmp= C[(0,0)]
    C.pop((0,0))
for ai,bi in C:
    if ai>=0 and C[(ai,bi)]>0:
        if (-bi,ai) in C and C[(-bi,ai)]>0:
            ans*=(pow(2,C[(-bi,ai)],mod)+pow(2,C[(ai,bi)],mod)-1)
            ans%=mod
            C[(-bi,ai)]=-1
        else:
            ans*= pow(2,C[(ai,bi)],mod)
            ans%=mod
    elif C[(ai,bi)]>0:
        if (bi,-ai) in C and C[(bi,-ai)]>0:
            ans*=(pow(2,C[(bi,-ai)],mod)+pow(2,C[(ai,bi)],mod)-1)
            ans%=mod
            C[(bi,-ai)]=-1
        else:
            ans*= pow(2,C[(ai,bi)],mod)
            ans%=mod
    
    #print((ai,bi),C[(ai,bi)],ans)
print((ans+tmp-1)%mod)

Submission status: Wrong Answer

Solution code:
n=int(input())
ablist=[]
slist=[]
zeros=[0,0,0]

for i in range(n):
    a, b = map(int,input().split())
    if a==0:
        if b==0:
            zeros[2]+=1
        else:
            zeros[1]+=1
    else:
        if b==0:
            zeros[0]+=1
        else:
            if a*b>0:
                slist.append([a/b, 1])
            else:
                slist.append([b/(-a), -1])
                #slist.append([abs(a/b), int(abs(a*b)/(a*b))])

slist=sorted(slist)
#print(slist)

zerok=2**(zeros[0])-1 + 2**(zeros[1])-1 + 1
#print(zerok)

mae=[0, 0]
onaji=[1, 0]

answer=1
#print(slist)

for sl in slist:
    if sl[0]==mae[0]:
        if sl[1]==mae[1]:
            onaji[0]+=1
        else:
            onaji[1]+=1
    else:
        if mae!=[0, 0]:
            answer*=(2**onaji[0]+2**onaji[1]-1)
            answer%=1000000007
            onaji=[1, 0]
    mae=sl
    #print(answer)

answer*=(2**onaji[0]+2**onaji[1]-1)
answer%=1000000007

#print(answer)

answer*=zerok
answer+=zeros[2]

print((answer-1)%1000000007)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

Q = 10**9+7

from collections import defaultdict
from math import gcd
def main():
    N = int( input())
    AB = [ tuple( map( int, input().split())) for _ in range(N)]
    d = defaultdict( int)
    for a, b in AB:
        if a == 0 and b == 0:
            d[(0,0)] += 1
            continue
        g = gcd(a, b)
        a //= g
        b //= g
        if a == 0:
            d[(0,1)] += 1
            continue
        if b == 0:
            d[(1,0)] += 1
            continue
        if a < 0:
            a = -a
            b = -b
        d[(a,b)] += 1
    ans = 1
    K = list( d.keys())
    for k in K:
        # print(ans)
        a, b = k
        if a == 0 and b == 0:
            continue
        if a*b == 0:
            if a > 0:
                ans *= (pow(2,d[(1,0)],Q) + pow(2,d[(0,1)],Q) -1)%Q
                ans %= Q
                continue
        if b > 0 and d[(a,b)] > 0 and d[(b,-a)] > 0:
            ans *= (pow(2,d[(a,b)],Q) + pow(2,d[(b,-a)],Q) - 1)%Q
            ans %= Q
            continue
        if b < 0 and d[(a,b)] > 0 and d[(-b,a)] > 0:
            continue
        ans *= pow(2,d[(a,b)],Q)
        ans %= Q
    
    ans -= 1
    ans += d[(0,0)]
    ans %= Q
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def examA():
    S = {0:"pon",1:"pon",2:"hon",3:"bon",4:"hon",5:"hon",6:"pon",7:"hon",8:"pon",9:"hon"}
    N = SI()
    ans = S[int(N[-1])]
    print(ans)
    return

def examB():
    K = I()
    S = SI()
    N = len(S)
    if N<=K:
        ans = S
    else:
        ans = S[:K]+"..."
    print(ans)
    return

def examC():
    A, B, H, M = LI()
    a = abs(H*30 - M*5.5)
    deg = min(360-a,a)*math.pi/180
    #print(deg)
    ans = (A**2 + B**2 - 2*A*B*math.cos(deg))**(0.5)
    print(ans)
    return

def examD():

    N, M = LI()
    V = [[]for _ in range(N)]
    for _ in range(M):
        a, b = LI()
        a -= 1; b -= 1
        V[a].append(b)
        V[b].append(a)

    ans = [-1]*N

    def bfs(n, e, fordfs):
        # 点の数、スタートの点、有向グラフ
        W = [-1] * n
        # 各点の状態量、最短距離とか,見たかどうかとか
        W[e] = 0
        que = deque()
        que.append(e)
        while que:
            now = que.popleft()
            nowW = W[now]
            for ne in fordfs[now]:
                if W[ne] == -1:
                    W[ne] = now
                    que.append(ne)
        return W
    ans = bfs(N,0,V)
    for a in ans:
        if a==-1:
            print("No")
            return
    print("Yes")
    for v in ans[1:]:
        print(v+1)
    return

def examE():
    def gcd(x, y):
        if y == 0:
            return x
        while (y != 0):
            x, y = y, x % y
        return x
    N = I()
    D = defaultdict(int)
    for i in range(N):
        A = LI()
        if A[0]==0 and A[1]==0:
            continue
        if A[0]<0 and A[1]<0:
            A = [-A[0],-A[1]]
        if A[0]<0:
            k = gcd(-A[0],A[1])
            V = [A[0] // k, A[1] // k]
        elif A[1]<0:
            k = gcd(A[0],-A[1])
            V = [A[0] // k, A[1] // k]
        else:
            k = gcd(A[0],A[1])
            V = [A[0]//k,A[1]//k]
        D[(V[0], V[1])] += 1
    ans = 1
    #print(D)
    C = deepcopy(D)
    for (a,b),d in C.items():
        if D[(a,b)]==0:
            continue
        if D[(-b,a)]>0:
            ans *= (pow(2,d,mod)-1 + pow(2,D[(-b,a)])-1 + 1)
            D[(-b,a)] = 0
        elif D[(b,-a)]>0:
            ans *= (pow(2,d,mod)-1 + pow(2,D[(b,-a)])-1 + 1)
            D[(b,-a)] = 0
        else:
            ans *= pow(2,d,mod)
        ans %= mod
        #print(ans,a,b,d)
    ans = (ans+mod-1)%mod
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examE()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    n = II()
    ab = LIR(n)
    par = [i for i in range(n)]
    def root(x):
        if par[x] == x:
            return x
        par[x] = root(par[x])
        return par[x]
    def unite(a, b):
        a = root(a)
        b = root(b)
        if a > b: a, b = b, a
        par[b] = a
        return a
    d = defaultdict(int)
    d2 = defaultdict(int)
    d3 = defaultdict(int)
    for a, b in ab:
        if a == 0 or b == 0:
            d[0] += 1
            d2[0] += 1
        else:
            if a / b > 0:
                d[a / b] += 1
                d3[a / b] += 1
            else:
                d2[-b / a] += 1
                d3[-b / a] += 1
    ans = 1
    if d[0] != 0:
        ans *= d[0] + 1
    for k in d3.keys():
        if k != 0:
            ans *= (2 ** d[k] + 2 ** d2[k] - 1)
            ans %= mod
    ans -= 1
    print(ans % mod)
    return


#main
if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
from math import gcd
n = int(input())
ab = {}
ans = 0
mod = 10 ** 9 + 7


def go(a, b):
    if a == 0 and b == 0:
        return 0, 0
    elif a == 0:
        return 0, 1
    elif b == 0:
        return 1, 0
    c = gcd(a, b)
    a, b = a // c, b // c
    if a < 0:
        a *= - 1
        b *= - 1
    return a, b


def la(a, b):
    r = max((a, b), go(b, -a))
    if r == (a, b):
        return r, 0
    else:
        return r, 1


zero = 0
for i in range(n):
    a, b = [int(i) for i in input().split()]
    a, b = go(a, b)
    if a == b == 0:
        zero += 1
    else:
        l, ind = la(a, b)
        if l in ab:
            ab[l][ind] += 1
        else:
            ab[l] = [0, 0]
            ab[l][ind] += 1
ans = 1
for i in ab:
    ans *= pow(2, ab[i][0], mod) + pow(2, ab[i][1], mod)-1
    ans %= mod
print(ans + zero-1)

Submission status: Wrong Answer

Solution code:
from math import gcd


MOD = 10**9 + 7

n = int(input())

cnt = {}

zero_cnt = 0
for i in range(n):
    a, b = map(int, input().split())
    if (a,b) == (0,0):
        zero_cnt += 1
        continue
    g = gcd(abs(a), abs(b))
    a /= g
    b /= g
    rotate = 0
    while not (a >= 0 and b > 0):
        a,b = -b,a
        rotate += 1
    if (a,b) not in cnt:
        cnt[(a,b)] = [0,0]

    cnt[(a,b)][rotate % 2] += 1

ans = 1
    
for key in cnt:
    A, B = cnt[key]
    ans *= 1 + pow(2, A, MOD) - 1 + pow(2, B, MOD) - 1
    ans %= MOD

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

Q = 10**9+7

from collections import defaultdict
from math import gcd
def main():
    N = int( input())
    AB = [ tuple( map( int, input().split())) for _ in range(N)]
    d = defaultdict( int)
    for a, b in AB:
        if a == 0 and b == 0:
            d[(0,0)] += 1
            continue
        g = gcd(a, b)
        a //= g
        b //= g
        if a == 0:
            d[(0,1)] += 1
            continue
        if b == 0:
            d[(1,0)] += 1
        if a < 0:
            a = -a
            b = -b
        d[(a,b)] += 1
    ans = 1
    K = list( d.keys())
    for k in K:
        # print(ans)
        a, b = k
        if a == 0 and b == 0:
            continue
        if a*b == 0:
            if a > 0:
                ans *= (pow(2,d[(1,0)],Q) + pow(2,d[(0,1)],Q) -1)%Q
                ans %= Q
                continue
        if b > 0 and d[(a,b)] > 0 and d[(b,-a)] > 0:
            ans *= (pow(2,d[(a,b)],Q) + pow(2,d[(b,-a)],Q) - 1)%Q
            ans %= Q
            continue
        if b < 0 and d[(a,b)] > 0 and d[(-b,a)] > 0:
            continue
        ans *= pow(2,d[(a,b)],Q)
        ans %= Q
    
    ans -= 1
    ans += d[(0,0)]
    ans %= Q
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]
def init_dp1(init, N): return [init for _ in range(N)]
def init_dp2(init, N, M): return [[init for _ in range(M)] for _ in range(N)]


def main():
    N = int(input())
    A = read_lists(N)    

    K = {}
    for a in A:
        if a[0] == 0:
            r = "I"
        else:
            r = a[1] / a[0]
        K[r] = K.setdefault(r, 0) + 1

    S = set()
    res = 1
    for k, v in K.items():
        if k in S:
            continue
        S.add(k)

        t = 0 if k == "I" else "I" if k == 0 else -1 / k

        if t in K:
            S.add(t)
            v2 = K[t]
            res *= (pow(2, v, mod) + pow(2, v2, mod) - 1)
            res %= mod
        else:
            res *= 2
            res %= mod

    print((res - 1) % mod)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

mod = 10**9 + 7
def gcd(x, y):
    x = abs(x); y = abs(y)
    while y:
        x, y = y, x%y
    return x

azr = bzr = czr = 0
n = ni()
d = dict()
for _ in range(n):
    a, b = nm()
    if a < 0:
        a = -a
        b = -b
    if a == b == 0:
        czr += 1
    elif a == 0 :
        azr += 1
    elif b == 0:
        bzr += 1
    else:
        g = gcd(a, b)
        a //= g
        b //= g
    if (a, b) not in d:
        d[(a, b)] = 0
    d[(a, b)] += 1

ans = (pow(2, azr, mod) + pow(2, bzr, mod) - 1) % mod
for x, y in d.items():
    if d[x] == 0:
        continue
    p, q = x
    if q < 0:
        q = -q
        p = -p
    if (q, -p) in d:
        z = d[(q, -p)]
        ans = ans * (pow(2, y, mod) + pow(2, z, mod) - 1) % mod
        d[x] = d[(q, -p)] = 0
    else:
        ans = ans * pow(2, y, mod) % mod
        d[x] = 0
ans = (ans - 1 + czr) % mod
print(ans)

Submission status: Wrong Answer

Solution code:
mod = 1000000007
from collections import defaultdict
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

N = int(input())
AB = [list(map(int,input().split())) for _ in range(N)]
d1 = defaultdict(lambda:0)
d2 = defaultdict(lambda:0)
for i in range(N):
    a,b = AB[i]
    a_ = abs(a)
    b_ = abs(b)
    d = gcd(a,b)
    if d != 0:
        a //= d
        b //= d
    if a < 0:
        a *= -1
        b *= -1
    if b>0:
        d1[(a,b)] += 1
    else:
        d2[(a,b)] += 1
        d1[(-b,a)] += 0

ans = 1
for a,b in d1:
    if a==0 and b==0:
        continue
    x = d1[(a,b)]
    y = d2[(b,-a)]
    ans *= pow(2,x,mod)+pow(2,y,mod)-1
    ans %= mod
ans -= 1
ans += d1[(0,0)]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
from math import gcd
n=N()
mod=10**9+7
az=0
bz=0
zz=0
l=LL(n)
ans=1
import collections
d=collections.defaultdict(int)
for a,b in l:
    if a==0 and b==0:
        zz+=1
    elif a==0:
        az+=1
    elif b==0:
        bz+=1
    elif a<0 and b<0:
        a=-a
        b=-b
        x=gcd(a,b)
        d[(a//x,b//x)]+=1
    elif a<0:
        a=-a
        x=gcd(a,b)
        d[(-a//x,b//x)]+=1
    elif b<0:
        b=-b
        x=gcd(a,b)
        d[(-a//x,b//x)]+=1
    else:
        x=gcd(a,b)
        d[(a//x,b//x)]+=1
pow2=[1]*(n+1)
t=1
for i in range(1,n+1):
    t*=2
    t%=mod
    pow2[i]=t
ans*=(1+(pow2[az]-1)+(pow2[bz]-1))
for a,b in list(d.keys()):
    if a>0 and b>0:
        x=d[(a,b)]
        y=d[(-b,a)]
        ans*=(1+(pow2[x]-1)+(pow2[y]-1))
        ans%=mod
    else:
        if not (b,-a) in d:
            ans*=pow2[d[(a,b)]]
            ans%=mod
print(ans+zz-1)

Submission status: Wrong Answer

Solution code:
n=int(input())
ablist=[]
slist=[]
zeros=[0,0,0]

for i in range(n):
    a, b = map(int,input().split())
    if a==0:
        if b==0:
            zeros[2]+=1
        else:
            zeros[1]+=1
    else:
        if b==0:
            zeros[0]+=1
        else:
            if a*b>0:
                slist.append([a/b, 1])
            else:
                slist.append([b/(-a), -1])
                #slist.append([abs(a/b), int(abs(a*b)/(a*b))])

slist=sorted(slist)
#print(slist)

zerok=2**(zeros[0])-1 + 2**(zeros[1])-1 + zeros[2] + 1
#print(zerok)

mae=[0, 0]
onaji=[1, 0]

answer=1
#print(slist)

for sl in slist:
    if sl[0]==mae[0]:
        if sl[1]==mae[1]:
            onaji[0]+=1
        else:
            onaji[1]+=1
    else:
        if mae!=[0, 0]:
            answer*=(2**onaji[0]+2**onaji[1]-1)
            answer%=1000000007
            onaji=[1, 0]
    mae=sl
    #print(answer)

answer*=(2**onaji[0]+2**onaji[1]-1)
answer%=1000000007

#print(answer)

answer*=zerok

print((answer-1)%1000000007)

Submission status: Wrong Answer

Solution code:
from math import gcd
from collections import Counter
n=int(input())

iw=[]
for i in range(n):
    ab=list(map(int, input().split( )))
    iw.append(ab)

for i in range(n):
    ai,bi=iw[i]
    if ai and bi:##互いに素にする
        g=gcd(ai,bi)
        iw[i][0]//=g;iw[i][1]//=g
    else:#どちらか0なら残りを1か0にする
        if ai:#biがゼロでaiが非ゼロ
            iw[i][0]=1
        elif bi:#aiがゼロでbiが非ゼロ
            iw[i][1]=1
    if bi<0:#biは正に設定
        iw[i][0]*=-1;iw[i][1]*=-1
    if bi==0 and ai<0:#biがゼロならaiは正かゼロ
        iw[i][0]*=-1
iw = [tuple(iwi) for iwi in iw]
C=Counter(iw)
ans=1
mod=10**9+7
#print(C)
#ai bi=0,0は別に処理が要る
if (0,0) in C:
    ans+= C[(0,0)]
    C.pop((0,0))
for ai,bi in C:
    if ai>=0 and C[(ai,bi)]>0:
        if (-bi,ai) in C and C[(-bi,ai)]>0:
            ans*=(pow(2,C[(-bi,ai)],mod)+pow(2,C[(ai,bi)],mod)-1)
            ans%=mod
            C[(-bi,ai)]=-1
        else:
            ans*= pow(2,C[(ai,bi)],mod)
            ans%=mod
    elif C[(ai,bi)]>0:
        if (bi,-ai) in C and C[(bi,-ai)]>0:
            ans*=(pow(2,C[(bi,-ai)],mod)+pow(2,C[(ai,bi)],mod)-1)
            ans%=mod
            C[(bi,-ai)]=-1
        else:
            ans*= pow(2,C[(ai,bi)],mod)
            ans%=mod
    
    #print((ai,bi),C[(ai,bi)],ans)
print(ans-1)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from math import gcd
MOD = 1000000007
inpl = lambda: list(map(int,input().split()))
groups = defaultdict(int)
null = 0
N = int(input())
for _ in range(N):
    A, B = inpl()
    if A == 0 and B == 0:
        null += 1
    elif A == 0:
        groups[(0,1)] += 1
    elif B == 0:
        groups[(1,0)] += 1
    else:
        g = gcd(A,B)
        A //= g
        B //= g
        if A < 0:
            A *= -1
            B *= -1
        groups[(A, B)] += 1
ans = 1
for k in list(groups.keys()):
    A, B = k
    if B <= 0:
        C, D = -B, A
    else:
        C, D = B, -A
    groups[(C,D)]
for k, v in groups.items():
    A, B = k
    if B <= 0:
        continue
    u = groups[(B,-A)]
    p = pow(2,v,MOD) + pow(2,u,MOD) - 1
    ans *= p
    ans %= MOD
ans -= 1
ans += null
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = {}

def gcd(x,y):
    if x>y: x,y=y,x
    while x:
        x,y=y%x,x
    return y

print(gcd(12,5))
print(gcd(12,16))

for _ in range(N):
    A, B = map(int, input().split())
    if   A==0 and B==0: key=(0,0)
    elif A==0: key=(0,1)
    elif B==0: key=(1,0)
    else:
        if A<0:
            A=-A
            B=-B
        g = gcd(A,abs(B))
        key = (A//g, B//g)

    if key not in D: D[key]=0
    D[key]+=1

mod = 10**9+7

ans = 1
n00 = 0
for k1, v1 in D.items():
    if k1==(0,0):
        n00+=v1
        continue
    if v1==0: continue
        
    k2 = (k1[1], -k1[0]) if k1[1]>0 else (-k1[1], k1[0])
    if k2 not in D:
        ans = ans * pow(2, v1, mod) % mod
    else:
        v2 = D[k2]
        m = (pow(2, v1, mod) + pow(2, v2, mod) - 1) % mod
        ans = ans * m % mod
        D[k2]=0
        
print((ans+n00-1)%mod)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import defaultdict
P = 10 ** 36 + 67
mod = 10 ** 9 + 7
N = int(input())
D = defaultdict(int)
C00 = 0
C0 = 0
for i in range(N):
    a, b = map(int, input().split())
    if a == b == 0:
        C00 += 1
    elif a == 0 or b == 0:
        C0 += 1
    else:
        x = a * pow(b, P - 2, P) % P
        D[x] += 1
ans = C0 + 1
for x in D:
    y = pow(-x, P - 2, P)
    if y in D and x > y: continue
    ans *= 1 + pow(2, D[x], mod) - 1 + pow(2, (D[y] if y in D else 0), mod) - 1
    ans %= mod
print((ans + C00 - 1) % mod)

Submission status: Wrong Answer

Solution code:
import sys
from fractions import Fraction
mod = 1000000007

def solve():
    input = sys.stdin.readline
    N = int(input())
    F = [[int(i) for i in input().split()] for _ in range(N)]
    D = dict()
    for x, y in F:
        if x != 0: tan = Fraction(y, x)
        else: tan = "Inf"
        if tan in D: D[tan] += 1
        else: D[tan] = 1

    ans = 1
    used = set()
    for key in D:
        if key not in used:
            this = D[key]
            used |= {key}
            if key == "Inf":
                op = (0 if 0 not in D else D[0])
                used |= {0}
            elif key == 0: 
                op = (0 if "Inf" not in D else D["Inf"])
                used |= {"Inf"}
            else: 
                op = (0 if Fraction(-1 , key) not in D else D[Fraction(-1 , key)])
                used |= {-1 / key}
            select = (pow(2, this, mod) + pow(2, op, mod) - 1) % mod
            ans *= select
            ans %= mod
    ans = (ans - 1) % mod
    #print(D)
    print(ans)
    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    n = II()
    ab = LIR(n)
    par = [i for i in range(n)]
    def root(x):
        if par[x] == x:
            return x
        par[x] = root(par[x])
        return par[x]
    def unite(a, b):
        a = root(a)
        b = root(b)
        if a > b: a, b = b, a
        par[b] = a
        return a
    d = defaultdict(int)
    d2 = defaultdict(int)
    d3 = defaultdict(int)
    for a, b in ab:
        if a == 0 or b == 0:
            d[0] += 1
            d2[0] += 1
        else:
            if a / b > 0:
                d[a / b] += 1
                d3[a / b] += 1
            else:
                d2[-b / a] += 1
                d3[-b / a] += 1
    ans = 1
    for k in d3.keys():
        if k != 0:
            ans *= (2 ** d[k] + 2 ** d2[k] - 1)
            ans %= mod
    ans -= 1
    print(ans % mod)
    return


#main
if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
from math import gcd
from collections import defaultdict


def helper(s):
    a,b = map(int,s.split())
    if a == 0 and b == 0:
        return (0, 0, 0)
    elif a == 0:
        return (1, 1, 0)
    elif b == 0:
        return (-1, 0, 1)

    g = gcd(a,b)
    sign = 1 if a*b > 0 else -1
    return (sign, abs(a//g), abs(b//g))

MOD = 10**9+7
# mを法とするときのa^n
def modpow(a,n):
    res = 1
    t = a
    while n:
        if n%2:
            res = (res*t)%MOD
        t = (t*t)%MOD
        n //= 2
    return res


N = int(input())
counter = defaultdict(int)
for _ in range(N):
    counter[helper(input())] += 1

goods = 1

for (a,b,c),s in tuple(counter.items()):
    if a == 0:
        continue

    s = counter[(a,b,c)]
    t = counter[(-a,c,b)]
    if a < 0 and t > 0:
        continue
    if t == 0:
        goods *= modpow(2,s)
    else:
        goods *= modpow(2,s)+modpow(2,t)-1
    goods %= MOD

goods -= 1
goods %= MOD

print(goods)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import bisect
import collections
import sys
import math
from fractions import Fraction

sys.setrecursionlimit(1000000)
ACMOD = 1000000007
INF = 1 << 62

MOD = 1000000007  # type: int


def solve(N: int, A: "List[int]", B: "List[int]"):
    ab = collections.defaultdict(lambda: [0, 0])  # [posi][nega]
    for i in range(N):
        if A[i] == 0:
            ab[0][1] += 1
        elif A[i] * B[i] >= 0:
            ab[Fraction(abs(B[i]), abs(A[i]))][0] += 1
        else:
            ab[Fraction(abs(A[i]), abs(B[i]))][1] += 1

    # check B[i] ==0
    ans = 1
    for x, y in ab.values():
        pattern = 1  # not select
        pattern += 2 ** x - 1
        pattern += 2 ** y - 1
        ans = ans * pattern % MOD
    print((ans - 1) % MOD)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]"
    B = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, A, B)


if __name__ == '__main__':
    main()