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:
from collections import Counter
import sys
import math
from functools import cmp_to_key

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)


def main():
    n = int(input())
    p = [tuple(map(int, input().split())) for i in range(n)]
    a = {}
    b = {}
    c = 0
    for x, y in p:
        if x == y == 0:
            c += 1
            continue
        if y == 0:
            if x > 0:
                a[(0, 1)] = a.get((0, 1), 0) + 1
            else:
                b[(0, 1)] = b.get((0, 1), 0) + 1

        g = math.gcd(x, y)
        if x * y > 0:
            x = abs(x)
            y = abs(y)
            a[(x//g, y//g)] = a.get((x//g, y//g), 0) + 1
        else:
            x = abs(x)
            y = abs(y)
            b[(y//g, x//g)] = b.get((y//g, x//g), 0) + 1

    ans = 1
    s = 0
    for k, v in a.items():
        if k in b:
            s += v + b[k]
            ans *= pow(2, v) + pow(2, b[k]) - 1
            ans %= mod
    ans *= pow(2, n - s - c, mod)
    print((ans - 1 + c) % mod)

main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
import math
from functools import cmp_to_key

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)


def main():
    n = int(input())
    p = [tuple(map(int, input().split())) for i in range(n)]
    a = {}
    b = {}
    c = 0
    for x, y in p:
        if x == y == 0:
            c += 1
            continue
        if y == 0:
            if x > 0:
                a[(0, 1)] = a.get((0, 1), 0) + 1
            else:
                b[(0, 1)] = b.get((0, 1), 0) + 1

        g = math.gcd(x, y)
        if x * y > 0:
            x = abs(x)
            y = abs(y)
            a[(x//g, y//g)] = a.get((x//g, y//g), 0) + 1
        else:
            x = abs(x)
            y = abs(y)
            b[(y//g, x//g)] = b.get((y//g, x//g), 0) + 1

    ans = 1
    s = 0
    for k, v in a.items():
        if k in b:
            s += v + b[k]
            ans *= pow(2, v) + pow(2, b[k]) - 1
            ans %= mod
    ans *= pow(2, n - s - c, mod)
    print((ans - 1) % mod)

main()

Submission status: Wrong Answer

Solution code:
N=int(input())
mod=10**9+7
Azero=0
Bzero=0
both=0
plus={}
minus={}
import math
for i in range(N):
  A,B=map(int,input().split())
  if A==0 and B==0:
    both+=1
  elif A==0 and B!=0:
    Azero+=1
  elif A!=0 and B==0:
    Bzero+=1
  else:
    K=math.gcd(A,B)
    A=int(A/K)
    B=int(B/K)
    if A/B>0:
      if A<0:
        A,B=-A,-B
      if (A,B) in plus:
        plus[(A,B)]+=1
      else:
        plus[(A,B)]=1
    else:
      if A<0:
        A,B=-A,-B
      if (A,B) in minus:
        minus[(A,B)]+=1
      else:
        minus[(A,B)]=1

L=[]
if Azero>0 and Bzero>0:
  L.append((Azero,Bzero))
for k,v in plus.items():
  if (k[1],-k[0]) in minus:
    L.append((v,minus[(k[1],-k[0])]))
ans=0
for i in range(len(L)):
  N-=L[i][0]+L[i][1]
N-=both
c=1

for i in range(len(L)):
  c*=(pow(2,L[i][0],mod)+pow(2,L[i][1],mod)-1)
  c%=mod

ans=(c*pow(2,N,mod)-1)%mod

print((ans+both)%mod)

Submission status: Wrong Answer

Solution code:
N=int(input())
mod=10**9+7
Azero=0
Bzero=0
both=0
plus={}
minus={}
import math
for i in range(N):
  A,B=map(int,input().split())
  if A==0 and B==0:
    both+=1
  elif A==0 and B!=0:
    Azero+=1
  elif A!=0 and B==0:
    Bzero+=1
  else:
    K=math.gcd(A,B)
    A=int(A/K)
    B=int(B/K)
    if A/B>0:
      if A<0:
        A,B=-A,-B
      if (A,B) in plus:
        plus[(A,B)]+=1
      else:
        plus[(A,B)]=1
    else:
      if A<0:
        A,B=-A,-B
      if (A,B) in minus:
        minus[(A,B)]+=1
      else:
        minus[(A,B)]=1

L=[]
if Azero>0 and Bzero>0:
  L.append((Azero,Bzero))
for k,v in plus.items():
  if (k[1],-k[0]) in minus:
    L.append((v,minus[(k[1],-k[0])]))
ans=0
for i in range(len(L)):
  N-=L[i][0]+L[i][1]
N-=both
c=1

for i in range(len(L)):
  c*=(pow(2,L[i][0],mod)+pow(2,L[i][1],mod)-1)
  c%=mod

ans=(c*pow(2,N,mod)-1)%mod

print(ans+both)

Submission status: Wrong Answer

Solution code:
N=int(input())
mod=10**9+7
Azero=0
Bzero=0
both=0
plus={}
minus={}
import math
for i in range(N):
  A,B=map(int,input().split())
  if A==0 and B==0:
    both+=1
  elif A==0 and B!=0:
    Azero+=1
  elif A!=0 and B==0:
    Bzero+=1
  else:
    K=math.gcd(A,B)
    A=int(A/K)
    B=int(B/K)
    if A/B>0:
      if A<0:
        A,B=-A,-B
      if (A,B) in plus:
        plus[(A,B)]+=1
      else:
        plus[(A,B)]=1
    else:
      if A<0:
        A,B=-A,-B
      if (A,B) in minus:
        minus[(A,B)]+=1
      else:
        minus[(A,B)]=1

L=[]
if Azero>0 and Bzero>0:
  L.append((Azero,Bzero))
for k,v in plus.items():
  if (k[1],-k[0]) in minus:
    L.append((v,minus[(k[1],-k[0])]))
ans=0
for i in range(len(L)):
  N-=L[i][0]+L[i][1]
N-=both
c=1

for i in range(len(L)):
  c*=(pow(2,L[i][0],mod)+pow(2,L[i][1],mod)-1)
  c%=mod

ans=(c*pow(2,N,mod)-1)%mod
print(ans)

Submission status: Wrong Answer

Solution code:
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
import sys
gcd = math.gcd
co = collections.Counter()
n = ni()
mod=10**9+7
for i in range(n):
    a,b = ma()
    d = gcd(a,b)
    if d!=0:
        a//=d
        b//=d
    elif abs(a)>0 or abs(b)>0:
        l = max(abs(a), abs(b))
        a//=l
        b//=l
    co[(a,b)]+=1
d = collections.defaultdict(lambda:False)
ans=1
for t,cnt in co.items():
    a,b = t
    if t==(0,0) or d[t]:
        continue
    d[(a,b)]=True;d[(-a,-b)]=True;d[(b,-a)]=True;d[(-b,a)]=True
    l1 = co[(a,b)]+co[(-a,-b)]
    l2 = co[(b,-a)]+co[(-b,a)]
    ans=ans*(pow(2,l1,mod)+pow(2,l2,mod) -1)%mod
    ans%=mod
print((ans-1)%mod)

Submission status: Wrong Answer

Solution code:
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
import sys
gcd = math.gcd
co = collections.Counter()
n = ni()
mod=10**9+7
for i in range(n):
    a,b = ma()
    d = gcd(a,b)
    if d!=0:
        a//=d
        b//=d
    co[(a,b)]+=1
d = collections.defaultdict(lambda:False)
ans=1
for t,cnt in co.items():
    a,b = t
    if t==(0,0) or d[t]:
        continue
    d[(a,b)]=True;d[(-a,-b)]=True;d[(b,-a)]=True;d[(-b,a)]=True
    l1 = co[(a,b)]+co[(-a,-b)]
    l2 = co[(b,-a)]+co[(-b,a)]
    ans=ans*(pow(2,l1,mod)+pow(2,l2,mod) -1)%mod
    ans%=mod
print((ans-1)%mod)

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
z = 0
d = defaultdict(int)
for _ in range(n):
    a,b = inpl()
    if a == 0 and b == 0:
        z += 1
        continue
    if a == 0: b = 1
    if b == 0: a = 1
    if b < 0: a,b = -a,-b
    g = math.gcd(a,b)
    a //= g; b //= g
    d[(a,b)] += 1
res = 1
seen = set()
for k in list(d):
    a,b = k
    if k in seen: continue
    if a < 0: x,y = b,-a
    else: x,y = -b,a
    res *= pow(2,d[(a,b)],mod) + pow(2,d[(x,y)],mod) -1
    res %= mod
    # print(res)
    seen.add(k); seen.add((x,y))
res += z - 1
print(res%mod)

Submission status: Wrong Answer

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

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N = I()
mod = 10**9+7
plus = defaultdict(int)
minus = defaultdict(int)
flag = defaultdict(int)
A_zero,B_zero = 0,0
zero_zero = 0
for i in range(N):
    a,b = MI()
    if a == b == 0:
        zero_zero += 1
    elif a == 0:
        A_zero += 1
    elif b == 0:
        B_zero += 1
    else:
        if a < 0:
            a,b = -a,-b
        a,b = a//gcd(a,b),b//gcd(a,b)
        if b > 0:
            plus[(a,b)] += 1
        else:
            minus[(a,b)] += 1
            flag[(a,b)] = 1

ans = 1

for a,b in plus.keys():
    ans *= pow(2,plus[(a,b)],mod)+pow(2,minus[(b,-a)],mod)-1
    ans %= mod
    flag[(b,-a)] = 0

for key in minus.keys():
    if flag[key] == 1:
        ans *= pow(2,minus[key],mod)
        ans %= mod

ans *= pow(2,A_zero,mod)+pow(2,B_zero,mod)-1
ans %= mod

ans += zero_zero
ans %= mod

print(ans-1)

Submission status: Wrong Answer

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

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N = I()
mod = 10**9+7
plus = defaultdict(int)
minus = defaultdict(int)
flag = defaultdict(int)
A_zero,B_zero = 0,0
for i in range(N):
    a,b = MI()
    if a == b == 0:
        continue
    elif a == 0:
        A_zero += 1
    elif b == 0:
        B_zero += 1
    else:
        if a < 0:
            a,b = -a,-b
        a,b = a//gcd(a,b),b//gcd(a,b)
        if b > 0:
            plus[(a,b)] += 1
        else:
            minus[(a,b)] += 1
            flag[(a,b)] = 1

ans = 1
for a,b in plus.keys():
    ans *= pow(2,plus[(a,b)],mod)+pow(2,minus[(b,-a)],mod)-1
    ans %= mod
    flag[(b,-a)] = 0

for key in minus.keys():
    if flag[key] == 1:
        ans *= pow(2,minus[key],mod)
        ans %= mod

ans *= pow(2,A_zero,mod)+pow(2,B_zero,mod)-1
ans %= mod

print(ans-1)

Submission status: Wrong Answer

Solution code:
MOD = 10 ** 9 + 7
from math import gcd
from collections import defaultdict

n = int(input())
plus = defaultdict(int)
minus = defaultdict(int)
zero = [0, 0, 0]
for _ in range(n):
    a, b = map(int, input().split())
    if a * b == 0:
        if a == b == 0:
            zero[0] += 1
        elif a == 0:
            zero[1] += 1
        else:
            zero[2] += 1
        continue
    g = gcd(a, b)
    a //= g
    b //= g
    if a < 0:
        a *= -1
        b *= -1
    if b >= 0:
        s = str(a) + "-" + str(b)
        plus[s] += 1
    else:
        s = str(-b) + "-" + str(a)
        minus[s] += 1

pm = [[zero[1], zero[2]]]
cnt = sum(zero)
for key, value in plus.items():
    if minus[key] != 0:
        pm.append([value, minus[key]])
        cnt += value + minus[key]
        
ans = pow(2, n - cnt, MOD)

for p, m in pm:
    ans *= (pow(2, p, MOD) + pow(2, m, MOD) - 1)
    ans %= MOD
ans -= 1
ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque
import math

kMod = 1000000007

N = int(input())
key2count = defaultdict(lambda: [0, 0])

for _ in range(N):
    a, b = map(int, input().split())
    g = math.gcd(a, b)
    if g > 0:
        a, b = a//g, b//g
    if a < 0:
        a, b = -a, -b
    idx = 0
    if b <= 0:
        idx = 1
        a, b = -b, a
    key2count[(a, b)][idx] += 1

ans = 1
for key, val in key2count.items():
    if key == (0, 0):
        continue
    plus, minus = val
    ans *= (pow(2, plus, kMod) + pow(2, minus, kMod)-1)
    ans %= kMod

ans += sum(key2count[(0, 0)])

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque
import math

kMod = 10**9 + 7

N = int(input())
key2count = defaultdict(lambda: [0, 0])

for _ in range(N):
    a, b = map(int, input().split())
    g = math.gcd(a, b)
    if g > 0:
        a, b = a//g, b//g
    if a < 0:
        a, b = -a, -b
    idx = 0
    if b <= 0:
        idx = 1
        a, b = -b, a
    key2count[(a, b)][idx] += 1

ans = 1
for key, val in key2count.items():
    plus, minus = val
    if key == (0, 0):
        continue
    else:
        ans *= (pow(2, plus, kMod) + pow(2, minus, kMod)-1)
    ans %= kMod

ans += sum(key2count[(0, 0)])

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from math import gcd as g
n = int(input())
mod = 10**9+7
sardines = set()
Ddic = defaultdict(int)
ans = 1
zcount = 0
for i in range(n):
  a,b = map(int,input().split())
  if a == 0 and b == 0:
    zcount += 1
    continue

  if a == 0:
    Ddic[(0,1)] += 1
    sardines.add((0,1))
    continue

  if b == 0:
    sardines.add((1,0))
    Ddic[(1,0)] += 1
    continue

  A,B = abs(a),abs(b)
  G = g(A,B)
  a //= G
  b //= G

  if b < 0:
    a = -a
    b = -b

  Ddic[(a,b)] += 1
  sardines.add((a,b))

for i in sardines:
  if i == (0,0) or (i[0] <= 0 and Ddic[(i[1],-i[0])] != 0):continue
  if i[0] <= 0:
    ans *= (2**Ddic[i] + 2**(Ddic[(i[1],-i[0])]))-1
  else:
    ans *= (2**Ddic[i] + 2**(Ddic[(-i[1],i[0])]))-1
  print (ans)
  ans %= mod
print((ans+zcount-1)%mod)

Submission status: Wrong Answer

Solution code:
mod = 1000000007

N = int(input())

pos = []
neg = []
zer = []
inf = []
sol = 0

###除外すべき組み合わせの個数を数える
NG = []

for i in range(N):
    a,b = map(int,input().split())
    if a*b > 0:
        pos.append((a,b))
    elif a*b < 0:
        neg.append((a,b))
    elif a == 0 and b != 0:
        inf.append((a,b))
    elif a != 0 and b == 0:
        zer.append((a,b))
    else:
        sol += 1

NG.append((len(inf),len(zer)))
free = len(pos)+len(neg)


# 以下しばらくneg,posに含まれるものに関する議論

pos.sort(key=lambda x:(x[1]/x[0]))
neg.sort(key=lambda x:(x[1]/x[0]))

x = 0
y = 0


while (x < len(pos) and y < len(neg)):
    if pos[x][0]*neg[y][0]+pos[x][1]*neg[y][1] == 0:
        s = 1
        t = 1
        while x+1 < len(pos) and pos[x+1][0]*neg[y][0]+pos[x+1][1]*neg[y][1] == 0:
            x += 1
            s += 1
        while y+1 < len(neg) and pos[x][0]*neg[y+1][0]+pos[x][1]*neg[y+1][1] == 0:
            y += 1
            t += 1
        NG.append((s,t))
        x += 1
        y += 1
        free -= (s+t)
        continue


    if x >= len(pos)-1 and y >= len(neg)-1:
        break

    elif y+1 < len(neg) and pos[x][0]*neg[y][0]+pos[x][1]*neg[y][1] > 0:
        y += 1
    elif x+1 < len(pos) and pos[x][0]*neg[y][0]+pos[x][1]*neg[y][1] < 0:
        x += 1
    elif x >= len(pos)-1:
        y += 1
    elif y >= len(neg)-1:
        x += 1

ans = pow(2,free,mod)

for s,t in NG:
    # s個のうち1個以上入れる or t個のうち1個以上入れる or どちらも1つも入れない
    ans *= pow(2,s,mod)-1 +pow(2,t,mod)-1 +1
    ans %= mod

#print('free',free)
#print('NG',NG)

# 1つも選ばないものの除外、solは単体で選べばOK
print((ans+sol-1)%mod)

Submission status: Wrong Answer

Solution code:
mod = 1000000007

N = int(input())

pos = []
neg = []
zer = []
inf = []
sol = 0

###除外すべき組み合わせの個数を数える
NG = []

for i in range(N):
    a,b = map(int,input().split())
    if a*b > 0:
        pos.append((a,b))
    elif a*b < 0:
        neg.append((a,b))
    elif a == 0 and b != 0:
        inf.append((a,b))
    elif a != 0 and b == 0:
        zer.append((a,b))
    else:
        sol += 1

NG.append((len(inf),len(zer)))
free = len(pos)+len(neg)

'''
ans = 0

ans += len(pos)*(len(pos)-1)//2
ans += len(neg)*(len(neg)-1)//2
ans += len(pos)*len(neg)

ans %= mod
'''

# 以下しばらくneg,posに含まれるものに関する議論

pos.sort(key=lambda x:(x[1]/x[0]))
neg.sort(key=lambda x:(x[1]/x[0]))

x = 0
y = 0


while (x < len(pos) and y < len(neg)):
    if pos[x][0]*neg[y][0]+pos[x][1]*neg[y][1] == 0:
        s = 1
        t = 1
        while x+1 < len(pos) and pos[x+1][0]*neg[y][0]+pos[x+1][1]*neg[y][1] == 0:
            x += 1
            s += 1
        while y+1 < len(neg) and pos[x][0]*neg[y+1][0]+pos[x][1]*neg[y+1][1] == 0:
            y += 1
            t += 1
        NG.append((s,t))
        x += 1
        y += 1
        free -= (s+t)
        continue


    if x >= len(pos)-1 and y >= len(neg)-1:
        break

    elif y+1 < len(neg) and pos[x][0]*neg[y][0]+pos[x][1]*neg[y][1] > 0:
        y += 1
    elif x+1 < len(pos) and pos[x][0]*neg[y][0]+pos[x][1]*neg[y][1] < 0:
        x += 1
    elif x >= len(pos)-1:
        y += 1
    elif y >= len(neg)-1:
        x += 1

ans = pow(2,free,mod)
for s,t in NG:
    # s個のうち1個以上入れる or t個のうち1個以上入れる or どちらも1つも入れない
    ans *= pow(2,s,mod)-1 +pow(2,t,mod)-1 +1
    ans %= mod

#print('free',free)
#print('NG',NG)

# 1つも選ばないものの除外、solは単体で選べばOK
print((ans+sol-1)%mod)

Submission status: Wrong Answer

Solution code:
mod = 1000000007

N = int(input())

pos = []
neg = []

for i in range(N):
    a,b = map(int,input().split())
    if a*b > 0:
        pos.append((a,b))
    elif a*b < 0:
        neg.append((a,b))
'''
ans = 0

ans += len(pos)*(len(pos)-1)//2
ans += len(neg)*(len(neg)-1)//2
ans += len(pos)*len(neg)

ans %= mod
'''

pos.sort(key=lambda x:(x[1]/x[0]))
neg.sort(key=lambda x:(x[1]/x[0]))

x = 0
y = 0

###除外すべき組み合わせの個数を数える
NG = []
free = N

while (x < len(pos) and y < len(neg)):
    if pos[x][0]*neg[y][0]+pos[x][1]*neg[y][1] == 0:
        s = 1
        t = 1
        while x+1 < len(pos) and pos[x+1][0]*neg[y][0]+pos[x+1][1]*neg[y][1] == 0:
            x += 1
            s += 1
        while y+1 < len(neg) and pos[x][0]*neg[y+1][0]+pos[x][1]*neg[y+1][1] == 0:
            y += 1
            t += 1
        NG.append((s,t))
        x += 1
        y += 1
        free -= (s+t)
        continue


    if x >= len(pos)-1 and y >= len(neg)-1:
        break

    elif y+1 < len(neg) and pos[x][0]*neg[y][0]+pos[x][1]*neg[y][1] > 0:
        y += 1
    elif x+1 < len(pos) and pos[x][0]*neg[y][0]+pos[x][1]*neg[y][1] < 0:
        x += 1
    elif x >= len(pos)-1:
        y += 1
    elif y >= len(neg)-1:
        x += 1

ans = pow(2,free,mod)
for s,t in NG:
    # s個のうち1個以上入れる or t個のうち1個以上入れる or どちらも1つも入れない
    ans *= pow(2,s,mod)-1 +pow(2,t,mod)-1 +1
    ans %= mod

#print('free',free)
#print('NG',NG)
print((ans-1)%mod)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
from collections import defaultdict
d = defaultdict(list)
s = set()
zc = 0
for i in range(n):
    a,b = map(int, input().split())
    g = math.gcd(a,b)
    if g!=0:
        a //= g; b //= g
        if a<0:
            a,b = -a, -b
        elif b<0:
            b *= -1
        d[a,b].append(i)
    if a==b==0:
        zc += 1
v = 1
s = set()
M = 10**9+7
for (a,b),val in d.items():
    aa,bb = b,-a
    if aa<0:
        aa,bb = -aa, -bb
    elif bb<0:
        bb *= -1
    if (a,b) in s or (aa,bb) in s:
        continue
    if (aa,bb) in d.keys():
        v *= (pow(2, len(val), M) + pow(2, len(d[aa,bb]), M) - 1)
    else:
        v *= pow(2, len(val), M)
    v %= M
    s.add((a,b))
    s.add((aa,bb))
v -= 1
v += zc
print(v%M)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
from collections import defaultdict
d = defaultdict(list)
s = set()
zc = 0
for i in range(n):
    a,b = map(int, input().split())
    g = math.gcd(a,b)
    if g!=0:
        a //= g; b //= g
        if a<0:
            a,b = -a, -b
        d[a,b].append(i)
    if a==b==0:
        zc += 1
v = 1
s = set()
M = 10**9+7
for (a,b),val in d.items():
    aa,bb = b,-a
    if aa<0:
        aa,bb = -aa, -bb
    if (a,b) in s or (aa,bb) in s:
        continue
    if (aa,bb) in d.keys():
        v *= (pow(2, len(val), M) + pow(2, len(d[aa,bb]), M) - 1)
    else:
        v *= pow(2, len(val), M)
    v %= M
    s.add((a,b))
    s.add((aa,bb))
v -= 1
v += zc
print(v%M)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
from collections import defaultdict
d = defaultdict(list)
s = set()
zc = 0
for i in range(n):
    a,b = map(int, input().split())
    g = math.gcd(a,b)
    if g!=0:
        a //= g; b //= g
        if a<0:
            a,b = -a, -b
        d[a,b].append(i)
    else:
        zc += 1
v = 1
s = set()
M = 10**9+7
for (a,b),val in d.items():
    aa,bb = b,-a
    if aa<0:
        aa,bb = -aa, -bb
    if (a,b) in s or (aa,bb) in s:
        continue
    if (aa,bb) in d.keys():
        v *= (pow(2, len(val), M) + pow(2, len(d[aa,bb]), M) - 1)
    else:
        v *= pow(2, len(val), M)
    v %= M
    s.add((a,b))
    s.add((aa,bb))
v -= 1
v += zc
print(v%M)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
from collections import defaultdict
d = defaultdict(list)
s = set()
zc = 0
for i in range(n):
    a,b = map(int, input().split())
    g = math.gcd(a,b)
    if g!=0:
        a //= g; b //= g
        if a<0:
            a,b = -a, -b
        d[a,b].append(i)
    else:
        zc += 1
v = 1
s = set()
M = 10**9+7
for (a,b),val in d.items():
    aa,bb = b,-a
    if aa<0:
        aa,bb = -aa, -bb
    if (a,b) in s or (aa,bb) in s:
        continue
    if (aa,bb) in d.keys():
        v *= (pow(2, len(val), M) + pow(2, len(d[aa,bb]), M) - 1)
    else:
        v *= pow(2, len(val), M)
    v %= M
    s.add((a,b))
    s.add((aa,bb))
v -= 1
print(v%M)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
from collections import defaultdict
d = defaultdict(list)
s = set()
for i in range(n):
    a,b = map(int, input().split())
    g = math.gcd(a,b)
    if g!=0:
        a //= g; b //= g
    if a<0:
        a,b = -a, -b
    d[a,b].append(i)
v = 1
s = set()
M = 10**9+7
for (a,b),val in d.items():
    aa,bb = b,-a
    if aa<0:
        aa,bb = -aa, -bb
    if (a,b) in s or (aa,bb) in s:
        continue
    if (aa,bb) in d.keys():
        v *= (pow(2, len(val), M) + pow(2, len(d[aa,bb]), M) - 1)
    else:
        v *= pow(2, len(val), M)
    v %= M
    s.add((a,b))
    s.add((aa,bb))
v -= 1
print(v%M)

Submission status: Wrong Answer

Solution code:
N = int(input())
mod = 10 **9 + 7
from math import gcd
def equal(item0, item1, delta = 10 ** (-20)):
    if abs(item0 - item1) < delta:
        return True
    else:
        return False
def bigger(item0, item1, delta = 10** (-20)):
    if item0 -item1 > delta:
        return True
    else:
        return False

def binary_insert(list, item):
    low = 0
    high = len(list) - 1
    while low <= high:
        mid = (low + high) //2
        guess = list[mid][0]
        if equal(guess,item):
            list[mid][1] += 1
            return None
        if bigger(guess, item):
            high = mid -1
        else:
            low = mid + 1
    mid = (low + high) //2
    if list:
        if mid < len(list):
            if bigger(item, list[mid][0]):
                list.insert(mid+1, [item, 1])
                return None
        if mid > 0:
            if bigger(list[mid-1][0], item):
                list.insert(mid-1, [item, 1])
                return None
    list.insert(mid, [item, 1])
    return None


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

from collections import deque
ab = deque(ab)
ba = deque(ba)
ans = 1 #all pattern
pair = []
a = [-1, 0]
b = [-1, 0]
flaga = True
flagb = True

while True:
    if flaga:
        if ab:
            a = ab.popleft()
        else:
            a = [-1, 0]
            flaga = False
    if flagb:
        if ba:
            b = ba.popleft()
        else:
            b = [-1, 0]
            flagb = False
    if a[0] == b[0] == -1:
        break
    elif equal(a[0], b[0]):
        pair.append([a[1], b[1]])
        flaga = True
        flagb = True
        continue
    elif bigger(a[0], b[0]):
        if b[0] == -1:
            pair.append([a[1], 0])
            flaga = True
            continue
        else:
            pair.append([0, b[1]])
            if ba:
                flaga = False
                flagb = True
            continue
    else:
        if a[0] == -1:
            pair.append([0, b[1]])
            flagb = True
            continue
        else:
            pair.append([a[1], 0])
            if ab:
                flaga = True
                flagb = False

ans = 1
for item in pair:
    ans *= pow(2, item[0], mod) + pow(2, item[1], mod) -1
    ans %= mod
ans += zero-1
ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
mod = 10 **9 + 7
from math import gcd
def equal(item0, item1, delta = 10 ** (-24)):
    if abs(item0 - item1) < delta:
        return True
    else:
        return False
def bigger(item0, item1, delta = 10** (-24)):
    if item0 -item1 > delta:
        return True
    else:
        return False

def binary_insert(list, item):
    low = 0
    high = len(list) - 1
    while low <= high:
        mid = (low + high) //2
        guess = list[mid][0]
        if equal(guess,item):
            list[mid][1] += 1
            return None
        if bigger(guess, item):
            high = mid -1
        else:
            low = mid + 1
    mid = (low + high) //2
    if list:
        if mid < len(list):
            if bigger(item, list[mid][0]):
                list.insert(mid+1, [item, 1])
                return None
        if mid > 0:
            if bigger(list[mid-1][0], item):
                list.insert(mid-1, [item, 1])
                return None
    list.insert(mid, [item, 1])
    return None


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

from collections import deque
ab = deque(ab)
ba = deque(ba)
ans = 1 #all pattern
pair = []
a = [-1, 0]
b = [-1, 0]
flaga = True
flagb = True

while True:
    if flaga:
        if ab:
            a = ab.popleft()
        else:
            a = [-1, 0]
            flaga = False
    if flagb:
        if ba:
            b = ba.popleft()
        else:
            b = [-1, 0]
            flagb = False
    if a[0] == b[0] == -1:
        break
    elif equal(a[0], b[0]):
        pair.append([a[1], b[1]])
        flaga = True
        flagb = True
        continue
    elif bigger(a[0], b[0]):
        if b[0] == -1:
            pair.append([a[1], 0])
            flaga = True
            continue
        else:
            pair.append([0, b[1]])
            if ba:
                flaga = False
                flagb = True
            continue
    else:
        if a[0] == -1:
            pair.append([0, b[1]])
            flagb = True
            continue
        else:
            pair.append([a[1], 0])
            if ab:
                flaga = True
                flagb = False

ans = 1
for item in pair:
    ans *= pow(2, item[0], mod) + pow(2, item[1], mod) -1
    ans %= mod
ans += zero-1
ans %= mod
print(ans)

Submission status: Wrong Answer

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

def equal(item0, item1, delta = 10 ** (-24)):
    if abs(item0 - item1) < delta:
        return True
    else:
        return False
def bigger(item0, item1, delta = 10** (-24)):
    if item0 -item1 > delta:
        return True
    else:
        return False

def binary_insert(list, item):
    low = 0
    high = len(list) - 1
    while low <= high:
        mid = (low + high) //2
        guess = list[mid][0]
        if equal(guess,item):
            list[mid][1] += 1
            return None
        if bigger(guess, item):
            high = mid -1
        else:
            low = mid + 1
    mid = (low + high) //2
    if len(list) > 0:
        if mid < len(list):
            if item > list[mid][0]:
                mid += 1
    list.insert(mid, [item, 1])


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

from collections import deque
ab = deque(ab)
ba = deque(ba)
ans = 1 #all pattern
pair = []
a = [-1, 0]
b = [-1, 0]
flaga = True
flagb = True

while True:
    if flaga:
        if ab:
            a = ab.popleft()
        else:
            a = [-1, 0]
            flaga = False
    if flagb:
        if ba:
            b = ba.popleft()
        else:
            b = [-1, 0]
            flagb = False
    if a[0] == b[0] == -1:
        break
    elif equal(a[0], b[0]):
        pair.append([a[1], b[1]])
        flaga = True
        flagb = True
        continue
    elif bigger(a[0], b[0]):
        if b[0] == -1:
            pair.append([a[1], 0])
            flaga = True
            continue
        else:
            pair.append([0, b[1]])
            if ba:
                flaga = False
                flagb = True
            continue
    else:
        if a[0] == -1:
            pair.append([0, b[1]])
            flagb = True
            continue
        else:
            pair.append([a[1], 0])
            if ab:
                flaga = True
                flagb = False

ans = 1
for item in pair:
    ans *= pow(2, item[0], mod) + pow(2, item[1], mod) -1
    ans %= mod
ans += zero-1
ans %= mod
print(ans)