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:
n = int(input())
mod = 10**9 + 7
cou = 0
pdic = {}
kan = []
betu = [0,0,0]

for i in range(n):
    a , b = map(int,input().split())
    if a*b != 0:
        p = a/b
        q = -b/a
        if pdic.get(q,-1) != -1:
            kan[pdic[q]][1] += 1
        elif pdic.get(p,-1) == -1:
            pdic[p] = cou
            kan.append([1,0])
            cou += 1
        elif pdic.get(p,-1) != -1:
            kan[pdic[p]][0] += 1
    elif a*b == 0:
        if a == 0 and b == 0:
            betu[2] += 1
        elif a == 0:
            betu[0] += 1
        elif b == 0:
            betu[1] += 1
        
        
ans = 1
for i in range(len(kan)):
    ans *= (pow(2,kan[i][0],mod) + pow(2,kan[i][1],mod) - 1) % mod
    ans %= mod
ans *= (pow(2,betu[0],mod) + pow(2,betu[1],mod) - 1) % mod
print((ans-1+betu[2])%mod)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
A = 0
B = 0
Z = 0
C = {}
m = 1000000007

def mypow(dummy, num):
    ans = 1
    for i in range(num):
        ans = (ans*2)%1000000007
    return ans

def rNum(a, b):
    g = math.gcd(a, b)
    if a >0 and b <0:
        return (-1*(a//g), -1*(b//g))
    else:
        return (a//g, b//g)

def inv(rnum):
    a,b = rnum
    if a <0 and b >0:
        return (-1*b, -1*a)
    else:
        return (b, a)
        

for i in range(N):
    a, b = map(int, input().split())
    
    if a == 0 and b==0:
        Z += 1
        continue
    elif a==0:
        A += 1
        continue
    elif b==0:
        B +=1
        continue
    
    r = rNum(a, b)
    if r in C.keys():
        C[r] +=1
    else: C[r] = 1


used = set()
ans = 1
ans *= (mypow(2, A) + mypow(2, B) -1)%m



for c in C.keys():
    if c in used: continue
    a, b = c
    a *= -1
    r = rNum(b, a)
    if r in C.keys():
        if c == inv(c): continue
        
        used.add(r)
        score = mypow(2, C[c]) + mypow(2, C[r])- 1
        ans = (ans * score)%m

    else:
        ans = (ans*mypow(2, C[c]))%m

ans += Z

print(ans-1)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, cos, radians, pi, sin, gcd
from operator import mul
from functools import reduce
from operator import mul


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]

mod = 1000000007

n = I()
D = defaultdict(int)
A = []
B = []
F = []
pow2 = [1] * (n + 1)
for i in range(1, n + 1):
    pow2[i] = pow2[i - 1] * 2 % mod

ans = 1
cnt1 = 0
cnt2 = 0
for i in range(n):
    a, b = LI()
    flg = 0
    if a * b < 0:
        flg = 1
    a = abs(a)
    b = abs(b)
    g = gcd(a, b)
    if g:
        a = a // g
        b = b // g
    A += [a]
    B += [b]
    F += [flg]
    if a == 0:
        cnt1 += 1
    elif b == 0:
        cnt2 += 1
    else:
        D[(flg, a, b)] += 1

visited = defaultdict(int)
for j in range(n):
    fi, ai, bi = F[j], A[j], B[j]
    if ai == 0 or bi == 0:
        continue
    if visited[(fi, ai, bi)]:
        continue
    visited[(fi, ai, bi)] = 1
    visited[(fi ^ 1, bi, ai)] = 1
    ans = ans * (pow2[D[(fi, ai, bi)]] + pow2[D[(fi ^ 1, bi, ai)]] - 1) % mod

print(ans * (pow2[cnt1] + pow2[cnt2] - 1) % mod - 1)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
A=[]
AA=[]
B=[]
C=[]
X=[]
mod=10**18+7
for i in range(n):
  a,b=map(int,input().split())
  if a<0:
    a=a*-1
    b=b*-1
  if a*b>0:
    A.append(b*pow(a,mod-2,mod)%mod)
  elif a*b<0:
    AA.append(a*pow((-b),mod-2,mod)%mod)
  else:
    if a==0 and b==0:
      X.append(i)
    elif a==0:
      B.append(i)
    else:
      C.append(i)
mod = 10**9+7
D=collections.Counter(A)
DD=collections.Counter(AA)
E=set(list(D)+list(DD))
a=1
for i in E:
  a=(a*(2**D[i]+2**DD[i]-1))%mod
  print(a)
a=(a*(2**len(B)+2**len(C)-1)-1)%mod
print((a+len(X))%mod)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from collections import *

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

N = int(input())
zero = 0
cnt = defaultdict(int)
MOD = 10**9+7

for _ in range(N):
    A, B = map(int, input().split())
    
    if A==0 or B==0:
        zero += 1
    elif A>0 and B>0:
        G = gcd(A, B)
        A //= G
        B //= G
        cnt[(A, B)] += 1
    elif A>0 and B<0:
        B *= -1
        G = gcd(A, B)
        A //= G
        B //= G
        cnt[(-A, B)] += 1
    elif A<0 and B>0:
        A *= -1
        G = gcd(A, B)
        A //= G
        B //= G
        cnt[(-A, B)] += 1
    else:
        A *= -1
        B *= -1
        G = gcd(A, B)
        A //= G
        B //= G
        cnt[(A, B)] += 1

s = set()
ans = 1

for k in cnt.keys():
    if k in s:
        continue
    
    k2 = (-k[1], k[0])
    
    if k2[0]<0 and k2[1]<0:
        k2 = (-k2[0], -k2[1])
    elif k2[0]>0 and k2[1]<0:
        k2 = (-k2[0], -k2[1])
        
    a = cnt[k]
    
    if k2 not in cnt:
        ans *= pow(2, a, MOD)
        ans %= MOD
    else:
        b = cnt[k2]
        ans *= pow(2, a, MOD)+pow(2, b, MOD)-1
        ans %= MOD
        s.add(k2)

if zero>=1:
    ans *= 2
    ans %= MOD
    
ans -= 1
ans %= MOD

print(ans)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
A = 0
B = 0
Z = 0
C = {}
m = 1000000007

def mypow(dummy, num):
    ans = 1
    for i in range(num):
        ans = (ans*2)%1000000007
    return ans

def rNum(a, b):
    g = math.gcd(a, b)
    if a >0 and b <0:
        return (-1*(a//g), -1*(b//g))
    else:
        return (a//g, b//g)

def inv(rnum):
    a,b = rnum
    if a >0 and b <0:
        return (-1*b, -1*a)
    else:
        return (b, a)
        

for i in range(N):
    a, b = map(int, input().split())
    
    if a == 0 and b==0:
        Z += 1
        continue
    elif a==0:
        A += 1
        continue
    elif b==0:
        B +=1
        continue
    
    r = rNum(a, b)
    if r in C.keys():
        C[r] +=1
    else: C[r] = 1


used = set()
ans = 1
ans *= (mypow(2, A) + mypow(2, B) -1)%m



for c in C.keys():
    if c in used: continue
    a, b = c
    a *= -1
    r = rNum(b, a)
    if r in C.keys():
        if c == inv(c): continue
        
        used.add(r)
        score = mypow(2, C[c]) + mypow(2, C[r])- 1
        ans = (ans * score)%m

    else:
        ans = (ans*mypow(2, C[c]))%m

ans += Z

print(ans-1)

Submission status: Wrong Answer

Solution code:
import collections
import math

N=int(input())
posi=[]
nega=[]
mod=1000000007
power=[1]*(N+1)
zero=0

for i in range(1,N+1):
    power[i]=power[i-1]*2%mod
    
for i in range(N):
    a,b=map(int,input().split())
    if a==0 and b==0:
        zero+=1
    elif a==0:
        posi.append((0,1))
    elif b==0:
        nega.append((0,1))
    elif a/b>=0:
        posi.append((a/math.gcd(a,b),b/math.gcd(a,b)))
    else:
        nega.append((abs(b/math.gcd(a,b)),abs(a/math.gcd(a,b))))

m=N-zero
cp=collections.Counter(posi)
cn=collections.Counter(nega)

x=1
y=1


for pp in cp.keys():
    if pp in cn.keys():
        p=cp[pp]
        n=cn[pp]
        powp=power[p]
        pown=power[n]
        e=(powp-1)*(pown-1)%mod
        f=(powp+pown-1)%mod
        x=x*(e+f)%mod
        y=y*f%mod
        m-=(p+n)
        
ans=power[N-zero]-1-power[m]*(x-y)%mod
print((ans+zero)%mod)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
c = 1
pp = []
mm = []
for i in range(n):
  a,b = map(int,input().split())
  if a*b == 0:
    c += 1
  else:
    pp.append(a/b)
    
mod = 10**9+7
c %= mod
p = Counter(pp)
r = 1
s = set()

for i in p.keys():
  if i in s:
    continue
  ans = p[i]
  chk = p[-1/i]
  r *= (pow(2,ans,mod)-1+pow(2,chk,mod))%mod
  r %= mod
  s.add(-1/i)
print((r*c-1)%mod)

Submission status: Wrong Answer

Solution code:
import collections
import math

N=int(input())
posi=[]
nega=[]
mod=1000000007
power=[1]*(N+1)
zero=0

for i in range(1,N+1):
    power[i]=power[i-1]*2%mod
    
for i in range(N):
    a,b=map(int,input().split())
    if a==0 and b==0:
        zero+=1
    elif a==0:
        posi.append((0,1))
    elif b==0:
        nega.append((1,0))
    elif a/b>=0:
        posi.append((a/math.gcd(a,b),b/math.gcd(a,b)))
    else:
        nega.append((abs(b/math.gcd(a,b)),abs(a/math.gcd(a,b))))

m=N-zero
cp=collections.Counter(posi)
cn=collections.Counter(nega)

x=1
y=1


for pp in cp.keys():
    if pp in cn.keys():
        p=cp[pp]
        n=cn[pp]
        powp=power[p]
        pown=power[n]
        e=(powp-1)*(pown-1)%mod
        f=(powp+pown-1)%mod
        x=x*(e+f)%mod
        y=y*f%mod
        m-=(p+n)
        
ans=power[N-zero]-1-power[m]*(x-y)%mod
print((ans+zero)%mod)

Submission status: Wrong Answer

Solution code:
import collections
import math

N=int(input())
posi=[]
nega=[]
mod=1000000007
power=[1]*(N+1)
zero=0

for i in range(1,N+1):
    power[i]=power[i-1]*2%mod
    
for i in range(N):
    a,b=map(int,input().split())
    if a==0 and b==0:
        zero+=1
    elif a==0:
        posi.append((a,b))
    elif b==0:
        nega.append((b,a))
    elif a/b>=0:
        posi.append((a/math.gcd(a,b),b/math.gcd(a,b)))
    else:
        nega.append((abs(b/math.gcd(a,b)),abs(a/math.gcd(a,b))))

m=N-zero
cp=collections.Counter(posi)
cn=collections.Counter(nega)

x=1
y=1


for pp in cp.keys():
    if pp in cn.keys():
        p=cp[pp]
        n=cn[pp]
        powp=power[p]
        pown=power[n]
        e=(powp-1)*(pown-1)%mod
        f=(powp+pown-1)%mod
        x=x*(e+f)%mod
        y=y*f%mod
        m-=(p+n)
        
ans=power[N-zero]-1-power[m]*(x-y)%mod
print((ans+zero)%mod)

Submission status: Wrong Answer

Solution code:
import collections
import math

N=int(input())
posi=[]
nega=[]
mod=1000000007
power=[1]*(N+1)
zero=0

for i in range(1,N+1):
    power[i]=power[i-1]*2%mod
    
for i in range(N):
    a,b=map(int,input().split())
    if a==0 and b==0:
        zero+=1
    elif a==0:
        posi.append((a,b))
    elif b==0:
        nega.append((b,a))
    elif a/b>=0:
        posi.append((a/math.gcd(a,b),b/math.gcd(a,b)))
    else:
        nega.append((abs(b/math.gcd(a,b)),abs(a/math.gcd(a,b))))

m=N-zero
cp=collections.Counter(posi)
cn=collections.Counter(nega)
print(cp)
print(cn)

x=1
y=1


for pp in cp.keys():
    if pp in cn.keys():
        p=cp[pp]
        n=cn[pp]
        powp=power[p]
        pown=power[n]
        e=(powp-1)*(pown-1)%mod
        f=(powp+pown-1)%mod
        x=x*(e+f)%mod
        y=y*f%mod
        m-=(p+n)
        
ans=power[N-zero]-1-power[m]*(x-y)%mod
print((ans+zero)%mod)

Submission status: Wrong Answer

Solution code:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

dic=defaultdict(int)
zero=[0,0]
kasu=0
for i in range(n):
    a,b=ab[i]
    if a==0 and b==0:
        kasu+=1
    elif a==0:
        zero[0]+=1
    elif b==0:
        zero[1]+=1
    else:
        dic[a/b]+=1

anslst=[]
lst=list(dic.items())
ans=1

for i in range(len(lst)):
    num,m=lst[i]
    tmp=1
    if dic[num]!=0:
        tmp=pow(2,m,mod)-1+pow(2,dic[-1/num],mod)-1+1
    dic[-1/num]=0
    ans*=tmp
    ans%=mod


ans*=pow(2,zero[0],mod)-1+pow(2,zero[1],mod)-1+1

ans=(ans-1+kasu)%mod
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from collections import *

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

N = int(input())
zero = 0
cnt = defaultdict(int)
MOD = 10**9+7

for _ in range(N):
    A, B = map(int, input().split())
    
    if A==0 or B==0:
        zero += 1
    elif A>0 and B>0:
        G = gcd(A, B)
        A //= G
        B //= G
        cnt[(A, B)] += 1
    elif A>0 and B<0:
        B *= -1
        G = gcd(A, B)
        A //= G
        B //= G
        cnt[(-A, B)] += 1
    elif A<0 and B>0:
        A *= -1
        G = gcd(A, B)
        A //= G
        B //= G
        cnt[(-A, B)] += 1
    else:
        A *= -1
        B *= -1
        G = gcd(A, B)
        A //= G
        B //= G
        cnt[(A, B)] += 1

s = set()
ans = 1

for k in cnt.keys():
    if k in s:
        continue
    
    k2 = (-k[1], k[0])
    
    if k2[0]<0 and k2[1]<0:
        k2 = (-k2[0], -k2[1])
    elif k2[0]>0 and k2[1]<0:
        k2 = (-k2[0], -k2[1])
        
    a = cnt[k]
    
    if k2 not in cnt:
        ans *= pow(2, a, MOD)
        ans %= MOD
    else:
        b = cnt[k2]
        ans *= pow(2, a, MOD)+pow(2, b, MOD)-1
        ans %= MOD
        s.add(k2)

ans *= 2**zero
ans %= MOD
ans -= 1
ans %= MOD

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = 0
pp = []
mm = []
for i in range(n):
  a,b = map(int,input().split())
  if a*b == 0:
    c += 1
  else:
    pp.append(a/b)
    
mod = 10**9+7
from collections import Counter
p = Counter(pp)
r = 1
s = set()
for i in p.keys():
  if i in s:
    continue
  ans = p[i]
  chk = p[-1/i]
  r *= (pow(2,ans,mod)-1+pow(2,chk,mod))%mod
  r %= mod
  s.add(-1/i)
print(r*(c+1)%mod-1)

Submission status: Wrong Answer

Solution code:
from fractions import Fraction
import math

n = int(input())


ab = []
ba = []

a0 = 0
b0 = 0
ab0 = 0

for i in range(n):
    a, b = map(int, input().split())
    if a != 0 and b != 0:
        ab.append(Fraction(a, b))
        ba.append(Fraction(-b, a))
    elif a == 0 and b == 0:
        ab0 += 1
    elif a == 0 and b != 0:
        a0 += 1
    elif a != 0 and b == 0:
        b0 += 1


d_ab = dict()
d_ba = dict()

d_done = dict()

for i in range(len(ab)):
    cur = ab[i]

    if cur in d_ab:
        d_ab[cur] += 1
    else:
        d_ab[cur] = 1

    cur = ba[i]

    if cur in d_ba:
        d_ba[cur] += 1
    else:
        d_ba[cur] = 1

mod = 1000000007

ans = 1

for k, v in d_ab.items():
    x = v
    if k in d_ba:
        if k in d_done:
            continue
        else:
            y = d_ba[k]
            kake = 0
            kake += ((2**x) % mod + (2**y) % mod - 1)
            ans *= kake
            ans %= mod
            d_done[Fraction(-k.denominator, k.numerator)] = 1
    else:
        kake = (2**x) % mod
        ans *= kake
        ans %= mod

ans *= ((2**ab0) % mod)
ans %= mod
ans *= ((2**a0) % mod+(2**b0) % mod-1)
ans %= mod

print(ans-1)

Submission status: Wrong Answer

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

bad_li = sum([[(i,j) for i in range(j+1, n) if li[i][0]*li[j][0]+li[i][1]*li[j][1]==0] for j in range(n)], [])
ans=2**n-1
add_set = set(bad_li)
for cnt in range(n):
    if cnt%2==0:
        ans -= sum([2**(n-len(s)) for s in add_set])
    else:
        ans += sum([2**(n-len(s)) for s in add_set])
    length = len(bad_li)
    add_set = set()
    bad_set = set(bad_li)
    for i in range(length):
        for j in range(i, length):
            a, b = set(bad_li[i]), set(bad_li[j])
            if a!=b and (tuple(a|b) not in bad_set):
                add_set.add(tuple(a|b))
    
    bad_li.extend(list(add_set))
    if len(add_set)==0:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
def resolve():
    import math
    from fractions import Fraction
    mod = 10**9 + 7
    n = int(input())
    dic1 = {}
    dic1["all0"] = 0
    dic1["b0"] = 0
    dic1[Fraction(0,1)] = 0
    for i in range(n):
        a, b = map(int, input().split())
        if a == 0 and b == 0:
            dic1["all0"] += 1
        elif b == 0:
            dic1["b0"] += 1
        else:
            c = math.gcd(a,b)
            a = a//c
            b = b//c
            if Fraction(a,b) in dic1:
                dic1[Fraction(a,b)] += 1
            else:
                dic1[Fraction(a,b)] = 1
 
    ans = 1
    all0 = 0
    for i in dic1:
        if i == "all0":
            all0 = dic1["all0"]
            continue
        elif i == "b0":
            counter = Fraction(0, 1)
            ans *= (2 ** dic1[i] + 2 ** dic1[counter] - 1)
            ans %= mod
            dic1[i] = 0
            dic1[counter] = 0
        elif i == Fraction(0,1):
            counter = "b0"
            ans *= (2 ** dic1[i] + 2 ** dic1[counter] - 1)
            ans %= mod
            dic1[i] = 0
            dic1[counter] = 0
 
        elif -1 * (Fraction(1,i)) in dic1:
            counter = -1 * (Fraction(1,i))
            ans *= (2**dic1[i]+2**dic1[counter]-1)
            ans %= mod
            dic1[i] = 0
            dic1[counter] = 0
        else:
            ans *= (dic1[i]+1)
            ans %= mod
    ans += all0
    print(ans%mod-1)
resolve()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import bisect

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

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


both_zero=0
D=defaultdict(int)
D01=0
D10=0
for a,b in L:
    if a==0 and b==0:
        both_zero+=1
        continue
    
    if b==0:
        D10+=1
        continue
    elif a==0:
        D01+=1
        continue
    g=gcd(abs(a),abs(b))
    prefix= 1 if a*b>=0 else -1
    D[(prefix*abs(a/g),abs(b/g))]+=1


ans=1
MOD=10**9+7

used_key=set()
for key,val in D.items():
    if key in used_key:
        continue
    if key[0]*key[1]<0:
        rev_key=(abs(key[1]),abs(key[0]))
    else:
        rev_key=(-abs(key[1]),abs(key[0]))
    if rev_key not in D.keys():
        ans*=pow(2,val,MOD)
        continue
    rev_val = D[rev_key]
    ans*=(((pow(2,val,MOD)-1)+(pow(2,rev_val,MOD))-1)+1)
    used_key.add(rev_key)
    used_key.add(key)

ans*=(((pow(2,D01,MOD)-1)+(pow(2,D10,MOD))-1)+1)
ans*=(both_zero+1)
print((ans+MOD-1)%MOD)

Submission status: Wrong Answer

Solution code:

def resolve():
    import math
    from fractions import Fraction
    mod = 10**9 + 7
    n = int(input())
    dic1 = {}
    dic1["all0"] = 0
    dic1["b0"] = 0
    dic1[Fraction(0,1)] = 0
    for i in range(n):
        a, b = map(int, input().split())
        if a == 0 and b == 0:
            dic1["all0"] += 1
        elif b == 0:
            dic1["b0"] += 1
        else:
            c = math.gcd(a,b)
            a = a//c
            b = b//c
            if Fraction(a,b) in dic1:
                dic1[Fraction(a,b)] += 1
            else:
                dic1[Fraction(a,b)] = 1

    ans = 1
    all0 = 0
    for i in dic1:
        if i == "all0":
            all0 = dic1["all0"]
            continue
        elif i == "b0":
            counter = Fraction(0, 1)
            ans *= (2 ** dic1[i] + 2 ** dic1[counter] - 1)
            ans %= mod
            dic1[i] = 0
            dic1[counter] = 0
        elif i == Fraction(0,1):
            counter = "b0"
            ans *= (2 ** dic1[i] + 2 ** dic1[counter] - 1)
            ans %= mod
            dic1[i] = 0
            dic1[counter] = 0

        elif -1 * (Fraction(1,i)) in dic1:
            counter = -1 * (Fraction(1,i))
            ans *= (2**dic1[i]+2**dic1[counter]-1)
            ans %= mod
            dic1[i] = 0
            dic1[counter] = 0
        else:
            ans *= (dic1[i]+1)
            ans %= mod
    print(ans%mod-1)


resolve()

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict as dd
from math import gcd
input = sys.stdin.readline
N = int(input())
mod = 10 ** 9 + 7
d = dd(int)
a = [tuple(map(int, input().split())) for _ in range(N)]
z = 0
for x, y in a:
  g = gcd(abs(x), abs(y))
  if y < 0:
    x, y = -x, -y
  if (x, y) == (0, 0):
    N -= 1
    z += 1
    continue
  d[(x // g, y // g)] += 1
res = 1
u = 0
itr = list(d.keys())
#print(itr)
for x, y in itr:
  t = 0
  if (x, y) == (0, 1):
    t = d[(1, 0)]
  elif (x, y) == (1, 0):
    t = d[(0, 1)]
  else:
    t = d[(y * pow(-1, int(x < 0) + 1), abs(x))]
  if t == 0: u += d[(x, y)]
for x, y in itr:
  t = 0
  if (x, y) == (0, 1):
    t = d[(1, 0)]
  elif (x, y) == (1, 0):
    t = d[(0, 1)]
  else:
    t = d[(y * pow(-1, int(x < 0) + 1), abs(x))]
  #print(t, d, (x, y))
  if t:
    v = 0
    v += pow(2, d[(x, y)], mod) - 1
    v %= mod
    v += pow(2, t, mod) - 1
    v %= mod
    v += 1
    v %= mod
    res *= v
    res %= mod
    #print(res, v)
  d[(x, y)] = 0
#print(itr, u, res, z)
print(res * pow(2, u, mod) - 1 + z % mod)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict
dic1 = defaultdict(int)
dic2 = defaultdict(int)
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
mod = 10**9+7
def pow(n,p,mod=10**9+7): #繰り返し二乗法(nのp乗)
    res = 1
    while p > 0:
        if p % 2 == 0:
            n = n ** 2 % mod
            p //= 2
        else:
            res = res * n % mod
            p -= 1
    return res % mod
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
def lcm(a,b):
    return (a//gcd(a,b)*b)
def to_standard_form(a, b):
    if a == 0:
        return (0, 1)
    g = gcd(a, b)
    a //= g
    b //= g
    if a < 0:
        return (-a, -b)
    return (a, b)
n = int(readline())
zero = 0
for i in range(n):
    a,b= map(int,readline().split())
    plamai = 1 if a*b > 0 else 0
    a,b = to_standard_form(a,b)
    if a == b == 0:
        zero += 1
    elif b <= 0:
        dic2[(a,b)] += 1
    else:
        dic1[(b,-a)] += 1
        dic2[(b,-a)] += 0

ans = 1
for key,cnt in dic2.items():
    res = dic1[key]
    x = pow(2,cnt)+pow(2,res)
    ans *= x-1
    ans %= mod
print(ans-1+zero)

Submission status: Wrong Answer

Solution code:
import math
mod = 1000000007
D = {}
X = []
zero = 0
N = int(input())
for i in range(N):
    a,b = map(int,input().split())
    if (a,b) == (0,0):
        zero += 1
        continue
    if a < 0 :
        a = -a
        b = -b
    if a == 0:
        b = 1
    else:
        g = math.gcd(a,b)
        a = a//g
        b = b//g
    c = b
    d = -a
    if c < 0:
        c = -c
        d = -d    
    if (a,b) in X:
        D[(a,b)] += 1
    else:
        D[(a,b)] = 1
        X.append((a,b))
n = N - zero
A = []
for (a,b) in X:
    c = b
    d = -a
    if c < 0:
        c = -c
        d = -d
    x = D[(a,b)]
    y = 0
    if [c,d] in X:
        y = D[(c,d)]
        X.remove((c,d))
    if y > 0:
        A.append([x,y])
        n = n - x - y
ans = 1
for [x,y] in A:
    z = (2**x + 2**y - 1)%mod
    ans *= z
    ans % mod
z = 2**n % mod
ans *= z
ans -= 1
ans %= mod
ans += zero
ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import bisect

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

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


both_zero=0
D=defaultdict(int)
for a,b in L:
    if a==0 and b==0:
        both_zero+=1
        continue
    
    if b==0:
        D[(1,0)]+=1
        continue
    g=gcd(abs(a),abs(b))
    prefix= 1 if a*b>=0 else -1
    D[(prefix*abs(a/g),abs(b/g))]+=1


ans=1
MOD=10**9+7

used_key=set()
for key,val in D.items():
    if key in used_key:
        continue
    if key[0]*key[1]<0:
        rev_key=(abs(key[1]),abs(key[0]))
    else:
        rev_key=(-abs(key[1]),abs(key[0]))
    if rev_key not in D.keys():
        ans*=pow(2,val,MOD)
        continue
    rev_val = D[rev_key]
    ans*=(((pow(2,val,MOD)-1)+(pow(2,rev_val,MOD))-1)+1)
    used_key.add(rev_key)
    used_key.add(key)

ans*=(both_zero+1)
print((ans+MOD-1)%MOD)

Submission status: Wrong Answer

Solution code:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

dic=defaultdict(int)
zero=[0,0]
kasu=0
for i in range(n):
    a,b=ab[i]
    if a==0 and b==0:
        kasu+=1
    elif a==0:
        zero[0]+=1
    elif b==0:
        zero[1]+=1
    else:
        dic[a/b]+=1

anslst=[]
lst=list(dic.items())
ans=1

for i in range(len(lst)):
    num,m=lst[i]
    tmp=1
    if dic[num]!=0:
        tmp=pow(2,m,mod)-1+pow(2,dic[-1/num],mod)-1+1
        dic[-1/num]=0
    ans*=tmp
    ans%=mod


ans*=pow(2,zero[0],mod)-1+pow(2,zero[1],mod)-1+1

ans=(ans-1+kasu)%mod
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
sin_dic = {}
import math
mod = 1000000007
INF = 10 ** 15

zero_num = 0
for i in range(N):
    a, b = list(map(int, input().split()))
    if a == 0 and b == 0:
        zero_num += 1
        continue
    if a == 0:
        b = -1
        #asin = INF
    elif b == 0:
        a = 1
    else:
        c = math.gcd(a, b)
        a, b = a//c, b//c
        if a < 0 and b < 0:
            a, b = -a, -b
        elif a < 0 and b > 0:
            a, b = -a, -b
    if (a,b) in sin_dic:
        sin_dic[(a, b)].append(i)
    else:
        sin_dic[(a, b)] = [i]

ans = 1
skip_dic = {}
for (key, _key) , values in sin_dic.items():
    if (key, _key) in skip_dic:
        continue
    oth_len = 0
    norm_len = 0
    norm_len += len(values)
    if (-key, -_key) in sin_dic:
        norm_len += len(sin_dic[(-key, -_key)])
    if (_key, -key) in sin_dic:
        oth_len += len(sin_dic[(_key, -key)])
    if (-_key, key) in sin_dic:
        oth_len += len(sin_dic[(-_key, key)])

    p = pow(2, oth_len, mod) - 1 + pow(2, norm_len, mod)
    ans = (ans * p) % mod
    skip_dic[(_key, -key)] = True
    skip_dic[(-_key, key)] = True
    skip_dic[(-_key, -key)] = True
print( (ans-1 + zero_num) % mod)

Submission status: Wrong Answer

Solution code:
from sys import stdin, setrecursionlimit


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


def main():
    mod = 10 ** 9 + 7
    input = stdin.buffer.readline
    n = int(input())
    p = []
    m = []

    zz = 0

    for _ in range(n):
        a, b = map(int, input().split())
        if a != 0 and b != 0:
            g = gcd(a, b)
            f = b / a
            if b / a < 0:
                m.append(-(a // g) / (b // g))
            elif f > 0:
                p.append((b // g) / (a // g))
        elif a == 0 and b == 0:
            zz += 1
        elif a == 0:
            m.append(0)
        elif b == 0:
            p.append(0)

    g_p = {}
    for k in p:
        if k in g_p:
            g_p[k] += 1
        else:
            g_p[k] = 1
    g_m = {}
    for k in m:
        if k in g_m:
            g_m[k] += 1
        else:
            g_m[k] = 1

    ans = 1

    for k in g_p:
        if k in g_m:
            ans *= (2 ** g_p[k] + 2 ** g_m[k] - 1)
        else:
            ans *= 2 ** g_p[k]
        ans %= mod
    for k in g_m:
        if not (k in g_p):
            ans *= 2 ** g_m[k]
            ans %= mod
    print((ans + zz - 1) % mod)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin, setrecursionlimit
from collections import defaultdict
from math import gcd

setrecursionlimit(10 ** 9)
INF = 1 << 60


def input():
    return stdin.readline().strip()


MOD = 1000000007
N = int(input())
d = defaultdict(int)
zeros = 0
for i in range(N):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        zeros += 1
    else:
        g = gcd(a, b)
        a //= g
        b //= g
        if a < 0:
            a *= -1
            b *= -1
        d[(a, b)] += 1


ans = 1
free = 0
keys = sorted(d.keys())
for a, b in keys:
    n = d[(a, b)]
    if b >= 0:
        if (b, -a) in d:
            m = d[(b, -a)]
            ans = ans * (pow(2, n, MOD) + pow(2, m, MOD) - 1) % MOD
        else:
            free += n
    else:
        if (-b, a) not in d:
            free += n

ans = (ans * pow(2, free, MOD) + zeros - 1) % MOD
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import math
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10**8)
INF = float("inf")

MOD = 1000000007  # type: int


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


def solve(N: int, A: "List[int]", B: "List[int]"):
    # 直交するイワシは選べない
    # 順にイワシを見てグループを探す。

    d = Counter()
    for i, (a, b) in enumerate(zip(A, B)):
        if a == 0:
            if b > 0:
                d[(0, 1)] += 1
            elif b < 0:
                d[(0, -1)] += 1
            else:
                d[(0, 0)] += 1
        else:
            aa = a//GCD(a, b)
            bb = b//GCD(a, b)
            if aa < 0:
                aa = -aa
                bb = -bb
            d[(aa, bb)] += 1
    # print(d)
    ans = 1
    for a, b in d:
        x, y = b, -a
        if x < 0:
            x = -x
            y = -y
        if d[(x, y)] == 0 or (a, b) == (0, 0):
            ans *= pow(2, d[(a, b)], MOD)
            ans %= MOD
            continue

        else:
            buf = pow(2, d[(a, b)], MOD)
            buf += pow(2, d[(x, y)], MOD)
            buf -= 1
            buf %= MOD
            # print(buf)
            ans *= buf
            ans %= MOD
            d[(x, y)] = 0
            d[(a, b)] = 0

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