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 math
mod = 10**9+7
n = int(input())
mp = {}
zero = 0
for i in range(n):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        zero += 1
        continue
    g = math.gcd(a, b)
    a /= g
    b /= g
    if b < 0:
        a, b = -a, -b
    if b == 0 and a < 0:
        a, b = 1, 0
    rot90 = a <= 0
    if rot90:
        a, b = b, -a
        if (a, b) in mp:
            mp[(a,b)][0] += 1
        else:
            mp[(a,b)] = [1, 0]
    else:
        if (a, b) in mp:
            mp[(a, b)][1] += 1
        else:
            mp[(a, b)] = [0, 1]
ans = 1
for k in mp:
    s = mp[k][0]
    t = mp[k][1]
    now = 1
    now += (pow(2, s, mod) - 1) % mod
    now += (pow(2, t, mod) - 1) % mod
    ans = (ans * now) % mod
ans =  (ans -1) % mod
ans = (ans + zero) % mod 
print(ans)

Submission status: Wrong Answer

Solution code:
import math
mod = 10**9+7
n = int(input())
mp = {}
zero = 0
for i in range(n):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        zero += 1
        continue
    g = math.gcd(a, b)
    a /= g
    b /= g
    if b < 0:
        a, b = -a, -b
    if b == 0 and a < 0:
        a, b = 1, 0
    rot90 = a <= 0
    if rot90:
        a, b = b, -a
        if (a, b) in mp:
            mp[(a,b)][0] += 1
        else:
            mp[(a,b)] = [1, 0]
    else:
        if (a, b) in mp:
            mp[(a, b)][1] += 1
        else:
            mp[(a, b)] = [0, 1]
ans = 1
for k in mp:
    s = mp[k][0]
    t = mp[k][1]
    now = 1
    now += (pow(2, s, mod) - 1) % mod
    now += (pow(2, t, mod) - 1) % mod
    ans = (ans * now) % mod
ans -= 1
ans += zero
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
p = 10**9+7
from math import gcd
from collections import Counter
from collections import defaultdict
used = defaultdict(list)

n = int(input())

ctr = Counter()
az = bz = zz = 0
for i in range(n):
    a, b = map(int, input().split())
    if a==b==0:
        zz+=1
    elif a==0:
        az+=1
    elif b==0:
        bz+=1
    else:
        g = gcd(a,b)
        a,b = a//g, b//g
        if b < 0:
            a*=-1
            b*=-1
        ctr[(a,b)]+=1
        used[(a,b)]=False

if n==1:
    print(0)
    exit()

ans = 1

# 仲の悪いグループ対ごとに処理する
for (a1,b1),v1 in ctr.items():
    if used[(a1,b1)]:
        continue
    a2,b2=-b1,a1
    if b2 < 0:
        b2*=-1
        a2*=-1
    v2 = ctr[(a2,b2)]

    r = (pow(2,v1,p)+pow(2,v2,p)-1)%p
    ans*=r
    ans%=p
    used[(a1,b1)]=True
    used[(a2,b2)]=True

# 片方が0のクループ対
r = (pow(2,az,p)+pow(2,bz,p)-1)%p
ans*=r
ans%=p

ans+=zz # 0匹のケースは禁止されている
ans-=1 # 0匹のケースは禁止されている
ans%=p
print(ans)

Submission status: Wrong Answer

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

def input():
    return sys.stdin.readline().rstrip()

MOD = 10**9 + 7
n = int(input())
cnt = {}
zero_cnt = 0
ans = 1

