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 math import gcd
mod = 10**9+7
n = int(input())
dicn = {}
dicp = {}
dicz = {'a': 0, 'b': 0, 'z': 0}
for i in range(n):
  a, b = map(int, input().split())
  if a == 0 and b == 0:
    dicz['z'] += 1
  else:
    g = gcd(a,b)
    a //= g
    b //= g
    if a < 0:
      a *= -1
      b *= -1
    elif a == 0 and b < 0:
      b *= -1
    if a * b > 0:
      if a in dicp:
        if b in dicp[a]:
          dicp[a][b] += 1
        else:
          dicp[a][b] = 1
      else:
        dicp[a] = {b: 1}
    elif a * b < 0:
      if b in dicn:
        if a in dicn[b]:
          dicn[b][a] += 1
        else:
          dicn[b][a] = 1
      else:
        dicn[b] = {a: 1}
    else:
      if a == 0:
        dicz['a'] += 1
      else:
        dicz['b'] += 1

ans = 1

for a in dicp:
  for b in dicp[a]:
    if -a in dicn:
      if b in dicn[-a]:
        ans *= (pow(2, dicp[a][b], mod) + pow(2, dicn[-a][b], mod) - 1)
        dicn[-a][b] = 0
      else:
        ans *= pow(2, dicp[a][b], mod)
    else:
      ans *= pow(2, dicp[a][b], mod)
    ans %= mod

for b in dicn:
  for a in dicn[b]:
    ans *= pow(2, dicn[b][a], mod)
    ans %= mod
    
if dicz['a'] > 0 and dicz['b'] > 0:
  ans *= pow(2,dicz['a'],mod) + pow(2,dicz['b'],mod) - 1
elif dicz['a'] > 0:
  ans *= pow(2,dicz['a'],mod)
elif dicz['b'] > 0:
  ans *= pow(2,dicz['b'],mod)
  
ans *= pow(2,dicz['z'],mod)
    
print((ans-1)%mod)

Submission status: Wrong Answer

Solution code:
n = int(input())
a_list = []
b_list = []
mod = 10 ** 9 + 7
p = [1] * (n + 1)
for i in range(n):
    p[i + 1] = p[i] * 2 % mod
for _ in range(n):
    a, b = map(int, input().split())
    a_list.append((a * pow(b, mod - 2, mod)) % mod)
    b_list.append((b * pow(a, mod - 2, mod)) % mod)
count = n
out = 0
for aa in a_list:
    num = b_list.count((aa * (-1)) % mod)
    out += p[count - num - 1]
    out = out % mod
    count -= 1
    b_list.pop(0)
print(out)

Submission status: Wrong Answer

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

N = int(input())
AB = [[int(i) for i in input().split()] for _ in range(N)]

mod = 10 ** 9 + 7

def gcd(a, b) :
  if b > a : 
    a, b = b, a
  
  while b != 0 :
    a, b = b, a % b
  return a

p = []
zero = 0
for a, b in AB :
  if a == 0 or b == 0 :
    zero += 1
    continue
  g = gcd(abs(a), abs(b))
  a //= g
  b //= g
  if a < 0 :
    a *= -1
    b *= -1
  p.append((a, b))

ret = 1
visited = set()
cnt = Counter(p)
for k, v in cnt.items() :
  a, b = k
  c, d = b, -a
  if c < 0 :
    c *= -1
    d *= -1
  if cnt[(c, d)] == 0 :
    ret *= pow(2, v, mod)
  else :
    if not (c, d) in visited :
      u = cnt[(c, d)]
      ret *= (pow(2, u, mod) + pow(2, v, mod) - 1)
      visited.add((a, b))
      visited.add((c, d))
  ret %= mod

ret *= zero + 1
ret %= mod

print((ret - 1) % mod)

Submission status: Wrong Answer

Solution code:
from sys import stdin, setrecursionlimit


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

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

    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 - 1) % mod)


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

