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:
import sys
sys.setrecursionlimit(300000)
from fractions import gcd
from collections import defaultdict

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N = I()
d = defaultdict(int)
zero = 0
for i in range(N):
    a, b = MI()
    if a == 0 and b == 0:
        zero += 1
        continue
    g = gcd(a, b)
    a, b = a // g, b // g
    minus = (-1) ** ((a < 0) + (b < 0))
    d[(minus * abs(a), abs(b))] += 1
print(d)
ans = 1
seen = set()
for a, b in d:
    if (a, b) not in seen:
        if (a, b) in [(1, 0), (0, 1)]:
            ainv, binv = b, a
        else:
            ainv, binv = b * (1 if a < 0 else -1), abs(a)
        lans = (2 ** d[(a, b)] - 1)
        lans += (2 ** d[(ainv, binv)] - 1) if d.get((ainv, binv)) is not None else 0
        lans += 1
        ans = ans * lans % MOD
        seen.add((a, b))
        seen.add((ainv, binv))
ans = (ans + zero) % MOD
print((ans + MOD - 1) % MOD)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(300000)
from fractions import gcd
from collections import defaultdict

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N = I()
d = defaultdict(int)
zero = 0
for i in range(N):
    a, b = MI()
    if a == 0 and b == 0:
        zero += 1
        continue
    g = gcd(a, b)
    a, b = a // g, b // g
    minus = (-1) ** ((a < 0) + (b < 0))
    d[(minus * abs(a), abs(b))] += 1

ans = 1
seen = set()
for a, b in d:
    if (a, b) not in seen:
        ainv, binv = b * (1 if a < 0 else -1), abs(a)
        lans = (2 ** d[(a, b)] - 1)
        lans += (2 ** d[(ainv, binv)] - 1) if d.get((ainv, binv)) is not None else 0
        lans += 1
        ans = ans * lans % MOD
        seen.add((a, b))
        seen.add((ainv, binv))
ans = (ans + zero) % MOD
print((ans + MOD - 1) % MOD)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(300000)
from fractions import gcd
from collections import defaultdict

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N = I()
d = defaultdict(int)
zero = 0
for i in range(N):
    a, b = MI()
    if a == 0 and b == 0:
        zero += 1
        continue
    g = gcd(a, b)
    a, b = a // g, b // g
    minus = (-1) ** ((a < 0) + (b < 0))
    d[(minus * abs(a), abs(b))] += 1

ans = 1
seen = set()
for a, b in d:
    if (a, b) not in seen:
        ainv, binv = b * (1 if a < 0 else -1), abs(a)
        lans = (2 ** d[(a, b)] - 1)
        lans += (2 ** d[(ainv, binv)] - 1) if d.get((ainv, binv)) is not None else 0
        lans += 1
        ans = ans * lans % MOD
        seen.add((a, b))
        seen.add((ainv, binv))
ans = (ans * (zero + 1)) % MOD
print((ans + MOD - 1) % MOD)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(300000)
from fractions import gcd
from collections import defaultdict

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N = I()
d = defaultdict(int)
for i in range(N):
    a, b = MI()
    if a == 0 and b == 0:
        d[(0, 0)] += 1
        continue
    g = gcd(a, b)
    a, b = a // g, b // g
    minus = (-1) ** ((a < 0) + (b < 0))
    d[(minus * abs(a), abs(b))] += 1

ans = 1
seen = set()
for a, b in d:
    if (a, b) not in seen:
        if a == 0 and b == 0:
            ans = (ans * (d[(0, 0)] + 1)) % MOD
            continue
        ainv, binv = b * (1 if a < 0 else -1), abs(a)
        lans = (2 ** d[(a, b)] - 1)
        lans += (2 ** d[(ainv, binv)] - 1) if d.get((ainv, binv)) is not None else 0
        lans += 1
        ans = ans * lans % MOD
        seen.add((a, b))
        seen.add((ainv, binv))
print((ans + MOD - 1) % MOD)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(300000)
from fractions import gcd
from collections import defaultdict

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N = I()
d = defaultdict(int)
for i in range(N):
    a, b = MI()
    if a == 0 and b == 0:
        d[(0, 0)] += 1
        continue
    g = gcd(a, b)
    a, b = a // g, b // g
    minus = (-1) ** ((a < 0) + (b < 0))
    d[(minus * abs(a), abs(b))] += 1