for _ in range(n):
    a, b = map(int, input().split())
    if (a, b) == (0, 0):
        zero_cnt += 1
        continue
    g = gcd(abs(a), abs(b))
    if a == 0 or b == 0: g = max(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

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 #for empty set
print(ans % MOD)

Submission status: Wrong Answer

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

def input():
    return sys.stdin.readline().rstrip()

MOD = 10**9 + 7
n = int(input())
cnt = {}
zero_cnt = 0
ans = 1

for _ in range(n):
    a, b = map(int, input().split())
    if (a, b) == (0, 0):
        zero_cnt += 1
        continue
    g = gcd(abs(a), abs(b))
    if g == 0: g = max(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

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 #for empty set
print(ans % MOD)

Submission status: Wrong Answer

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

def input():
    return sys.stdin.readline().rstrip()

MOD = 10**9 + 7
n = int(input())
cnt = {}
zero_cnt = 0
ans = 1

for _ in range(n):
    a, b = map(int, input().split())
    if (a, b) == (0, 0):
        zero_cnt += 1
        continue
    g = gcd(abs(a), abs(b))
    if g != 0:
        a /= g
        b /= g
    else:
        if a > 0: a = 1
        if b > 0: b = 1

    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

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 #for empty set
print(ans % MOD)

Submission status: Wrong Answer

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

def input():
    return sys.stdin.readline().rstrip()

MOD = 10**9 + 7
n = int(input())
cnt = {}
zero_cnt = 0
ans = 1

for _ in range(n):
    a, b = map(int, input().split())
    if (a, b) == (0, 0):
        zero_cnt += 1
        continue
    g = gcd(abs(a), abs(b))
    if g != 0:
        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

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 #for empty set
print(ans % MOD)

Submission status: Wrong Answer

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

def input():
    return sys.stdin.readline().rstrip()

MOD = 10**9 + 7
n = int(input())
cnt = {}
zero_cnt = 0
ans = 1

for _ in range(n):
    a, b = map(int, input().split())
    if (a, b) == (0, 0):
        zero_cnt += 1
        continue
    g = gcd(abs(a), abs(b))
    if g != 0:
        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

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 #for empty set
print(ans % MOD)

Submission status: Wrong Answer

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

def input():
    return sys.stdin.readline().rstrip()

MOD = 10**9 + 7
n = int(input())
cnt = {}
zero_cnt = 0
ans = 1

for _ in range(n):
    a, b = map(int, input().split())
    if (a, b) == (0, 0):
        zero_cnt += 1
        continue
    g = gcd(abs(a), abs(b))
    if g != 0:
        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

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 #for empty set
print(ans % MOD)

Submission status: Wrong Answer

Solution code:
from math import gcd
from numpy import sign
mod = 1000000007
N = int(input())

if N == 1:
    print(1)
    
d = {}
counter = 0

f = 0
l = 0

for _ in range(N):
    a, b = list(map(int, input().split()))
    if a == b == 0:
        counter += 1
    elif a==0:
        f += 1
    elif b==0:
        l += 1
    else:
        g = gcd(a, b)
        a, b =  a // g, b //g
        if b < 0:
            a, b = -a, -b
        if (a, b) not in d:
            d[(a, b)] =1
        else:
            d[(a, b)] +=1

answer = 1

group = set()
for (p, q), v in d.items():
    invp,invq=-q,p
    if invq<0:
        invp,invq=-invp,-invq
    if not (invp,invq) in group:
        group.add((p,q))

for (p, q) in group:
    invp,invq=-q,p
    if invq<0:
        invp,invq=-invp,-invq
    if (invp, invq) not in d:
        answer *= (2 ** d[(p, q)])
    else:
        answer *= ((2 ** d[(p, q)]) + (2 ** d[(invp, invq)]) - 1)
        
answer *= 2**f + 2**l - 1
    
print((answer + counter - 1) % mod)

Submission status: Wrong Answer

Solution code:
from math import gcd
from numpy import sign
mod = 1000000007
N = int(input())

if N == 1:
    print(1)
    
d = {}
counter = 0

f = 0
l = 0

for _ in range(N):
    a, b = list(map(int, input().split()))
    if a == b == 0:
        counter += 1
    elif a==0:
        f += 1
    elif b==0:
        l += 1
    else:
        g = gcd(a, b)
        a, b =  a // g, b //g
        if b < 0:
            a, b = -a, -b
        if (a, b) not in d:
            d[(a, b)] =1
        else:
            d[(a, b)] +=1

answer = 1

group = set()
for (p, q), v in d.items():
    invp,invq=-q,p
    if invq<0:
        invp,invq=-invp,-invq
    if not (invp,invq) in group:
        group.add((p,q))

for (p, q) in group:
    invp,invq=-q,p
    if invq<0:
        invp,invq=-invp,-invq
    if (invp, invq) not in d:
        answer *= (2 ** (d[(p, q)]-1)) % mod
        answer = answer % mod
    else:
        answer *= ((2 ** (d[(p, q)]-1)) + (2 ** (d[(invp, invq)]-1)) - 1) % mod
        answer = answer % mod
        
answer *= 2**f + 2**l - 1
    
print((answer + counter - 1) % mod)

Submission status: Wrong Answer

Solution code:
from math import gcd
from numpy import sign
mod = 1000000007
N = int(input())

if N == 1:
    print(1)
    
d = {}
counter = 0

f = 0
l = 0

for _ in range(N):
    a, b = list(map(int, input().split()))
    if a == b == 0:
        counter += 1
    elif a==0:
        f += 1
    elif b==0:
        l += 1
    else:
        g = gcd(a, b)
        a, b =  a // g, b //g
        if b < 0:
            a, b = -a, -b
        if (a, b) not in d:
            d[(a, b)] =1
        else:
            d[(a, b)] +=1

answer = 1

group = set()
for (p, q), v in d.items():
    invp,invq=-q,p
    if invq<0:
        invp,invq=-invp,-invq
    if not (invp,invq) in group:
        group.add((p,q))

for (p, q) in group:
    invp,invq=-q,p
    if invq<0:
        invp,invq=-invp,-invq
    if (invp, invq) not in d:
        answer *= (2 ** d[(p, q)]) % mod
        answer = answer % mod
    else:
        answer *= ((2 ** d[(p, q)]) + (2 ** d[(invp, invq)]) - 1) % mod
        answer = answer % mod
        
answer *= 2**f + 2**l - 1
    
print((answer + counter - 1) % mod)

Submission status: Wrong Answer

Solution code:
from math import gcd
from numpy import sign
mod = 1000000007
N = int(input())

if N == 1:
    print(1)
    
d = {}
counter = 0

f = 0
l = 0

for _ in range(N):
    a, b = list(map(int, input().split()))
    if a == b == 0:
        counter += 1
    elif a==0:
        f += 1
    elif b==0:
        l += 1
    else:
        g = gcd(a, b)
        a, b =  a // g, b //g
        if b < 0:
            a, b = -a, -b
        if (a, b) not in d:
            d[(a, b)] =1
        else:
            d[(a, b)] +=1

answer = 1


group = set()
for (p, q), v in d.items():
    invp,invq=-q,p
    if invq<0:
        invp,invq=-invp,-invq
    if not (invp,invq) in group:
        group.add((p,q))

for (p, q) in group:
    invp, invq = (sign(p) * (-1) * q, abs(p))
    if (invp, invq) not in d:
        answer *= (2 ** d[(p, q)]) % mod
        answer = answer % mod
    else:
        answer *= ((2 ** d[(p, q)]) + (2 ** d[(invp, invq)]) - 1) % mod
        answer = answer % mod
        
answer *= 2**f + 2**l - 1
    
print((answer + counter - 1) % mod)

Submission status: Wrong Answer

Solution code:
from math import gcd
from numpy import sign
mod = 1000000007
N = int(input())

if N == 1:
    print(1)
    
d = {}
counter = 0

for _ in range(N):
    a, b = list(map(int, input().split()))
    if a == b == 0:
        counter += 1
    else:
        g = gcd(a, b)
        a, b =  a // g, b //g
        if b < 0:
            a, b = -a, -b
        if (a, b) not in d:
            d[(a, b)] =1
        else:
            d[(a, b)] +=1

answer = 1

done_list = []


for (p, q), v in d.items():
    if (p, q) not in done_list:
        invp, invq = (sign(p) * (-1) * q, abs(p))
        if (invp, invq) not in d:
            answer *= (2 ** d[(p, q)]) % mod
            answer = answer % mod
            done_list += [(p, q)]
        else:
            answer *= ((2 ** d[(p, q)]) + (2 ** d[(invp, invq)]) - 1) % mod
            answer = answer % mod
            done_list += [(p, q), (invp, invq)]
    
print((answer + counter - 1) % mod)

Submission status: Wrong Answer

Solution code:
import math
import bisect
mod=pow(10,9)+7

n=int(input())
cnt=0
za=0
zb=0
p=[]
m=[]
for i in range(n):
    a,b=map(int,input().split())
    if a==0 and b==0:
        cnt+=1
    elif a==0:
        za+=1
    elif b==0:
        zb+=1
    else:
        g=math.gcd(a,b)
        if (a>0 and b>0) or (a<0 and b<0):
            p.append((a/g)/(b/g))
        else:
            m.append(-(b/g)/(a/g))

s=set(p+m)
ans=1
for i in s:
    ans*=pow(2,p.count(i),mod)+pow(2,m.count(i),mod)-1
    ans%=mod

ans*=pow(2,za,mod)+pow(2,zb,mod)-1
ans%=mod

ans-=1

ans+=cnt

print(ans%mod)

Submission status: Wrong Answer

Solution code:
import math
import bisect
mod=pow(10,9)+7

n=int(input())
cnt=0
z=0
za=0
zb=0
p=[]
m=[]
for i in range(n):
    a,b=map(int,input().split())
    if a==0 and b==0:
        cnt+=1
    elif a==0:
        za+=1
    elif b==0:
        zb+=1
    else:
        g=math.gcd(a,b)
        if (a>0 and b>0) or (a<0 and b<0):
            p.append((a/g)/(b/g))
        else:
            m.append(-(b/g)/(a/g))

s=set(p+m)
arr=[]
ans=1
for i in s:
    ans*=(pow(2,p.count(i),mod)+pow(2,m.count(i),mod)-1)%mod

ans*=(pow(2,za,mod)+pow(2,zb,mod)-1)%mod

ans-=1

ans+=cnt

print(ans%mod)

Submission status: Wrong Answer

Solution code:
import math
import bisect
mod=pow(10,9)+7

n=int(input())
cnt=0
z=0
za=0
zb=0
p=[]
m=[]
for i in range(n):
    a,b=map(int,input().split())
    if a==0 and b==0:
        cnt+=1
    elif a==0:
        za+=1
    elif b==0:
        zb+=1
    else:
        g=math.gcd(a,b)
        if (a>0 and b>0) or (a<0 and b<0):
            p.append((a/g)/(b/g))
        else:
            m.append(-(b/g)/(a/g))

s=set(p+m)
arr=[]
ans=1
for i in s:
    ans*=pow(2,p.count(i),mod)+pow(2,m.count(i),mod)-1

ans*=pow(2,za,mod)+pow(2,zb,mod)-1

ans-=1

ans+=cnt

print(ans%mod)

Submission status: Wrong Answer

Solution code:
import math
import bisect
mod=pow(10,9)+7

n=int(input())
cnt=0
z=0
za=0
zb=0
p=[]
m=[]
for i in range(n):
    a,b=map(int,input().split())
    if a==0 and b==0:
        cnt+=1
    elif a==0:
        za+=1
    elif b==0:
        zb+=1
    else:
        g=math.gcd(a,b)
        if (a>0 and b>0) or (a<0 and b<0):
            p.append((a/g)/(b/g))
        else:
            m.append(-(b/g)/(a/g))

s=set(p+m)
arr=[]
ans=1
for i in s:
    ans*=pow(2,p.count(i),mod)+pow(2,m.count(i),mod)-1

ans*=pow(2,za,mod)+pow(2,zb,mod)-1

ans-=1

ans+=cnt

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
import collections
c=collections.Counter()
from math import gcd
mod=10**9+7
for _ in range(n):
    a,b=map(int,input().split())
    g=abs(gcd(a,b))
    if g==0:
        g=1
    a//=g
    b//=g
    c[(a,b)]+=1
ans=1
s=set()
for i,j in c:
    if (i,j)==(0,0):
        ans+=c[(0,0)]
    if (i,j) not in s:
        s.add((i,j))
        s.add((-i,-j))
        s.add((-j,i))
        s.add((j,-i))
        ans*=(pow(2,c[(i,j)]+c[(-i,-j)],mod)+pow(2,c[(j,-i)]+c[(-j,i)],mod)-1)%mod
print((ans-1)%mod)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]

MOD = 1000000007

dic1 = {}
a_zero = 0
b_zero = 0
both_zero = 0

for a, b in AB:
    if a == 0 and b != 0:
        a_zero += 1
    elif a != 0 and b == 0:
        b_zero += 1
    elif a == 0 and b == 0:
        both_zero += 1
    else:
        g = math.gcd(a, b)
        a //= g
        b //= g

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

pair = []
used = set()

for key, val in dic1.items():
    if key in used:
        continue

    a, b = key
    used.add((a, b))
    cnt = 0

    if (-b, a) in dic1:
        cnt += dic1.get((-b, a), 0)
        used.add((-b, a))

    if (b, -a) in dic1:
        cnt += dic1.get((b, -a), 0)
        used.add((b, -a))

    pair.append((val, cnt))


all_cnt = 1
for cnt1, cnt2 in pair:
    all_cnt *= pow(2, cnt1, MOD) + pow(2, cnt2, MOD) - 1
    all_cnt %= MOD

all_cnt *= pow(2, a_zero, MOD) + pow(2, b_zero, MOD) - 1
all_cnt %= MOD
all_cnt += both_zero
all_cnt %= MOD

print((all_cnt - 1) % MOD)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]