Submission status: Wrong Answer

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

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

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

    L2=[0,0,0,0]

    for i in range(len(L)):
        k=L[i][0]
        if k==(0,0):
            continue
        v=d[k]
        d[k]=0
        temp=pow(2,v)
        a,b=k
        if a*b!=0:
            if (-b,a) in d:
                v2=d[(-b,a)]
                if v2!=0:
                    temp+=pow(2,v2)-1
                    d[(-b,a)]=0
            if (b,-a) in d:
                v2=d[(b,-a)]
                if v2!=0:
                    temp+=pow(2,v2)-1
                    d[(b,-a)]=0
            ans=(ans*temp)%mod
                    
        if (a,b)==(0,1):
            L2[0]=pow(2,v)-1
        elif (a,b)==(0,-1):
            L2[1]=pow(2,v)-1
        elif (a,b)==(1,0):
            L2[2]=pow(2,v)-1
        elif (a,b)==(-1,0):
            L2[3]=pow(2,v)-1
        
        
    temp2=1
    for i in range(2):
        if L2[i]!=0:
            temp2=(temp2*L2[i])%temp
    
            
    temp3=1
    for i in range(2,4):
        if L2[i]!=0:
            temp3=(temp3*L2[i])%temp
            
    temp=(temp2+temp3)-1
        
    ans=(ans*temp)%mod
        
    if (0,0) in d:
        #他の選び方と共存しない
        v=d[(0,0)]
        temp=pow(2,v)-1
        ans=(ans+temp)%mod

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

main()

Submission status: Wrong Answer

Solution code:
from decimal import *
getcontext().prec = 30

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

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

slist=sorted(slist)
#print(slist)


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

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

answer=1
#print(slist)

rev=0
swit=0
#print(slist)

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

if len(slist)>0:
    answer*=(2**onaji[0]+2**onaji[1]-1)
    answer%=1000000007

#print(answer)

answer*=zerok
answer+=zeros[2]

print((answer-1)%1000000007)

Submission status: Wrong Answer

Solution code:
from math import gcd
import random
n = int(input())
mod = 10**9 + 7
d1 = dict()
a_zero,b_zero = 0,0
ab = 0
# サンプル入力
#n = 2*10**5
#data = [[random.randint(-10**18,10**18),random.randint(-10**18,10**18)] for _ in range(n)]
for i in range(n):
    a,b = map(int, input().split())
    #a,b = data[i]
    if a == 0 and b == 0:
        ab += 1
        continue
    if a == 0:
        a_zero += 1
        continue
    if b == 0:
        b_zero += 1
        continue
    a,b = a//gcd(a,b),b//gcd(a,b)
    if a < 0:
        a *= -1
        b *= -1

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

ans =  1
ans *= pow(2,a_zero,mod)+pow(2,b_zero,mod)-1
ans %= mod
for a,b in d1:
    if b > 0 and (b,-a) in d1:
        ans *= pow(2,d1[(a,b)],mod)+pow(2,d1[(b,-a)],mod)-1
        d1[(a,b)] = 0
        d1[(b,-a)] = 0
    elif b < 0 and (-b,a) in d1:
        ans *= pow(2,d1[(a,b)],mod)+pow(2,d1[(-b,a)],mod)-1
        d1[(a,b)] = 0
        d1[(-b,a)] = 0
    else:
        ans *= pow(2,d1[(a,b)],mod)
        d1[(a,b)] = 0
    ans %= mod
    #print(a,b,d1)
print(ans-1 + ab)

Submission status: Wrong Answer

Solution code:

def nasu(a, b):
  c = a / b
  return c
    


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

MOD = 10 ** 9 + 7

R = {}

cnt = 0
ze = 0
for a, b in AB:
  if a == 0 and b == 0: 
    ze += 1
    continue
  if b == 0:
    s = "na"
  elif a == 0:
    s = "su"
  else:
    s = nasu(a, b)
  if s in R:
    R[s] += 1
  else:
    R[s] = 1
  cnt += 1