ans = 1
seen = set()
for a, b in d:
    if (a, b) not in seen:
        if a == 0 and b == 0:
            ans = (ans * d[(0, 0)] + 1) % MOD
            continue
        ainv, binv = b * (1 if a < 0 else -1), abs(a)
        lans = (2 ** d[(a, b)] - 1)
        lans += (2 ** d[(ainv, binv)] - 1) if d.get((ainv, binv)) is not None else 0
        lans += 1
        ans = ans * lans % MOD
        seen.add((a, b))
        seen.add((ainv, binv))
print((ans + MOD - 1) % MOD)

Submission status: Wrong Answer

Solution code:
import math


n = int(input())
mod = 1000000007
ab = [list(map(int,input().split())) for _ in range(n)]
dic = {}
z = 0
for a,b in ab:
    if a == 0 and b == 0:
        z += 1
        continue
    if a< 0:
        a = -a
        b = -b
    g = math.gcd(a,b)
    tp = (a//g,b//g)
    if tp not in dic:
        dic[tp] = 1
    else:
        dic[tp] += 1
    
ans = 1
nn = n
for tp,v in dic.items():
    if v == 0:
        continue
    vt = (tp[1],-1*tp[0])
    if vt in dic:
        w = dic[vt]
        #print(tp)
        e = pow(2,v,mod) + pow(2,w,mod) - 1
        ans *= e
        ans %= mod
        nn -= v + w 
        dic[tp] = 0
        dic[vt] = 0
ans *= pow(2,nn,mod)
ans += z-1
print(ans%mod)
#print(dic)

Submission status: Wrong Answer

Solution code:
import math


n = int(input())
mod = 1000000007
ab = [list(map(int,input().split())) for _ in range(n)]
dic = {}
z = 0
for a,b in ab:
    if a == 0 and b == 0:
        z += 1
        continue
    if a< 0:
        a = -a
        b = -b
    g = math.gcd(a,b)
    tp = (a//g,b//g)
    if tp not in dic:
        dic[tp] = 1
    else:
        dic[tp] += 1
    
ans = 1
nn = n
for tp,v in dic.items():
    vt = (tp[1],-1*tp[0])
    if vt in dic:
        w = dic[vt]
        #print(tp)
        e = pow(2,v,mod) + pow(2,w,mod) - 1
        ans *= e
        ans %= mod
        nn -= v + w 
ans *= pow(2,nn,mod)
ans += z-1
print(ans%mod)
#print(dic)

Submission status: Wrong Answer

Solution code:
# E - ∙ (Bullet)
import sys
from collections import defaultdict
from math import gcd

readline = sys.stdin.readline
MOD = 1000000007
N = int(readline())

# イワシの傾きをA/Bとする。
# A/Bは予めgcdで割って約分し、同じ傾きのものを揃えておく。
# このとき、仲の悪い組合せは(A, B)に対して(B, -A)となるもの。 
# 前者をS、後者をTとして考える。
d_S = defaultdict(int)
d_T = defaultdict(int)

'''
def gcd(x, y):
    if x == 0:
        return y
    else:
        return gcd(y%x, x)
'''

pow2_mod = [1] + [0] * (N + 10)
for i in range(1, N + 10):
    pow2_mod[i] = pow2_mod[i-1] * 2 % MOD

zeros = 0
for i in range(N):
    A, B = map(int, readline().split())
    # (0, 0)のイワシは他の全てのイワシと仲が悪いため、
    # 1匹のみでしか選ぶことができない。最後にこの数を足す。
    if A == 0 and B == 0:
        zeros += 1
    # (?, 0),(0, ?)のイワシは、?がどのような数字であろうとも
    # この組合せであれば仲が悪い。一律、(1,0)(0,-1)として考える。
    elif A == 0:
        d_S[(1, 0)] += 0
        d_T[(0, -1)] += 1
    elif B == 0:
        d_S[(1, 0)] += 1
        #d_T[(0, -1)] += 0
    else:
        g = gcd(A, B)
        A //= g
        B //= g
        # いずれもマイナスの場合、傾きはプラスになる
        if A < 0 and B < 0:
            A *= -1
            B *= -1
        if A * B > 0:
            d_S[(A, B)] += 1
            #d_T[(B, -A)] += 0
        # 片方がマイナスの場合、必ずAがマイナスになるよう揃える
        else:
            if A > B:
                A, B = B, A
            d_S[(-A, B)] += 0
            d_T[(B, A)] += 1

ans = 1
for (si, sj), s_cnt in d_S.items():
    t_cnt = d_T[(sj, -1*si)]
    tmp = 0
    tmp += pow2_mod[s_cnt] - 1 # Sから1匹以上選ぶ組合せ
    tmp += pow2_mod[t_cnt] - 1 # Tから1匹以上選ぶ組合せ
    tmp += 1 # どちらも選ばない組合せ
    ans = (ans * tmp)%MOD

ans -= 1 # 最終的に1匹も選ばない組合せ
ans += zeros # (0, 0)のイワシの数

print(ans%MOD)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict
from math import gcd
def input(): return sys.stdin.readline().strip()
mod = 1000000007

def main():
    N = int(input())
    fish = defaultdict(int)

    """
    b / aで値を管理するのは浮動小数点誤差が怖いので、
    g = gcd(a, b) として(a//g, b//g)のタプルで管理するのが良い。
    """

    zero = 0
    for _ in range(N):
        a, b = map(int, input().split())
        if a == 0 and b == 0: zero += 1
        elif a == 0: fish[(0, 1)] += 1
        elif b == 0: fish[(1, 0)] += 1
        else:
            g = gcd(a, b)
            if a < 0: a, b = -a, -b
            fish[(a // g, b // g)] += 1
    #print(fish)
    
    """
    仲の悪い組を(S1, T1), (S2, T2),...とすれば(Si, Ti)からの魚の選び方と
    (Sj, Tj)からの魚の選び方は独立じゃん。
    なぜ気づかなかったのか。。。
    """
    
    ans = 1
    finished = set([])
    for a, b in fish:
        if (a, b) in finished: continue
        finished.add((a, b))
        s = fish[(a, b)]
        if b > 0:
            t = fish[(b, -a)] if (b, -a) in fish else 0
            finished.add((b, -a))
        else:
            t = fish[(-b, a)] if (-b, a) in fish else 0
            finished.add((-b, a))
        ans *= pow(2, s, mod) + pow(2, t, mod) - 1
        ans %= mod
        #print("(a, b)=({}, {}) -> s={}, t={}, val={}".format(a, b, s, t, pow(2, s, mod) + pow(2, t, mod) - 1))
    print(ans + zero - 1)



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def resolve():
    from math import gcd
    n=int(input())
    INF=10**19
    MOD=10**9+7
    abc={}
    for i in range(n):
        a,b=map(int,input().split())
        if a==0 and b==0:
            c='0'
        elif a==0:
            c='0/1'
        elif b==0:
            c='-1/0'
        else:
            g=gcd(abs(a),abs(b))
            if a*b<0:
                c='-'+str(int(abs(a)/g))+'/'+str(int(abs(b)/g))
            else:
                c=str(int(abs(a)/g))+'/'+str(int(abs(b)/g))
        if c in abc.keys():
            abc[c]+=1
        else:
            abc[c]=1
    ans,cnt,zero=1,0,0
    for i,j in abc.items():
        if i=='0':
            zero+=j
            abc[i]=0
            continue
        if j==0:
            continue
        bi=i
        if i[0]=='-':
            i=i[::-1][:-1]
        else:
            i='-'+i[::-1]
        if i in abc.keys():
            k=abc[i]
            abc[bi],abc[i]=0,0
            ans*=pow(2,j,MOD)+pow(2,k,MOD)-1
            ans%=MOD
        else:
            cnt+=1
    ans*=pow(2,sum(abc.values()),MOD)
    ans%=MOD
    if ans>0:
        ans-=1
    ans+=zero
    print(ans%MOD)

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    from math import gcd
    n=int(input())
    INF=10**19
    MOD=10**9+7
    abc={}
    for i in range(n):
        a,b=map(int,input().split())
        if a==0 and b!=0:
            c='0'
        elif a==0 and b==0:
            c='INF'
        else:
            g=gcd(abs(a),abs(b))
            if a*b<0:
                c='-'+str(int(abs(a)/g))+'/'+str(int(abs(b)/g))
            else:
                c=str(int(abs(a)/g))+'/'+str(int(abs(b)/g))
        if c in abc.keys():
            abc[c]+=1
        else:
            abc[c]=1
    ans,cnt,zero=1,0,0
    for i,j in abc.items():
        if i=='0':
            zero+=j
            abc[i]=0
            continue
        if j==0:
            continue
        if i=='INF':
            cnt+=1
            continue
        bi=i
        if i[0]=='-':
            i=i[::-1][:-1]
        else:
            i='-'+i[::-1]
        if i in abc.keys():
            k=abc[i]
            abc[bi],abc[i]=0,0
            ans*=pow(2,j,MOD)+pow(2,k,MOD)-1
            ans%=MOD
        else:
            cnt+=1
    ans*=pow(2,sum(abc.values()),MOD)
    ans%=MOD
    if ans>0:
        ans-=1
    ans+=zero
    print(ans%MOD)

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    from math import gcd
    n=int(input())
    INF=10**19
    MOD=10**9+7
    abc={}
    for i in range(n):
        a,b=map(int,input().split())
        if a==0 and b!=0:
            c='0'
        elif b==0:
            c='INF'
        else:
            g=gcd(abs(a),abs(b))
            if a*b<0:
                c='-'+str(int(abs(a)/g))+'/'+str(int(abs(b)/g))
            else:
                c=str(int(abs(a)/g))+'/'+str(int(abs(b)/g))
        if c in abc.keys():
            abc[c]+=1
        else:
            abc[c]=1
    ans,cnt,zero=1,0,0
    for i,j in abc.items():
        if i=='0':
            zero+=j
            abc[i]=0
            continue
        if j==0:
            continue
        if i=='INF':
            cnt+=1
            continue
        bi=i
        if i[0]=='-':
            i=i[::-1][:-1]
        else:
            i='-'+i[::-1]
        if i in abc.keys():
            k=abc[i]
            abc[bi],abc[i]=0,0
            ans*=pow(2,j,MOD)+pow(2,k,MOD)-1
            ans%=MOD
        else:
            cnt+=1
    ans*=pow(2,sum(abc.values()),MOD)
    ans%=MOD
    if ans>0:
        ans-=1
    ans+=zero
    print(ans%MOD)

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import math
import copy

def main():
    N=int(input())
    zero_fish=0

    Pair={}

    for i in range(N):
        A,B=map(int,input().split())

        if A==0 and B==0:
            zero_fish+=1
            continue
        if B==0:
            bunsi=1
            bunbo=0
        elif B>0:
            bunsi=A//math.gcd(A,B)
            bunbo=B//math.gcd(A,B)
        else:
            bunsi=-1*A//math.gcd(A,B)
            bunbo=-1*B//math.gcd(A,B)

        key = str(bunsi) + "/" + str(bunbo)

        if bunsi == 0 or bunbo == 0:
            rev_bunsi = bunbo
            rev_bunbo = bunsi
        elif bunsi < 0:
            rev_bunsi = bunbo
            rev_bunbo = -1 * bunsi
        else:
            rev_bunsi = -1 * bunbo
            rev_bunbo = bunsi
        rev_key = str(rev_bunsi) + "/" + str(rev_bunbo)

        if (key in Pair.keys()):
            Pair[key][0]+=1
        elif (rev_key in Pair.keys()):
            Pair[rev_key][1]+=1
        else:
            Pair[key]=[1,0]

    res=1
    mod=1000000007
    for p in Pair.values():
        if p[1]==0:
            temp=pow(2,p[0],mod)
        else:
            temp=pow(2,p[0],mod)+pow(2,p[1],mod)-1
        res=(res*temp)%mod
    res+=zero_fish-1

    print(res)

if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math
import collections
from collections import defaultdict

N = int(input())
iwa = []
mod = 10**9+7
cnt = 0
for i in range(N):
    a, b = map(int,input().split())
    if a == 0 and b == 0:
        cnt = 1
        continue
    elif b == 0:
        iwa.append((1,0))
    elif a == 0:
        iwa.append((0,1))
    elif b > 0:
        c = math.gcd(a,b)
        iwa.append((a/c, b/c))#bは正
    else:
        c = math.gcd(a,b)
        iwa.append((-a/c, -b/c))#bは正
        
S = set(iwa)
I = collections.Counter(iwa)
#print(I)
jdg = defaultdict(int)

ans = 1
for i in S:
    if jdg[i] == 1:
        continue
    elif i == (1,0) or i == (0,1):
        k = I[(1,0)]
        l = I[(0,1)]
        if min(k,l) == 0:
            ans *= pow(2,max(l,k),mod)
        else:
            ans *= (pow(2,l,mod)-1) + (pow(2,k,mod)-1)+1
        jdg[(1,0)] = 1
        jdg[(0,1)] = 1
    else:
        k = I[i]
        a, b = i
        if a < 0:
            l = I[(b,-a)]
            jdg[(b, -a)] = 1
        else:
            l = I[(-b,a)]
            jdg[(-b,a)] = 1
        if min(l,k) == 0:
            ans *= pow(2,max(l,k),mod)
        else:
            ans *= (pow(2,l,mod)-1) + (pow(2,k,mod)-1)+1
        jdg[i] = 1
print(ans+cnt-1)

Submission status: Wrong Answer

Solution code:
import math
import copy

def main():
    N=int(input())
    zero_fish=0

    Pair={}

    for i in range(N):
        A,B=map(int,input().split())

        if A==0 and B==0:
            zero_fish+=1
            continue
        if B==0:
            bunsi=1
            bunbo=0
        elif B>0:
            bunsi=A//math.gcd(A,B)
            bunbo=B//math.gcd(A,B)
        else:
            bunsi=-1*A//math.gcd(A,B)
            bunbo=-1*B//math.gcd(A,B)

        key = str(bunsi) + "/" + str(bunbo)

        if bunsi == 0 or bunbo == 0:
            rev_bunsi = bunbo
            rev_bunbo = bunsi
        elif bunsi < 0:
            rev_bunsi = bunbo
            rev_bunbo = -1 * bunsi
        else:
            rev_bunsi = -1 * bunbo
            rev_bunbo = bunsi
        rev_key = str(rev_bunsi) + "/" + str(rev_bunbo)

        if (key in Pair.keys()):
            Pair[key][0]+=1
        elif (rev_key in Pair.keys()):
            Pair[rev_key][1]+=1
        else:
            Pair[key]=[1,0]

    res=1
    mod=1000000007
    print(Pair)
    for p in Pair.values():
        if p[1]==0:
            temp=pow(2,p[0],mod)
        else:
            temp=pow(2,p[0],mod)+pow(2,p[1],mod)-1
        res=(res*temp)%mod
    res+=zero_fish-1

    print(res)

if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
def resolve():
    from math import gcd
    n=int(input())
    INF=10**19
    MOD=10**9+7
    abc={}
    for i in range(n):
        a,b=map(int,input().split())
        if a==0:
            c='0'
        elif b==0:
            c='INF'
        else:
            g=gcd(abs(a),abs(b))
            if a*b<0:
                c='-'+str(int(abs(a)/g))+'/'+str(int(abs(b)/g))
            else:
                c=str(int(abs(a)/g))+'/'+str(int(abs(b)/g))
        if c in abc.keys():
            abc[c]+=1
        else:
            abc[c]=1
    ans,cnt,zero=1,0,0
    for i,j in abc.items():
        if i=='0':
            zero+=j
            abc[i]=0
            continue
        if j==0:
            continue
        if i=='INF':
            cnt+=1
            continue
        bi=i
        if i[0]=='-':
            i=i[::-1][:-1]
        else:
            i='-'+i[::-1]
        if i in abc.keys():
            k=abc[i]
            abc[bi],abc[i]=0,0
            ans*=pow(2,j,MOD)+pow(2,k,MOD)-1
            ans%=MOD
        else:
            cnt+=1
    ans*=pow(2,sum(abc.values()),MOD)
    ans%=MOD
    if ans>0:
        ans-=1
    ans+=zero
    print(ans%MOD)

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import math
import collections
from collections import defaultdict

N = int(input())
iwa = []
mod = 10**9+7

for i in range(N):
    a, b = map(int,input().split())
    if a == 0 and b == 0:
        continue
    elif b == 0:
        iwa.append((1,0))
    elif a == 0:
        iwa.append((0,1))
    elif b > 0:
        c = math.gcd(a,b)
        iwa.append((a/c, b/c))#bは正
    else:
        c = math.gcd(a,b)
        iwa.append((-a/c, -b/c))#bは正
        
S = set(iwa)
I = collections.Counter(iwa)
#print(I)
jdg = defaultdict(int)

ans = 1
for i in S:
    if jdg[i] == 1:
        continue
    elif i == (1,0) or i == (0,1):
        k = I[(1,0)]
        l = I[(0,1)]
        if min(k,l) == 0:
            ans *= pow(2,max(l,k),mod)
        else:
            ans *= (pow(2,l,mod)-1) + (pow(2,k,mod)-1)+1
        jdg[(1,0)] = 1
        jdg[(0,1)] = 1
    else:
        k = I[i]
        a, b = i
        if a < 0:
            l = I[(b,-a)]
            jdg[(b, -a)] = 1
        else:
            l = I[(-b,a)]
            jdg[(-b,a)] = 1
        if min(l,k) == 0:
            ans *= pow(2,max(l,k),mod)
        else:
            ans *= (pow(2,l,mod)-1) + (pow(2,k,mod)-1)+1
        jdg[i] = 1
print(ans-1)

Submission status: Wrong Answer

Solution code:
def resolve():
    from math import gcd
    n=int(input())
    INF=10**19
    MOD=10**9+7
    abc={}
    for i in range(n):
        a,b=map(int,input().split())
        if a==0:
            c='0'
        elif b==0:
            c='INF'
        else:
            g=gcd(abs(a),abs(b))
            if a*b<0:
                c='-'+str(int(abs(a)/g))+'/'+str(int(abs(b)/g))
            else:
                c=str(int(abs(a)/g))+'/'+str(int(abs(b)/g))
        if c in abc.keys():
            abc[c]+=1
        else:
            abc[c]=1
    ans,cnt,zero=1,0,0
    for i,j in abc.items():
        if i=='0':
            zero+=1
            abc[i]=0
            continue
        if j==0:
            continue
        if i=='INF':
            cnt+=1
            continue
        bi=i
        if i[0]=='-':
            i=i[::-1][:-1]
        else:
            i='-'+i[::-1]
        if i in abc.keys():
            k=abc[i]
            abc[bi],abc[i]=0,0
            ans*=pow(2,j,MOD)+pow(2,k,MOD)-1
            ans%=MOD
        else:
            cnt+=1
    ans*=pow(2,sum(abc.values()),MOD)
    ans%=MOD
    if ans>0:
        ans-=1
    ans+=zero
    print(ans%MOD)

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    from math import gcd
    n=int(input())
    INF=10**19
    MOD=10**9+7
    abc={}
    for i in range(n):
        a,b=map(int,input().split())
        if a==0:
            c='0'
        elif b==0:
            c='INF'
        else:
            g=gcd(abs(a),abs(b))
            if a*b<0:
                c='-'+str(int(abs(a)/g))+'/'+str(int(abs(b)/g))
            else:
                c=str(int(abs(a)/g))+'/'+str(int(abs(b)/g))
        if c in abc.keys():
            abc[c]+=1
        else:
            abc[c]=1
    ans,cnt,zero=1,0,0
    for i,j in abc.items():
        if i=='0':
            zero+=1
            continue
        if j==0:
            continue
        if i=='INF':
            cnt+=1
            continue
        bi=i
        if i[0]=='-':
            i=i[::-1][:-1]
        else:
            i='-'+i[::-1]
        if i in abc.keys():
            k=abc[i]
            abc[bi],abc[i]=0,0
            ans*=pow(2,j,MOD)+pow(2,k,MOD)-1
            ans%=MOD
        else:
            cnt+=1
    ans*=pow(2,sum(abc.values()),MOD)
    ans%=MOD
    ans+=zero-1
    print(ans%MOD)

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:

Submission status: Wrong Answer

Solution code:
import math
import copy

def main():
    N=int(input())
    zero_fish=0

    Pair={}

    for i in range(N):
        A,B=map(int,input().split())

        if A==0 and B==0:
            zero_fish+=1
            continue
        if B==0:
            bunsi=1
            bunbo=0
        elif B>0:
            bunsi=A//math.gcd(A,B)
            bunbo=B//math.gcd(A,B)
        else:
            bunsi=-1*A//math.gcd(A,B)
            bunbo=-1*B//math.gcd(A,B)

        key = str(bunsi) + "/" + str(bunbo)

        if bunsi == 0 or bunbo == 0:
            rev_bunsi = bunbo
            rev_bunbo = bunsi
        elif bunsi < 0:
            rev_bunsi = bunbo
            rev_bunbo = -1 * bunsi
        else:
            rev_bunsi = -1 * bunbo
            rev_bunbo = bunsi
        rev_key = str(rev_bunsi) + "/" + str(rev_bunbo)

        if (key in Pair.keys()):
            Pair[key][0]+=1
        elif (rev_key in Pair.keys()):
            Pair[rev_key][1]+=1
        else:
            Pair[key]=[1,0]

    res=1
    mod=1000000007
    for p in Pair.values():
        if p[1]==0:
            temp=pow(2,p[0],mod)
        else:
            temp=pow(2,p[0],mod)+pow(2,p[1],mod)-1
        res*=temp
    res+=zero_fish-1

    print(res)

if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math
mod = 10**9+7
N = int(input())

iwashi01 = 0
iwashi10 = 0
iwashi00 = 0
iwashi = dict()
for i in range(N):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        iwashi00 += 1
    elif a == 0:
        iwashi01 += 1
    elif b == 0:
        iwashi10 += 1            
    else:
        g = math.gcd(abs(a), abs(b))
        a //= g; b //= g
        if a*b > 0:
            if a < 0 and b < 0:
                a *= -1
                b *= -1
            iwashi.setdefault((a, b), [0, 0])
            iwashi[(a, b)][0] += 1
        if a*b < 0:
            if a < 0 and b > 0:
                a *= -1
                b *= -1
            a, b = -b, a
            iwashi.setdefault((a, b), [0, 0])
            iwashi[(a, b)][1] += 1

r = 2**iwashi01 % mod - 1 + 2**iwashi10 % mod - 1 + 1
for s, t in iwashi.values():
    r *= 2**s % mod -1 + 2**t % mod -1 + 1
    r %= mod
print(r + iwashi00 - 1)

Submission status: Wrong Answer

Solution code:
import math
import copy

def main():
    N=int(input())
    zero_fish=0

    Rate={}

    for i in range(N):
        A,B=map(int,input().split())

        if A==0 and B==0:
            zero_fish+=1
            continue
        if B==0:
            bunsi=1
            bunbo=0
        elif B>0:
            bunsi=A//math.gcd(A,B)
            bunbo=B//math.gcd(A,B)
        else:
            bunsi=-1*A//math.gcd(A,B)
            bunbo=-1*B//math.gcd(A,B)

        num_str = str(bunsi) + "/" + str(bunbo)
        if (num_str in Rate.keys()):
            Rate[num_str] += 1
        else:
            Rate[num_str] = 1

    Keys=copy.copy(list(Rate.keys()))

    pair=[]
    no_pair=0
    while len(Keys)>0:
        key=Keys.pop(0)
        bunsi,bunbo=map(int,key.split("/"))
        if bunsi==0 or bunbo==0:
            rev_bunsi=bunbo
            rev_bunbo=bunsi
        elif bunsi<0:
            rev_bunsi=bunbo
            rev_bunbo=-1*bunsi
        else:
            rev_bunsi=-1*bunbo
            rev_bunbo=bunsi
        rev_key=str(rev_bunsi)+"/"+str(rev_bunbo)

        if (rev_key in Keys):
            pair.append((Rate[key],Rate[rev_key]))
            Keys.remove(rev_key)
        else:
            no_pair+=Rate[key]
    pair.append((no_pair,0))

    res=1
    mod=1000000007
    for p in pair:
        if p[1]==0:
            temp=pow(2,p[0],mod)
        else:
            temp=pow(2,p[0],mod)+pow(2,p[1],mod)-1
        res*=temp
    res+=zero_fish-1

    print(res)

if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
from math import gcd
from collections import defaultdict

n=int(input())
abd=defaultdict(int)
mod=10**9+7
wzero=0
azero=0
bzero=0
for i in range(n):
    a,b=map(int,input().split())
    if a==0 and b==0:
        wzero+=1
    elif a==0 and b!=0:
        azero+=1
    elif a!=0 and b==0:
        bzero+=1
    else:
        x=gcd(a,b)
        a//=x
        b//=x
        abd[(a,b)]+=1

used=[]
liskey=list(abd.keys())
ans=1
for k in liskey:
    if abd[k] != 0:
        x=abd[k]
        used.append(k)
        a,b=k
        y=abd[(-b,a)]+abd[(b,-a)]
        abd[(-b,a)]=0
        abd[(b,-a)]=0
        ans*=(2**x+2**y-1+mod)%mod
        ans%=mod

ans*=(2**azero+2**bzero-1+mod)%mod
ans%=mod
ans+=wzero
ans=(ans+mod-1)%mod
print(ans)

Submission status: Wrong Answer

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    from math import gcd
    d={}
    for i in range(N):
        a,b=MI()
        if a*b!=0:
            g=gcd(abs(a),abs(b))
            a=a//g
            b=b//g
        elif (a,b)!=(0,0):
            if a==0:
                b=1
            else:
                a=1
            
        if (a,b) in d:
            d[(a,b)]+=1
        else:
            d[(a,b)]=1
        
    ans=1
    L=[]
    for k in d.keys():
        L.append((k,d[k]))

    temp0=0
    for i in range(len(L)):
        k=L[i][0]
        v=d[k]
        d[k]=0
        temp=pow(2,v)
        a,b=k
        if a*b!=0:
            if (-b,a) in d:
                v2=d[(-b,a)]
                if v2!=0:
                    temp+=pow(2,v2)-1
                    d[(-b,a)]=0
            if (b,-a) in d:
                v2=d[(b,-a)]
                if v2!=0:
                    temp+=pow(2,v2)-1
                    d[(b,-a)]=0
        elif (a,b)==(1,0) or (a,b)==(0,1):
            if (b,a) in d:
                v2=d[(b,a)]
                if v2!=0:
                    temp+=pow(2,v2)-1
                    d[(b,a)]=0
        else:
            temp0=v
            temp=1
        ans=(ans*temp)%mod
        
        


    ans=(ans-1+temp0)%mod
    print(ans)
        
        
            
            
    #せんぶ０の組みをひく
        
    

main()

Submission status: Wrong Answer

Solution code:


def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9
    N=I()
    from math import gcd
    from collections import defaultdict
    dd = defaultdict(int)
    temp0=0

    for i in range(N):
        a,b=MI()
        if (a,b)==(0,0):
            temp0+=1
            continue
        
        if a<0:
            a*=-1
            b*=-1
        
        #(+,+)と(+,-)だけにする
        if a*b!=0:
            g=gcd(a,b)
            a=a//g
            b=b//g
            if a*b>0:#(+,+)
                dd[(a,b)]+=1
                dd[b,-a]+=0
                
            else:#(+,-)
                dd[(a,b)]+=1
                dd[(-b,a)]+=0
            
        elif (a,b)!=(0,0):
            #assert 0
            if a==0:
                b=1
            else:
                a=1
                
            dd[(a,b)]+=1
            dd[(b,a)]+=0
        

    ans=1
    
    for k,v in dd.items():
        a,b=k
        if b<=0:
            continue
        #( +,+)と(0,1)だけ見る
        
        if a*b!=0:
            v=dd[k]
            v2=dd[(b,-a)]
        else:
            v=dd[k]
            v2=dd[(b,a)]
        temp=pow(2,v,mod)+pow(2,v2,mod)-1
        
        ans=(ans*temp)%mod

    ans=(ans-1+temp0)%mod
    print(ans)
        
        
            
            
    #せんぶ０の組みをひく
        
    

main()