MOD = 1000000007

dic1 = {}
dic2 = {}
a_zero = 0
b_zero = 0
both_zero = 0

for a, b in AB:
    if a == 0 and b != 0:
        a_zero += 1
    elif a != 0 and b == 0:
        b_zero += 1
    elif a == 0 and b == 0:
        both_zero += 1
    else:
        g = math.gcd(a, b)
        a /= g
        b /= g
        s = a / b
        t = -b / a

        if s in dic1:
            dic1[s] += 1
        else:
            dic1[s] = 1

        if t in dic2:
            dic2[t] += 1
        else:
            dic2[t] = 1

pair = {}

for val1, cnt1 in dic1.items():
    val2 = - 1 / val1
    cnt2 = dic2.get(val1, 0)

    if val1 < val2:
        if (val1, val2) not in pair:
            pair[(val1, val2)] = (cnt1, cnt2)
    else:
        if (val2, val1) not in pair:
            pair[(val2, val1)] = (cnt2, cnt1)

all_cnt = 1
for _, y in pair.items():
    all_cnt *= pow(2, y[0], MOD) + pow(2, y[1], MOD) - 1
    all_cnt %= MOD


all_cnt *= pow(2, a_zero, MOD) + pow(2, b_zero, MOD) - 1
all_cnt %= MOD