L = []
for i in R.keys():
  if i == "na":
    s = "su"
  elif i == "su":
    s = "na"
  else:
    s = - 1 / i
  t = R[i]
  if s not in R:
    L.append(pow(2, t, MOD))
    continue
  k = R[s]
  L.append((pow(2, t) + pow(2, k) - 1) % MOD)
  R[i] = 0
  R[s] = 0

ans = 1
for i in L:
  ans = ans * i % MOD

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

Submission status: Wrong Answer

Solution code:
from math import gcd
from collections import Counter
N, *A = map(int, open(0).read().split())
*A, = zip(*[iter(A)]*2)

mod = 10**9 + 7


def modpow(a, n, mod):
    ret = 1
    while n:
        if n & 1:
            ret = ret * a % mod
        a = a * a % mod
        n >>= 1
    return ret


col = []
row = []
for a, b in A:
    if a == b == 0:
        continue
    if a == 0:
        b = 1
    elif b == 0:
        a = 1
    else:
        g = gcd(abs(a), abs(b))
        a //= g
        b //= g

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

    if a >= 0 and b > 0:
        col.append((a, b))
    elif a > 0 and b < 0 or b == 0:
        row.append((-b, a))


C = Counter(col)
D = Counter(row)
S = set(col) | set(row)


ans = 1
for s in S:
    if s in C:
        if s in D:
            mul = modpow(2, C[s], mod) + modpow(2, D[s], mod) - 1
        else:
            mul = modpow(2, C[s], mod)
    elif s in D:
        mul = modpow(2, D[s], mod)

    ans *= mul
    ans %= mod

ans -= 1
ans %= mod

print(ans)

Submission status: Wrong Answer

Solution code:
import math
import numpy as np
import queue
from collections import deque
import heapq
mod = 10**9+7
ans = 1

def twoxxn(t,mod):
    ni = t
    an = 1
    n2 = 2
    while ni > 0:
        if ni%2 == 1:
            an = (an*n2)%mod
        n2 = (n2**2)%mod
        ni //= 2
    return an