all_cnt += both_zero
all_cnt %= MOD

print((all_cnt - 1) % MOD)

Submission status: Wrong Answer

Solution code:
import math

def heikatu(A,B):

    
    c = math.gcd(A,B)

    return (A//c,B//c)
 
 
def pow_r(x, n,mod=10**9+7):
    """
    O(log n)
    """
    if n == 0:  # exit case
        return 1
    if n % 2 == 0:  # standard case ① n is even
        return pow_r((x ** 2)%1000000007 , n // 2) % mod
    else:  # standard case ② n is odd
        return (x * pow_r((x ** 2)%1000000007, (n - 1) // 2) % mod) % mod
 
 
 
def resolve():
    N = int(input())
 
    
    km = dict()
    kp = dict()
    zero = [0,0]
    zerozero = 0
    for i in range(N):
        A,B = map(int,input().split())
 
        if A == 0 and B == 0:
            zerozero+=1

            continue
        
        if A == 0:
            B = abs(B)
        if B == 0:
            A = abs(A)

 
        if A <0:
            A *= -1
            B *= -1
        xx = heikatu(A,B)
 
 
 
        if B < 0:
            if not xx in km:
                km[xx]=0
            km[xx]+=1
        else:
            if not xx in kp:
                kp[xx]=0
            kp[xx]+=1

    ans = 1

    groups = []
    for (x,y),v in km.items():
        if (-y,x) in kp:
            groups.append((v,kp[(-y,x)]))
            del kp[(-y,x)]
        else:
            groups.append((v,0))

    for v in kp.values():
        groups.append((v,0))


    for i,j in groups:
        ans *= (pow_r(2,i)+pow_r(2,j)-1)%1000000007
        ans %= 1000000007



    print((ans+zerozero-1)%(10**9+7))       

resolve()

Submission status: Wrong Answer

Solution code:
import math

def heikatu(A,B):

    
    c = math.gcd(A,B)

    return (A//c,B//c)
 
 
def pow_r(x, n,mod=10**9+7):
    """
    O(log n)
    """
    if n == 0:  # exit case
        return 1
    if n % 2 == 0:  # standard case ① n is even
        return pow_r((x ** 2)%1000000007 , n // 2) % mod
    else:  # standard case ② n is odd
        return (x * pow_r((x ** 2)%1000000007, (n - 1) // 2) % mod) % mod
 
 
 
def resolve():
    N = int(input())
 
    
    km = dict()
    kp = dict()
    zero = [0,0]
    zerozero = 0
    for i in range(N):
        A,B = map(int,input().split())
 
        if A == 0 and B == 0:
            zerozero+=1

            continue
 

 
        if A <0:
            A *= -1
            B *= -1
        xx = heikatu(A,B)
 
 
 
        if B < 0:
            if not xx in km:
                km[xx]=0
            km[xx]+=1
        else:
            if not xx in kp:
                kp[xx]=0
            kp[xx]+=1

    ans = 1

    groups = []
    for (x,y),v in km.items():
        if (-y,x) in kp:
            groups.append((v,kp[(-y,x)]))
            del kp[(-y,x)]
        else:
            groups.append((v,0))

    for v in kp.values():
        groups.append((v,0))


    for i,j in groups:
        ans *= (pow_r(2,i)+pow_r(2,j)-1)%1000000007
        ans %= 1000000007



    print((ans+zerozero-1)%(10**9+7))       

resolve()

Submission status: Wrong Answer

Solution code:
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]

MOD = 1000000007

dic1 = {}
dic2 = {}
a_zero = 0
b_zero = 0
both_zero = 0

for a, b in AB:
    if a == 0 and b != 0:
        a_zero += 1
    elif a != 0 and b == 0:
        b_zero += 1
    elif a == 0 and b == 0:
        both_zero += 1
    else:
        s = a / b
        t = -b / a

        if s in dic1:
            dic1[s] += 1
        else:
            dic1[s] = 1

        if t in dic2:
            dic2[t] += 1
        else:
            dic2[t] = 1

pair = {}

for val1, cnt1 in dic1.items():
    val2 = - 1 / val1
    cnt2 = dic2.get(val1, 0)

    if val1 < val2:
        if (val1, val2) not in pair:
            pair[(val1, val2)] = (cnt1, cnt2)
    else:
        if (val2, val1) not in pair:
            pair[(val2, val1)] = (cnt2, cnt1)

all_cnt = 1
for _, y in pair.items():
    all_cnt *= pow(2, y[0], MOD) + pow(2, y[1], MOD) - 1
    all_cnt %= MOD


all_cnt *= pow(2, a_zero, MOD) + pow(2, b_zero, MOD) - 1
all_cnt %= MOD

all_cnt += both_zero
all_cnt %= MOD

print((all_cnt - 1) % MOD)

Submission status: Wrong Answer

Solution code:
import math

def heikatu(A,B):

    
    c = math.gcd(A,B)

    return (A//c,B//c)
 
 
def pow_r(x, n,mod=10**9+7):
    """
    O(log n)
    """
    if n == 0:  # exit case
        return 1
    if n % 2 == 0:  # standard case ① n is even
        return pow_r((x ** 2)%1000000007 , n // 2) % mod
    else:  # standard case ② n is odd
        return (x * pow_r((x ** 2)%1000000007, (n - 1) // 2) % mod) % mod
 
 
 
def resolve():
    N = int(input())
 
    
    km = dict()
    zero = [0,0]
    zerozero = 0
    for i in range(N):
        A,B = map(int,input().split())
 
        if A == 0 and B == 0:
            zerozero+=1
            continue
 

 
        if A <0:
            A *= -1
            B *= -1
        xx = heikatu(A,B)
 
 
 

        if not xx in km:
            km[xx]=0
        km[xx]+=1
    ans = 1

    for x,y in sorted(km.keys(),key = lambda x: x[1]):

        if km[(x,y)]==0:

            continue
        tmp = pow_r(2,km[(x,y)])
        km[(x,y)] = 0
        rev = (-y,x)
        if rev in km and km[rev]!=0:

            tmp+=pow_r(2,km[rev])-1
            tmp %= 1000000007
            km[rev]=0

        ans *= tmp
        ans %= 1000000007




    print((ans+zerozero-1)%(10**9+7))       

resolve()

Submission status: Wrong Answer

Solution code:
"""
https://sen-comp.hatenablog.com/entry/2020/05/18/010611
"""

N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]

MOD = 1000000007

dic1 = {}
dic2 = {}
a_zero = 0
b_zero = 0
both_zero = 0

for a, b in AB:
    if a == 0 and b != 0:
        a_zero += 1
    elif a != 0 and b == 0:
        b_zero += 1
    elif a == 0 and b == 0:
        both_zero += 1
    else:
        s = a / b
        t = -b / a

        if s in dic1:
            dic1[s] += 1
        else:
            dic1[s] = 1

        if t in dic2:
            dic2[t] += 1
        else:
            dic2[t] = 1

pair = {}

for val1, cnt1 in dic1.items():
    val2 = - 1 / val1
    cnt2 = dic2.get(val1, 0)

    if val1 < val2:
        if (val1, val2) not in pair:
            pair[(val1, val2)] = (cnt1, cnt2)
    else:
        if (val2, val1) not in pair:
            pair[(val2, val1)] = (cnt2, cnt1)

all_cnt = 1
for _, y in pair.items():
    all_cnt *= pow(2, y[0], MOD) + pow(2, y[1], MOD) - 1
    all_cnt = all_cnt % MOD


all_cnt *= pow(2, a_zero, MOD) + pow(2, b_zero, MOD) - 1
all_cnt = all_cnt % MOD

all_cnt += both_zero

print((all_cnt - 1) % MOD)

Submission status: Wrong Answer

Solution code:
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]

MOD = 1000000007

dic1 = {}
dic2 = {}
a_zero = 0
b_zero = 0
both_zero = 0

for a, b in AB:
    if a == 0 and b != 0:
        a_zero += 1
    elif a != 0 and b == 0:
        b_zero += 1
    elif a == 0 and b == 0:
        both_zero += 1
    else:
        s = a / b
        t = -b / a

        if s in dic1:
            dic1[s] += 1
        else:
            dic1[s] = 1

        if t in dic2:
            dic2[t] += 1
        else:
            dic2[t] = 1

pair = {}

for val1, cnt1 in dic1.items():
    val2 = - 1 / val1
    cnt2 = dic2.get(val1, 0)

    if val1 < val2:
        if (val1, val2) not in pair:
            pair[(val1, val2)] = (cnt1, cnt2)
    else:
        if (val2, val1) not in pair:
            pair[(val2, val1)] = (cnt2, cnt1)

all_cnt = 1
for _, y in pair.items():
    all_cnt *= 2 ** y[0] + 2 ** y[1] - 1
    all_cnt = all_cnt % MOD


all_cnt += both_zero

all_cnt *= 2 ** a_zero + 2 ** b_zero - 1
all_cnt = all_cnt % MOD

print(all_cnt - 1)

Submission status: Wrong Answer

Solution code:
import math
def heikatu(A,B):

    
    c = math.gcd(A,B)

    return (A//c,B//c)
 
 
def pow_r(x, n,mod=10**9+7):
    """
    O(log n)
    """
    if n == 0:  # exit case
        return 1
    if n % 2 == 0:  # standard case ① n is even
        return pow_r((x ** 2)%1000000007 , n // 2) % mod
    else:  # standard case ② n is odd
        return (x * pow_r((x ** 2)%1000000007, (n - 1) // 2) % mod) % mod
 
 
 
def resolve():
    N = int(input())
 
    kp = dict()
    km = dict()
    zero = [0,0]
    zerozero = 0
    for i in range(N):
        A,B = map(int,input().split())
 
        if A == 0 and B == 0:
            zerozero+=1
            continue
 

 
        if A <0:
            A *= -1
            B *= -1
        xx = heikatu(A,B)
 
 
 
        if B < 0:
            if not xx in km:
                km[xx]=0
            km[xx]+=1
        else:
            if not xx in kp:
                kp[xx]=0
            kp[xx]+=1
 
    tx = dict()
    if zero != [0,0]:
        zero.sort()
        tx[tuple(zero)] = 1
 
    for key in kp:
        A,B = key
        cou = kp[key]    
        if (B,-A) in km:
            tmp = (cou,km[(B,-A)])
            km.pop((B,-A))
        else:
            tmp = ((cou,0))
        
        tmp = tuple(sorted(tmp))
        if not tmp in tx:
            tx[tmp] = 0
        tx[tmp]+=1
 
    for key in km:
        if not (km[key],0) in tx:
            tx[(km[key],0)]=0    
        tx[(km[key],0)]+=1
 
    ans = 1
    mod = 1000000007
 
    for a,b in tx:
        xxx = 0
        if a != 0:
            xxx=(xxx+pow_r(2,a)) %mod
        if b != 0:
            xxx=(xxx+pow_r(2,b)) %mod
        if a !=0 and b!=0:
            xxx-=1
        xxx = pow_r(xxx,tx[(a,b)]) 
        ans = (ans*xxx) % mod
 
 
    ans = (ans+mod-1) % mod 
 
    print(ans)       

resolve()

Submission status: Wrong Answer

Solution code:
import math
def heikatu(A,B):

    
    c = math.gcd(A,B)

    return (A//c,B//c)
 
 
def pow_r(x, n,mod=10**9+7):
    """
    O(log n)
    """
    if n == 0:  # exit case
        return 1
    if n % 2 == 0:  # standard case ① n is even
        return pow_r((x ** 2)%1000000007 , n // 2) % mod
    else:  # standard case ② n is odd
        return (x * pow_r((x ** 2)%1000000007, (n - 1) // 2) % mod) % mod
 
 
 
def resolve():
    N = int(input())
 
    kp = dict()
    km = dict()
    zero = [0,0]
    zerozero = 0
    for i in range(N):
        A,B = map(int,input().split())
 
        if A == 0 and B == 0:
            zerozero+=1
            continue
 
        if A == 0:
            zero[0]+=1
            continue
        if B == 0:
            zero[1]+=1
            continue
 
        if A <0:
            A *= -1
            B *= -1
        xx = heikatu(A,B)
 
 
 
        if B < 0:
            if not xx in km:
                km[xx]=0
            km[xx]+=1
        else:
            if not xx in kp:
                kp[xx]=0
            kp[xx]+=1
 
    tx = dict()
    if zero != [0,0]:
        zero.sort()
        tx[tuple(zero)] = 1
 
    for key in kp:
        A,B = key
        cou = kp[key]    
        if (B,-A) in km:
            tmp = (cou,km[(B,-A)])
            km.pop((B,-A))
        else:
            tmp = ((cou,0))
        
        tmp = tuple(sorted(tmp))
        if not tmp in tx:
            tx[tmp] = 0
        tx[tmp]+=1
 
    for key in km:
        if not (km[key],0) in tx:
            tx[(km[key],0)]=0    
        tx[(km[key],0)]+=1
 
    ans = 1
    mod = 1000000007
 
    for a,b in tx:
        xxx = 0
        if a != 0:
            xxx=(xxx+pow_r(2,a)) %mod
        if b != 0:
            xxx=(xxx+pow_r(2,b)) %mod
        if a !=0 and b!=0:
            xxx-=1
        xxx = pow_r(xxx,tx[(a,b)]) 
        ans = (ans*xxx) % mod
 
 
    ans = (ans+mod-1) % mod 
 
    print(ans)       

resolve()