n = int(input())
d = dict()
for i in range(n):
    a,b = map(int,input().split())
    if a < 0 and (b < 0 or abs(a) > abs(b)):
        a = -a
        b = -b
    g = math.gcd(abs(a),abs(b))
    if a == 0 and b == 0:
        continue
    elif a == -b:
        if "1 -1" in d:
            d["1 -1"] += 1
        else:
            d["1 -1"] = 1
    elif a == b:
        if "1 1" in d:
            d["1 1"] += 1
        else:
            d["1 1"] = 1
    else:
        p1 = str(a//g)+" "+str(b//g)
        p2 = str(b//g)+" "+str(a//g)
        if p1 in d:
            d[p1] += 1
            d[p2] += 1
        else:
            d[p1] = 1
            d[p2] = 1

for i in d.keys():
    i0, i1 = map(int,i.split())
    if abs(i0) < abs(i1):
        continue
    elif str(i0)+" "+str(-i1) in d:
        if d[i] == 0:
            continue
        aaa = (twoxxn(d[str(i0)+" "+str(-i1)],mod)+twoxxn(d[i],mod)-1)%mod
        ans = (ans*aaa)%mod
        d[str(i0)+" "+str(-i1)] = 0
    else:
        ans = (ans*twoxxn(d[i],mod))%mod
ans = (ans-1)%mod

print(max(1,ans))

Submission status: Wrong Answer

Solution code:
import math 

MOD = 10**9 + 7
N = int(input())
ABC = []
for i in range(N):
    a, b = map(int, input().split())
    if a * b >=0 and a > 0:
        ABC.append([ math.atan2(abs(b),abs(a)), abs(a), abs(b),1])
    else:
        ABC.append([math.atan2(abs(a),abs(b)), abs(b), abs(a), -1])
ABC.sort()
current_arg = ABC[-1][0]
group = []
daiich = 0
daini = 0
while ABC:
    current = ABC.pop()
    if current[0] == current_arg:
        if current[3]==1:
            daiich += 1
        else:
            daini += 1
    else:
        group += [[daiich, daini]]
        daiich = 0
        daini = 0
        if current[3]==1:
            daiich += 1
        else:
            daini += 1
        if ABC:
            current_arg = ABC[-1][0]
else:
    group += [[daiich, daini]]
    daiich = 0
    daini = 0

ans = 1
for u, v in group:
    ans *= (2**u + 2**v -1)
    ans %= MOD
print(ans-1)

Submission status: Wrong Answer

Solution code:
import math
def heikatu(A,B):
    if A % abs(B) ==0:
        return (A//abs(B),B//abs(B))
    if abs(B) % A == 0:
        return (1,B//A)
    
    c = 2
    while c <=math.sqrt(max(A,abs(B))):
        while A % c ==0 and B% c ==0:
            A //=c
            B//=c
        c+=1

    return (A,B)


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:
            A *= -1
            B *= -1
        if A == 0 and B == 0:
            zerozero+=1
            continue

        if A == 0:
            zero[0]+=1
            continue
        if B == 0:
            zero[1]+=1
            continue

        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 = []
    if zero != [0,0]:
        tx.append(zero)

    for key in kp:
        A,B = key
        cou = kp[key]    
        if (B,-A) in km:
            tx.append([cou,km[(B,-A)]])
            km.pop((B,-A))
        else:
            tx.append([cou,0])
    for key in km:
        tx.append([0,km[key]])

    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,a)) %mod
        if a !=0 and b!=0:
            xxx-=1
        ans = (ans*xxx) % mod

    ans = (ans+mod-1+zerozero) % mod 

    print(ans)       


        







resolve()

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
mod = 1000000007
degs = {}
ans = 1
for i in range(N):
    A,B = map(int,input().split())
    if(A!=0):
        ab = B/A
    else:
        ab = "mugen"
    if(ab==0):
        nakawaru = "mugen"
    elif(ab == "mugen"):
        nakawaru = 0
    else:
        nakawaru = -1/ab
    if(ab not in degs.keys()):
        degs[ab] = 1
    else:
        degs[ab] += 1
    if(nakawaru not in degs.keys()):
        ans = ans*2%mod
    else:
        waru = pow(2,degs[nakawaru],mod)
        ans = (ans + ans*pow(waru,mod-2,mod)%mod)%mod
    
print(ans-1)

Submission status: Wrong Answer

Solution code:
import sys,math,bisect
input = sys.stdin.readline

mod = 1000000007
eps = 0.00000001

n = int(input())

ab = []
ang = []
for i in range(n):
    a,b = map(int,input().split())
    ab.append((a,b))
    if a == 0:
        ang.append(90.0)
    else:
        ang.append(math.degrees(math.atan(b/a)))
ang.sort()

res = 1
rest = n

i = 0
while True:
    if i >= n:
        break
    val = ang[i]
    if val > 2*eps:
        break
    cnt = bisect.bisect_right(ang,val+eps) - i
    cnt2 = bisect.bisect_right(ang,val+90+eps) - bisect.bisect_left(ang,val+90-eps)
    if cnt2 > 0:
        rest = rest - cnt - cnt2
        res = res*(pow(2,cnt,mod) + pow(2,cnt2,mod) - 1)%mod
    i += cnt
rest = max(rest,0)
res = res*pow(2,rest,mod)%mod - 1
print(res%mod)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from math import gcd

MOD = 10 ** 9 + 7
N = int(input())
AB = []
NUMS = defaultdict(int)
zeros = 0
for _ in range(N):
    a, b = map(int, input().split())
    AB.append((a, b))

    if a == b == 0:
        zeros += 1
        continue

    d = gcd(a, b)
    x, y = a // d, b // d
    if y < 0:
        x, y = -x, -y
    NUMS[x, y] += 1

todo = set(NUMS.keys())
ans = 1
while todo:
    x, y = todo.pop()
    if (-y, x) in todo or (y, -x) in todo:
        assert not ((-y, x) in todo and (y, -x) in todo)
        if (-y, x) in todo:
            v = NUMS[-y, x]
        else:
            v = NUMS[y, -x]
        ans = ans * (2 ** NUMS[x, y] + 2 ** v - 1) % MOD
        todo -= {(-y, x), (y, -x)}
    else:
        ans = ans * (2 ** NUMS[x, y]) % MOD
ans += zeros - 1
print(ans)

Submission status: Wrong Answer

Solution code:
class Combination:
    """階乗とその逆元のテーブルをO(N)で事前作成し、組み合わせの計算をO(1)で行う"""
    def __init__(self, n, MOD):
        self.fact = [1]
        for i in range(1, n + 1):
            self.fact.append(self.fact[-1] * i % MOD)
        self.inv_fact = [0] * (n + 1)
        self.inv_fact[n] = pow(self.fact[n], MOD - 2, MOD)
        for i in reversed(range(n)):
            self.inv_fact[i] = self.inv_fact[i + 1] * (i + 1) % MOD
        self.MOD = MOD

    def factorial(self, k):
        """k!を求める O(1)"""
        return self.fact[k]

    def inverse_factorial(self, k):
        """k!の逆元を求める O(1)"""
        return self.inv_fact[k]

    def permutation(self, k, r):
        """kPrを求める O(1)"""
        if k < r:
            return 0
        return (self.fact[k] * self.inv_fact[k - r]) % self.MOD

    def combination(self, k, r):
        """kCrを求める O(1)"""
        if k < r:
            return 0
        return (self.fact[k] * self.inv_fact[k - r] * self.inv_fact[r]) % self.MOD

    def combination2(self, k, r):
        """kCrを求める O(r) kが大きいが、r <= nを満たしているときに使用"""
        if k < r:
            return 0
        res = 1
        for l in range(r):
            res *= (k - l)
            res %= self.MOD
        return (res * self.inv_fact[r]) % self.MOD


def compress(string):
    string.append(-2)
    n = len(string)
    begin, end, cnt = 0, 1, 1
    ans = []
    while end < n:
        if string[begin] == string[end]:
            end, cnt = end + 1, cnt + 1
        else:
            ans.append((string[begin], cnt))
            begin, end, cnt = end, end + 1, 1
    return ans

  
from collections import defaultdict


n = int(input())
info = [list(map(int, input().split())) for i in range(n)]
MOD = 10 ** 9 + 7
comb = Combination(10 ** 6, MOD)
res1 = []
res2 = []
ind = []
cnt_00 = 0
cnt_a0 = 0
cnt_b0 = 0
for i in range(n):
    a, b = info[i]
    if a == 0 and b == 0:
        cnt_00 += 1
        continue
    if a == 0:
        cnt_a0 += 1
        continue
    if b == 0:
        cnt_b0 += 1
        continue
    res1.append(a / b)
    res2.append(- b / a)
    ind.append(i)

memo_r = defaultdict(int)
memo_l = defaultdict(int)

for i in range(len(res1)):
    l, r = res1[i], res2[i]
    memo_r[r] += 1
    memo_l[l] += 1

ans = 1
used = set()
for r in memo_r:
    if r in used:
        continue
    cnt_r = memo_r[r]
    cnt_l = 0
    if r in memo_l:
        cnt_l += memo_l[r]
    if r == -1.0 or r == 1.0:
        tmp = cnt_l + cnt_r + 1
    else:
        tmp = (pow(2, cnt_l, MOD) - 1) + (pow(2, cnt_r, MOD) - 1) + 1
    ans *= tmp
    used.add(-1 / r)

ans += cnt_00 + ans * (cnt_a0 + cnt_b0)
print((ans - 1) % MOD)

Submission status: Wrong Answer

Solution code:
MOD = 10**9+7
import sys
from collections import Counter
from math import gcd
def input():
	return sys.stdin.readline()[:-1]
n = int(input())
ans = 0
c = Counter()
for _ in range(n):
	a, b = map(int, input().split())
	if a < 0:
		a, b = -a, -b
	if a == 0:
		a, b = 0, 1
	g = gcd(a, b)
	c[(a//g, b//g)] += 1

ans = 1
for k, v in c.items():
	#print(k, v)
	if k[1] <= 0:
		x, y = -k[1], k[0]
		if c[(x, y)] > 0:
			continue
	else:
		x, y = k[1], -k[0]
	res = 0
	res += pow(2, v, MOD) - 1
	res += pow(2, c[(x, y)], MOD) - 1
	res += 1
	ans *= res
	ans %= MOD

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

Submission status: Wrong Answer

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations, combinations_with_replacement
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    n = inp()
    dic = defaultdict(int)
    dic1 = defaultdict(int)
    for _ in range(n):
        a,b = inpm()
        m = gcd(a,b)
        if a != 0 and b == 0:
            a = 1
        elif a == 0 and b != 0:
            b = 1
        else:
            if not (a==0 and b==0):
                a //= m
                b //= m
        if a < 0 and b < 0:
            a = -a
            b = -b
        if a < 0 and b > 0:
            a = -a
            b = -b
        index = ' '.join([str(a),str(b)])
        dic[index] += 1
        dic1[index] += 1
    ans = 1
    dic2 = defaultdict(int)
    for e in dic:
        a,b = map(int,e.split())
        if a == 0 or b == 0:
            continue
        flag = 0
        if a > 0 and b > 0:
            rev = ' '.join([str(b),str(-a)])
        else:
            rev = ' '.join([str(-b),str(a)])
        if dic1[rev] > 0 and dic2[rev] == 0:
            dic2[rev] = 1
            dic2[e] = 1
            flag = 1
        if flag:
            continue
        n1 = pow(2,dic[e],mod)-1
        n2 = pow(2,dic1[rev],mod)-1
        if n1 == 0:
            ans *= (n2+1)
        elif n2 == 0:
            ans *= (n1+1)
        else:
            ans *= (n1+n2+1)
        ans %= mod
    num = 1
    if dic['0 0']:
        num *= (dic['0 0']+1)
        num %= mod
    if dic['1 0']:
        num *= pow(2,dic['1 0'],mod)
        num %= mod
    if dic['0 1']:
        num *= pow(2,dic['0 1'],mod)
        num %= mod
    if num != 0:
        ans *= num
        ans %= mod
    print(ans-1)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
import sys
sys.setrecursionlimit(10**9)
from collections import deque,defaultdict
import heapq
from itertools import combinations
import bisect


mod=10**9+7

n=int(input())

dp=defaultdict(int)
dm=defaultdict(int)
z=0
ans=0
cp=[]
cm=[]
az=0
bz=0
cz=0
for i in range(n):
    a,b=map(int,input().split())
    if a*b>0:
        p=(abs(a)*pow(abs(b),mod-2,mod))%mod
        pp=(abs(b)*pow(abs(a),mod-2,mod))%mod
        if dp[p]==0:
            cp.append([p,pp])
        dp[p]+=1
    elif a*b<0:
        p=(abs(a)*pow(abs(b),mod-2,mod))%mod
        dm[p]+=1
    elif a==b==0:
        cz+=1
    elif a==0:
        az+=1
    elif b==0:
        bz+=1

kk=pow(2,az,mod)+pow(2,bz,mod)+cz-2
if kk>0:
    ans=kk
else:
    ans=1
z=n-(az+bz+cz)
if z==0:
    print(ans+1)
    exit()
for a,b in cp:
    ans*=pow(2,dp[a],mod)+pow(2,dm[b],mod)-1
    ans%=mod
    z-=(dp[a]+dm[b])
# print(z)
ans*=pow(2,z,mod)

# if kk>0:
#     ans+=1

print((ans-1)%mod)

Submission status: Wrong Answer

Solution code:
import collections

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


N = int(input())
fishes = []
for _ in range(N):
    fishes.append([int(s) for s in input().split()])

# fishes = [
#           (3, 0),
#           (0, 3),
#           (0, 0),
#           (3, 2),
# (3, 2),
# (-1 ,1),
# (2 ,-1),
# (-3 ,-9),
# (-8 ,12),
# (7 ,7),
# (8, 1),
# (8 ,2),
# (8, 4),
# ]

slopeCount = collections.defaultdict(int)
for x, y in fishes:
    gcl = getGreatestCommonDivisor(abs(x), abs(y))
    if gcl != 0:
        x //= gcl
        y //= gcl
    if x < 0:
        x = -x
        y = -y
    slopeCount[(x, y)] += 1

# print(slopeCount)

reversedPairs = dict()
independentCount = 0
for slope, count in slopeCount.items():
    x, y = slope
    rx, ry = (y, -x) if y >= 0 else (-y, x)
    if (x, y) == (0, 0):
        independentCount += count
        continue
    if (x, y) in reversedPairs or (rx, ry) in reversedPairs:
        continue
    if (rx, ry) not in slopeCount:
        independentCount += count
        continue
    reversedPairs[(x, y)] = (count, slopeCount[(rx, ry)])
    

# print(reversedPairs, independentCount)

M = 1000000007
def subsetNum(count):
    r = 1
    for _ in range(count):
        r *= 2
        r %= M
    return r

result = subsetNum(independentCount)
if len(reversedPairs) == 0:
    result -= 1
    result %= M
    print(result)
else:
    for c1, c2 in reversedPairs.values():
        result *= (subsetNum(c1) - 1 + subsetNum(c2) - 1 + 1)
        result %= M
    result -= 1
    result %= M
    print(result)

Submission status: Wrong Answer

Solution code:
import math
import numpy as np
import queue
from collections import deque
import heapq
mod = 10**9+7
ans = 1

def twoxxn(t,mod):
    ni = t
    an = 1
    n2 = 2
    while ni > 0:
        if ni%2 == 1:
            an = (an*n2)%mod
        n2 = (n2**2)%mod
        ni //= 2
    return an

n = int(input())
d = dict()
for i in range(n):
    a,b = map(int,input().split())
    if a < 0 and (b < 0 or abs(a) > abs(b)):
        a = -a
        b = -b
    g = math.gcd(abs(a),abs(b))
    if a == 0 and b == 0:
        continue
    elif a == -b:
        if "1 -1" in d:
            d["1 -1"] += 1
        else:
            d["1 -1"] = 1
    elif a == b:
        if "1 1" in d:
            d["1 1"] += 1
        else:
            d["1 1"] = 1
    else:
        p1 = str(a//g)+" "+str(b//g)
        p2 = str(b//g)+" "+str(a//g)
        if p1 in d:
            d[p1] += 1
            d[p2] += 1
        else:
            d[p1] = 1
            d[p2] = 1
print(d)

for i in d.keys():
    i0, i1 = map(int,i.split())
    if abs(i0) < abs(i1):
        continue
    elif str(i0)+" "+str(-i1) in d:
        if d[i] == 0:
            continue
        aaa = (twoxxn(d[str(i0)+" "+str(-i1)],mod)+twoxxn(d[i],mod)-1)%mod
        print(i,aaa)
        ans = (ans*aaa)%mod
        d[str(i0)+" "+str(-i1)] = 0
    else:
        ans = (ans*twoxxn(d[i],mod))%mod
ans = (ans-1)%mod

print(max(1,ans))

Submission status: Wrong Answer

Solution code:
n=int(input())
mod = 1000000007
gp = []
gm = []
ga0  =0
gb0 = 0
ans = 1
cnt = 0
for _ in range(n):
    a,b= map(int,input().split())
    #a,b = 1,1
    if a == 0 and b == 0:
        cnt += 1
    elif  a == 0:
        ga0 += 1
    elif b == 0:
        gb0 += 1
    elif b/a > 0:
        gp.append(b/a)
    else:
        gm.append(-a/b)
gp.sort()
gm.sort()

lp,lm=0,0
cntall = 0
while lp < len(gp) and lm < len(gm):
    cal = gp[lp] - gm[lm]
    if cal == 0:
        cntp,cntm = 1,1
        while lp +1 < len(gp) and  gp[lp] == gp[lp+1]:
            cntp += 1
            lp+=1
        while lm +1 < len(gm) and  gm[lm] == gm[lm+1]:
            cntm += 1
            lm+=1
        ans *= (pow(2,cntp,mod)+pow(2,cntm,mod))%mod-1
        ans %= mod
        lp+=1
        lm+=1
        cntall += cntp+cntm
    elif cal < 0:
        lp += 1
    else:
        lm += 1

ans *= (pow(2,ga0,mod)+pow(2,gb0,mod))%mod-1
ans %= mod
n -= ga0+gb0+cntall+cnt
ans *= pow(2,n,mod)
ans %= mod
ans += cnt - 1
ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
AB = [list(map(int,input().split())) for _ in range (N)]
MOD = 10**9+7

from collections import defaultdict
dnums = defaultdict(int)
dnums2 = defaultdict(int)
num_zero = 0
num_az = 0
num_bz = 0
keys = set()
for a,b in AB:
    if a!=0 and b!=0:
        dnums[b/a] += 1
        keys.add(b/a)
        dnums2[-a/b] += 1
    elif a==0 and b==0:
        num_zero += 1
    elif a == 0 and b!=0:
        num_az += 1
    elif a != 0 and b==0:
        num_bz += 1

mydict = dict()
for key in list(keys):
    mydict[key] = False

ans = 1
for key in list(keys):
    if mydict[key]:
        continue
    if -1/key in keys:
        mydict[-1/key] = True
        mydict[key] = True

    if dnums2[key] != 0:
        ans *= pow(2, dnums[key], MOD) + pow(2, dnums2[key], MOD) - 1
    else:
        ans *= 2

ans *= pow(2, num_az, MOD) + pow(2, num_bz, MOD) - 1
ans += num_zero
ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
import math
from collections import Counter

N = int(input())
A_B = []
mod = 1000000007
for _ in range(N):
    A, B = map(int, input().split())
    if (A == 0) and (B == 0):
        A_B.append((A, B))
    elif A == 0:
        A_B.append((0, -1))
    elif B == 0:
        A_B.append((1, 0))
    else:
        if A < 0:
            A = -A
            B = -B
        C = math.gcd(abs(A), abs(B))
        A_B.append((A // C, B // C))

A_B_C = Counter(A_B)


ans = 1
Done = set([])
for key, value in A_B_C.items():
    if key in Done:
        continue
    keya, keyb = key
    a = 0
    if keya == 0 and keyb == 0:
        a = value + 1
        Done.add((0, 0))
    else:
        if keyb < 0:
            keya = -keya
            keyb = -keyb
        if (keyb, -keya) not in A_B_C:
            a = pow(2, value, mod)
        else:
            a = (pow(2, value, mod) - 1) + (pow(2, A_B_C[(keyb, -keya)], mod) - 1) + 1
            Done.add((keyb, -keya))
    ans *= a
    ans %= mod
    Done.add(key)

print((ans - 1) % mod)