Problem:


Score : 800 points

Problem Statement

There are N lines in the xy-plane. The i-th line is represented by A_ix+B_iy=C_i.
Any two lines among the N+2 lines, the above N lines plus the x-axis and y-axis, cross each other at exactly one point.

For each pair 1 \leq i < j \leq N, there is a car at the cross point of the i-th and j-th lines.
Even where three or more lines intersect at a point, a car is individually placed for each pair of lines.
That is, there will be k(k-1)/2 cars placed at the intersection of k lines.

Those cars are already very old, and can only be moved parallel to the x-axis or y-axis.

Takahashi will hold an exhibition of antique cars at a place on the xy-plane.
In order to avoid damaging the half-broken cars too much, he will select the place of the exhibition so that the total distance covered will be minimized when all the cars are moved to the place.
If such a place is not uniquely determined, among the places that satisfy the condition above, the place with the minimum x-coordinate will be selected.
If the place is still not uniquely determined, among the places that satisfy the two conditions above, the place with the minimum y-coordinate will be selected.

Find the place of the exhibition that will be selected.

Constraints

2 \leq N \leq 4 × 10^4

1 \leq |A_i|,|B_i| \leq 10^4(1 \leq i \leq N)

0 \leq |C_i| \leq 10^4(1 \leq i \leq N)

No two given lines are parallel.

All input values are integers.

Inputs

Input is given from Standard Input in the following format:

N
A_1 B_1 C_1
:
A_N B_N C_N

Outputs

Print the x-coordinate and y-coordinate of the place of the exhibition that will be selected, in this order, with a space in between. The output will be judged as correct when the absolute or relative error is at most 10^{-9}.

Sample Input 1

3
1 1 1
2 -1 2
-1 2 2

Sample Output 1

1.000000000000000 1.000000000000000

There is a car at each place shown by a blue circle in the figure. The place to be selected is shown by a purple circle.

Sample Input 2

4
1 1 2
1 -1 0
3 -1 -2
1 -3 4

Sample Output 2

-1.000000000000000 -1.000000000000000

Sample Input 3

7
1 7 8
-2 4 9
3 -8 -5
9 2 -14
6 7 5
-8 -9 3
3 8 10

Sample Output 3

-1.722222222222222 1.325000000000000



Sample input:
3
1 1 1
2 -1 2
-1 2 2


Sample output:
1.000000000000000 1.000000000000000

Submission status: Time Limit Exceeded

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

class BIT:
    #1-indexed
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
        self.p = 2**(n.bit_length() - 1)
        self.dep = n.bit_length()
    def get(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
    
    def bl(self, v):
        if v <= 0:
            return -1
        s = 0
        k = self.p
        for _ in range(self.dep):
            if s + k <= self.size and self.tree[s+k] < v:
                s += k
                v -= self.tree[s+k]
            k //= 2
        return s + 1
    
    def reset(self):
        self.tree = [0]*(self.size+1)

N = int(readline())
INF = 1e9
EPS = 1e-9

Points = [tuple(map(int, readline().split())) for _ in range(N)]
XA = [-a/b for a, b, _ in Points]
XB = [c/b for _, b, c in Points]
YA = [-b/a for a, b, _ in Points]
YB = [c/a for a, _, c in Points]
con = -(-N*(N-1)//4)
T = BIT(N)

ds = sorted(range(N), key = lambda x: XA[x])
rd = [None]*N
for i in range(N):
    rd[ds[i]] = i

ng = -INF
ok = INF

while abs(ok-ng)/max(1, min(abs(ok), abs(ng))) > EPS:
    med = (ok+ng)/2
    T.reset()
    res = 0
    for idx in sorted(range(N), key = lambda x: XA[x]*med + XB[x]):
        res += T.get(rd[idx]+1)
        T.add(rd[idx]+1, 1)
    if res >= con:
        ok = med
    else:
        ng = med

X = ok

ds = sorted(range(N), key = lambda x: YA[x])

rd = [None]*N
for i in range(N):
    rd[ds[i]] = i

ng = -INF
ok = INF

while abs(ok-ng)/max(1, min(abs(ok), abs(ng))) > EPS:
    med = (ok+ng)/2
    T.reset()
    res = 0
    for idx in sorted(range(N), key = lambda x: YA[x]*med + YB[x]):
        res += T.get(rd[idx]+1)
        T.add(rd[idx]+1, 1)
    if res >= con:
        ok = med
    else:
        ng = med

Y = ok

print(X, Y)

Submission status: Time Limit Exceeded

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

class BIT:
    #1-indexed
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
        self.p = 2**(n.bit_length() - 1)
        self.dep = n.bit_length()
    def get(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
    
    def bl(self, v):
        if v <= 0:
            return -1
        s = 0
        k = self.p
        for _ in range(self.dep):
            if s + k <= self.size and self.tree[s+k] < v:
                s += k
                v -= self.tree[s+k]
            k //= 2
        return s + 1

N = int(readline())
INF = 1e9
EPS = 1e-9

Points = [tuple(map(int, readline().split())) for _ in range(N)]
XA = [-a/b for a, b, _ in Points]
XB = [c/b for _, b, c in Points]
YA = [-b/a for a, b, _ in Points]
YB = [c/a for a, _, c in Points]
ds = sorted(range(N), key = lambda x: XA[x])

rd = [None]*N
for i in range(N):
    rd[ds[i]] = i

ng = -INF
ok = INF

con = -(-N*(N-1)//4)
while abs(ok-ng) > EPS:
    med = (ok+ng)/2
    T = BIT(N)
    res = 0
    for idx in sorted(range(N), key = lambda x: XA[x]*med + XB[x]):
        res += T.get(rd[idx]+1)
        T.add(rd[idx]+1, 1)
    if res >= con:
        ok = med
    else:
        ng = med

X = ok

ds = sorted(range(N), key = lambda x: YA[x])

rd = [None]*N
for i in range(N):
    rd[ds[i]] = i

ng = -INF
ok = INF

while abs(ok-ng) > EPS:
    med = (ok+ng)/2
    T = BIT(N)
    res = 0
    for idx in sorted(range(N), key = lambda x: YA[x]*med + YB[x]):
        res += T.get(rd[idx]+1)
        T.add(rd[idx]+1, 1)
    if res >= con:
        ok = med
    else:
        ng = med

Y = ok

print(X, Y)

Submission status: Time Limit Exceeded

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

class BIT:
    #1-indexed
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
        self.p = 2**(n.bit_length() - 1)
        self.dep = n.bit_length()
    def get(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
    
    def bl(self, v):
        if v <= 0:
            return -1
        s = 0
        k = self.p
        for _ in range(self.dep):
            if s + k <= self.size and self.tree[s+k] < v:
                s += k
                v -= self.tree[s+k]
            k //= 2
        return s + 1

N = int(readline())

Points = [tuple(map(int, readline().split())) for _ in range(N)]

ds = sorted(range(N), key = lambda x: -Points[x][0]/Points[x][1])

rd = [None]*N
for i in range(N):
    rd[ds[i]] = i

ng = -10**18
ok = 10**18

con = -(-N*(N-1)//4)
for _ in range(100):
    med = (ok+ng)/2
    T = BIT(N)
    res = 0
    for idx in sorted(range(N), key = lambda x: -Points[x][0]/Points[x][1]*med + Points[x][2]/Points[x][1]):
        res += T.get(rd[idx]+1)
        T.add(rd[idx]+1, 1)
    if res >= con:
        ok = med
    else:
        ng = med

X = ok

ds = sorted(range(N), key = lambda x: -Points[x][1]/Points[x][0])

rd = [None]*N
for i in range(N):
    rd[ds[i]] = i

ng = -10**18
ok = 10**18

for _ in range(100):
    med = (ok+ng)/2
    T = BIT(N)
    res = 0
    for idx in sorted(range(N), key = lambda x: -Points[x][1]/Points[x][0]*med + Points[x][2]/Points[x][0]):
        res += T.get(rd[idx]+1)
        T.add(rd[idx]+1, 1)
    if res >= con:
        ok = med
    else:
        ng = med

Y = ok

print(X, Y)

Submission status: Time Limit Exceeded

Solution code:
def addbit(i):
    i += 1
    while i <= N:
        BIT[i] += 1
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0] * (N+1)
    re = 0
    for l in L:
        re += getsum(l)
        addbit(l)
    return N*(N-1)//2 - re
def get_rank(L):
    D = {x:i for i,x in enumerate(sorted(L))}
    return [D[x] for x in L]
def calc(Z):
    Z.sort()
    l, r, lc, rc = -1<<28, 1<<28, N*(N-1)//4+1, N*(N-1)//4+1
    f = 1
    while (r - l) / max(abs(l), 1) > 0.000000001:
        m = (l+r) / 2 if f else (l * rc + r * lc) / (lc + rc)
        A = [b for a, b in sorted([(s*m+t, i) for i, (s, t) in enumerate(Z)])]
        A = get_rank([s*m+t for s, t in Z])
        c = bit(A)
        if c > N*(N-1)//4:
            l = m
            lc = (c - N*(N-1)//4) * 2
        else:
            r = m
            rc = (N*(N-1)//4 - c) * 2 + 1
        f ^= 1
    return l

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))

Submission status: Time Limit Exceeded

Solution code:
def addbit(i):
    i += 1
    while i <= N:
        BIT[i] += 1
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0] * (N+1)
    re = 0
    for l in L:
        re += getsum(l)
        addbit(l)
    return N*(N-1)//2 - re
def calc(Z):
    Z.sort()
    l, r, lc, rc = -1<<28, 1<<28, N*(N-1)//4+1, N*(N-1)//4+1
    f = 1
    while (r - l) / max(abs(l), 1) > 0.000000001:
        m = (l+r) / 2 if f else (l * rc + r * lc) / (lc + rc)
        A = [b for a, b in sorted([(s*m+t, i) for i, (s, t) in enumerate(Z)])]
        c = bit(A)
        if c > N*(N-1)//4:
            l = m
            lc = (c - N*(N-1)//4) * 2
        else:
            r = m
            rc = (N*(N-1)//4 - c) * 2 + 1
        f ^= 1
    return l

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))

Submission status: Time Limit Exceeded

Solution code:
def addbit(i):
    i += 1
    while i <= N:
        BIT[i] += 1
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0] * (N+1)
    re = 0
    for l in L:
        re += getsum(l)
        addbit(l)
    return N*(N-1)//2 - re
def calc(Z):
    Z.sort()
    l, r, lc, rc = -1<<28, 1<<28, N*(N-1)//4+1, N*(N-1)//4+1
    while (r - l) / max(abs(l), 1) > 0.000000001:
        m = (l+r) / 2
        A = [a&((1<<16)-1) for a in sorted([(int((s*m+t)*2**40)<<16)+i for i, (s, t) in enumerate(Z)])]
        c = bit(A)
        if c > N*(N-1)//4:
            l = m
            lc = (c - N*(N-1)//4) * 2
        else:
            r = m
            rc = (N*(N-1)//4 - c) * 2 + 1
    return l

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))

Submission status: Time Limit Exceeded

Solution code:
def addbit(i):
    i += 1
    while i <= N:
        BIT[i] += 1
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0] * (N+1)
    re = 0
    for i, l in enumerate(L):
        re += i - getsum(l)
        addbit(l)
    return re
def calc(Z):
    Z.sort()
    l, r, lc, rc = -1<<28, 1<<28, N*(N-1)//4+1, N*(N-1)//4+1
    f = 1
    while r - l > 0.000000001:
        m = (l+r) / 2 if f else (l * rc + r * lc) / (lc + rc)
        A = [a&((1<<16)-1) for a in sorted([(int((s*m+t)*2**40)<<16)+i for i, (s, t) in enumerate(Z)])]
        c = bit(A)
        if c > N*(N-1)//4:
            l = m
            lc = (c - N*(N-1)//4) * 2
        else:
            r = m
            rc = (N*(N-1)//4 - c) * 2 + 1
        f ^= 1
    return l

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))

Submission status: Time Limit Exceeded

Solution code:
def addbit(i):
    i += 1
    while i <= N:
        BIT[i] += 1
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0] * (N+1)
    re = 0
    for l in L:
        re += getsum(l)
        addbit(l)
    return N*(N-1)//2 - re
def calc(Z):
    Z.sort()
    l, r, lc, rc = -1<<28, 1<<28, N*(N-1)//4+1, N*(N-1)//4+1
    f = 1
    while r - l > 0.000000001:
        m = (l+r) / 2 if f else (l * rc + r * lc) / (lc + rc)
        A = [a&((1<<16)-1) for a in sorted([(int((s*m+t)*2**40)<<16)+i for i, (s, t) in enumerate(Z)])]
        c = bit(A)
        if c > N*(N-1)//4:
            l = m
            lc = (c - N*(N-1)//4) * 2
        else:
            r = m
            rc = (N*(N-1)//4 - c) * 2 + 1
        f ^= 1
    return l

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))

Submission status: Time Limit Exceeded

Solution code:
def addbit(i):
    i += 1
    while i <= N:
        BIT[i] += 1
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0] * (N+1)
    re = 0
    for l in L:
        re += getsum(l)
        addbit(l)
    return N*(N-1)//2 - re
def calc(Z):
    Z.sort()
    l, r, lc, rc = -1<<20, 1<<20, N*(N-1)//4+1, N*(N-1)//4+1
    if N <= 10000: l, r = -1<<28, 1<<28
    while r - l > 0.000000001:
        m = (l+r) / 2 if N <= 10000 else (l * rc + r * lc) / (lc + rc)
        A = [a&((1<<16)-1) for a in sorted([(int((s*m+t)*2**(100 if N <= 10000 else 40))<<16)+i for i, (s, t) in enumerate(Z)])]
        c = bit(A)
        if c > N*(N-1)//4:
            l = m
            lc = (c - N*(N-1)//4) * 2
        else:
            r = m
            rc = (N*(N-1)//4 - c) * 2 + 1
    return l

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))

Submission status: Time Limit Exceeded

Solution code:
def addbit(i):
    i += 1
    while i <= N:
        BIT[i] += 1
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0] * (N+1)
    re = 0
    for l in L:
        re += getsum(l)
        addbit(l)
    return N*(N-1)//2 - re
def calc(Z):
    Z.sort()
    l, r, lc, rc = -1<<20, 1<<20, N*(N-1)//4+1, N*(N-1)//4+1
    if N <= 10000: l, r = -1<<28, 1<<28
    while r - l > 0.000000001:
        m = (l+r) / 2 if N <= 10000 else (l * rc + r * lc) / (lc + rc)
        A = [a&((1<<16)-1) for a in sorted([(int((s*m+t)*2**40)<<16)+i for i, (s, t) in enumerate(Z)])]
        c = bit(A)
        if c > N*(N-1)//4:
            l = m
            lc = (c - N*(N-1)//4) * 2
        else:
            r = m
            rc = (N*(N-1)//4 - c) * 2 + 1
    return l

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))

Submission status: Time Limit Exceeded

Solution code:
def addbit(i):
    i += 1
    while i <= N:
        BIT[i] += 1
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0] * (N+1)
    re = 0
    for l in L:
        re += getsum(l)
        addbit(l)
    return N*(N-1)//2 - re
def calc(Z):
    Z.sort()
    l, r, lc, rc = -1<<28, 1<<28, N*(N-1)//4+1, N*(N-1)//4+1
    while r - l > 0.000000001:
        m = (l * rc + r * lc) / (lc + rc)
        A = [a&((1<<16)-1) for a in sorted([(int((s*m+t)*2**40)<<16)+i for i, (s, t) in enumerate(Z)])]
        c = bit(A)
        if c > N*(N-1)//4:
            l = m
            lc = ((c - N*(N-1)//4) * 2) ** 0.5
        else:
            r = m
            rc = ((N*(N-1)//4 - c) * 2 + 1) ** 0.5
    return l

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))

Submission status: Time Limit Exceeded

Solution code:
def addbit(i):
    i += 1
    while i <= N:
        BIT[i] += 1
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0] * (N+1)
    re = 0
    for l in L:
        re += getsum(l)
        addbit(l)
    return N*(N-1)//2 - re
def calc(Z):
    Z.sort()
    l, r, lc, rc = -1<<20, 1<<20, N*(N-1)//4+1, N*(N-1)//4+1
    if N <= 10000: l, r = -1<<28, 1<<28
    while r - l > 0.000000001:
        m = (l * rc + r * lc) / (lc + rc)
        A = [a&((1<<16)-1) for a in sorted([(int((s*m+t)*2**40)<<16)+i for i, (s, t) in enumerate(Z)])]
        c = bit(A)
        if c > N*(N-1)//4:
            l = m
            lc = ((c - N*(N-1)//4) * 2) ** 0.5
        else:
            r = m
            rc = ((N*(N-1)//4 - c) * 2 + 1) ** 0.5
    return l

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))

Submission status: Time Limit Exceeded

Solution code:
def addbit(i):
    i += 1
    while i <= N:
        BIT[i] += 1
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0] * (N+1)
    re = 0
    for l in L:
        re += getsum(l)
        addbit(l)
    return N*(N-1)//2 - re
def calc(Z):
    Z.sort()
    l, r, lc, rc = -1<<20, 1<<20, N*(N-1)//4+1, N*(N-1)//4+1
    if N <= 10000: l, r = -1<<32, 1<<32
    while r - l > 0.000000001:
        m = (l * rc + r * lc) / (lc + rc)
        A = [a&((1<<16)-1) for a in sorted([(int((s*m+t)*2**40)<<16)+i for i, (s, t) in enumerate(Z)])]
        c = bit(A)
        if c > N*(N-1)//4:
            l = m
            lc = ((c - N*(N-1)//4) * 2) ** 0.5
        else:
            r = m
            rc = ((N*(N-1)//4 - c) * 2 + 1) ** 0.5
    return l

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))

Submission status: Time Limit Exceeded

Solution code:
def addbit(i):
    i += 1
    while i <= N:
        BIT[i] += 1
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0] * (N+1)
    re = 0
    for l in L:
        re += getsum(l)
        addbit(l)
    return N*(N-1)//2 - re
def calc(Z):
    Z.sort()
    l, r, lc, rc = -1<<32, 1<<32, N*(N-1)//4, N*(N-1)//4
    f = 1
    while r - l > 0.000000001:
        m = (l+r) / 2
        A = [a&((1<<16)-1) for a in sorted([(int((s*m+t)*2**40)<<16)+i for i, (s, t) in enumerate(Z)])]
        c = bit(A)
        if c > N*(N-1)//4:
            l = m
            lc = c - N*(N-1)//4
        else:
            r = m
            rc = max(N*(N-1)//4 - c, 1)
        
        f ^= 1
    return l

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))

Submission status: Time Limit Exceeded

Solution code:
def addbit(i):
    i += 1
    while i <= N:
        BIT[i] += 1
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0] * (N+1)
    re = 0
    for l in L:
        re += getsum(l)
        addbit(l)
    return N*(N-1)//2 - re
def calc(Z):
    Z.sort()
    l, r, lc, rc = -1<<32, 1<<32, N*(N-1)//4, N*(N-1)//4
    f = 1
    while r - l > 0.000000001:
        m = (l+r) / 2 if f else (l * rc + r * lc) / (lc + rc)
        A = [a&((1<<16)-1) for a in sorted([(int((s*m+t)*2**40)<<16)+i for i, (s, t) in enumerate(Z)])]
        c = bit(A)
        if c > N*(N-1)//4:
            l = m
            lc = c - N*(N-1)//4
        else:
            r = m
            rc = max(N*(N-1)//4 - c, 1)
        
        f ^= 1
    return l

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))

Submission status: Time Limit Exceeded

Solution code:
def addbit(i):
    i += 1
    while i <= N:
        BIT[i] += 1
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0] * (N+1)
    re = 0
    for i, l in enumerate(L):
        re += i - getsum(l)
        addbit(l)
    return re
def calc(Z):
    Z.sort()
    l, r = -1<<31, 1<<31
    for i in range(63):
        m = (l+r) / 2
        A = [a&((1<<16)-1) for a in sorted([(int((s*m+t)*2**40)<<16)+i for i, (s, t) in enumerate(Z)])]
        if bit(A) > N*(N-1)//4:
            l = m
        else:
            r = m
    return l

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))

Submission status: Time Limit Exceeded

Solution code:
NN = 16
def addbit(i, x=1):
    i += 1
    while i <= 2**NN:
        BIT[i] += x
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0]*(2**NN+1)
    re = 0
    for i, l in enumerate(L):
        re += i - getsum(l)
        addbit(l)
    return re
def calc(Z):
    Z.sort()
    l, r = -1<<27, 1<<27
    for i in range(70):
        m = (l+r) / 2
        A = [b for a, b in sorted([(s*m+t, i) for i, (s, t) in enumerate(Z)])]
        if bit(A) > N*(N-1)//4:
            l = m
        else:
            r = m
    return l

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))

Submission status: Time Limit Exceeded

Solution code:
NN = 16
def addbit(i, x=1):
    i += 1
    while i <= 2**NN:
        BIT[i] += x
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0]*(2**NN+1)
    re = 0
    for i, l in enumerate(L):
        re += i - getsum(l)
        addbit(l)
    return re
def calc(Z):
    l, r = -1<<30, 1<<30
    for i in range(150):
        m = (l+r) / 2
        A = [b for a, b in sorted([(s*m+t, i) for i, (s, t) in enumerate(sorted(Z))])]
        if bit(A) > N*(N-1)//4:
            l = m
        else:
            r = m
    return l

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
ABC = list(map(int,read().split()))
A = ABC[::3]; B = ABC[1::3]; C = ABC[2::3]

class BIT():
    def __init__(self, max_n):
        self.size = max_n + 1
        self.tree = [0] * self.size
        
    def get_sum(self,i):
        s = 0
        while i:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i < self.size:
            self.tree[i] += x
            i += i & -i

def Inversion(seq):
    # seqは、1,2,...,Nの順列
    N = len(seq)
    bit = BIT(N)
    inv = N*(N-1)//2
    for x in seq:
        inv -= bit.get_sum(x)
        bit.add(x,1)
    return inv

def get_rank(seq):
    x_to_i = {x:i for i,x in enumerate(sorted(seq))}
    return [1+x_to_i[x] for x in seq]

def solve_x(A,B,C):
    M = (N*(N-1)//2+1)//2 # 必要な交点個数
    U = 2*10**8 + 100 # 交点の座標の上界
    left = -U # 交点の個数の合計が M 個に満たない
    right = U # 交点の個数の合計が M 個以上である
    # x = -inf における y の順序
    order = sorted(range(N),key = lambda i: A[i]/B[i])
    def test(x):
        y = [(C[i]-A[i]*x)/(B[i]) for i in order]
        seq = get_rank(y)
        return Inversion(seq) >= M
    
    for _ in range(60):
        mid = (left + right)/2
        if test(mid):
            right = mid
        else:
            left = mid
    return (left + right)/2

x = solve_x(A,B,C)
y = solve_x(B,A,C)
print(x,y)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

import math
import fractions
import heapq
import collections
import re
import array
import bisect
import itertools

from collections import Counter, defaultdict


def argsort(l, one_base=False):
    return sorted(range(one_base, len(l) + one_base), key=lambda i: l[i-one_base])


class BinaryIndexedTree(object):
    def __init__(self, N):
        self.N = N
        self.tree = [0] * (N + 1)

    def add(self, a, w):
        x = a
        while x <= self.N:
            self.tree[x] += w
            x += (x & -x)

    def sum(self, a):
        if a == 0:
            return 0
        s = 0
        x = a
        while x > 0:
            s += self.tree[x]
            x -= (x & -x)
        return s


def count_inv(A):
    bit = BinaryIndexedTree(100001)
    ans = 0
    for j in range(len(A)):
        ans += j - bit.sum(A[j])
        bit.add(A[j], 1)
    return ans


def count_crossed_lines(N, C, a, b, x):
    c = 2
    Y = [(-C[i][a] * x + C[i][c]) / C[i][b] for i in range(N)]
    yl = argsort(Y, one_base=True)
    c = count_inv(yl)
    return c


def find_coord(N, C, a, b):
    med_v = math.ceil(N * (N-1) / 4)
    iangles = [C[i][a] / C[i][b] for i in range(N)]
    coefs = [C[i] for i in argsort(iangles)]
    # bin-search
    INF = 1e9
    rg = [-INF, INF]
    d = rg[1] - rg[0]
    m = (rg[1] + rg[0]) / 2
    while d > 1e-9:
        m = (rg[1] + rg[0]) / 2
        cl = count_crossed_lines(N, coefs, a, b, m)
        if cl < med_v:
            rg[0] = m
        else:
            rg[1] = m
        d = rg[1] - rg[0]
    return m


def main():
    N = int(input())
    coefs = [None] * N
    for i in range(N):
        a, b, c = map(int, input().split(" "))
        coefs[i] = (a, b, c)
    x = find_coord(N, coefs, 0, 1)
    y = find_coord(N, coefs, 1, 0)
    print("{} {}".format(x, y))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from math import sqrt
N = int(input())
D = []
for i in range(N):
    a, b, c = map(int, input().split())
    if a > 0:
        a = -a; b = -b; c = -c
    D.append((a, b, c))

def solve(P):
    EPS = 10**-10
    left = -10**8; right = 10**8
    def get(i):
        s = 0
        while i:
            s += data[i]
            i -= i & -i
        return s
    def add(i, x):
        while i <= N:
            data[i] += x
            i += i & -i
    VV = []; LI = []
    for i in range(N):
        a, b, c = P[i]
        v = b / sqrt(a**2 + b**2)
        VV.append((v, i))
        LI.append([a, b, c, -v, None])
    VV.sort(reverse=1)
    for i, e in enumerate(VV):
        LI[e[1]][-1] = i+1
    while right - left > EPS:
        mid = (left + right) / 2
        ps = [((c - b*mid) / a, v, i) for a, b, c, v, i in LI]
        ps.sort()
        res = 0
        data = [0]*(N+1)
        for p, v, i in ps:
            res += get(i)
            add(i, 1)
        if res > N*(N-1)/4:
            left = mid
        else:
            right = mid
    return mid

XA = solve(D)
E = [(b, a, c) if b < 0 else (-b, -a, -c) for a, b, c in D]
YA = solve(E)
print(YA, XA)

Submission status: Time Limit Exceeded

Solution code:
from math import sqrt
N = int(input())
D = []
for i in range(N):
    a, b, c = map(int, input().split())
    if a > 0:
        a = -a; b = -b; c = -c
    D.append((a, b, c))

def solve(P):
    EPS = 10**-12
    left = -10**8; right = 10**8
    def get(i):
        s = 0
        while i:
            s += data[i]
            i -= i & -i
        return s
    def add(i, x):
        while i <= N:
            data[i] += x
            i += i & -i
    VV = []
    for i in range(N):
        a, b, c = P[i]
        VV.append((b / sqrt(a**2 + b**2), i))
        #print(i, b / sqrt(a**2 + b**2))
    VV.sort(reverse=1)
    ID = [0]*N
    for i, e in enumerate(VV):
        ID[e[1]] = i+1
    #print(ID)
    while right - left > EPS:
        data = [0]*(N+1)
        mid = (left + right) / 2
        ps = []
        for i in range(N):
            a, b, c = P[i]
            ps.append(((c - b*mid) / a, -b / sqrt(a**2 + b**2), i))
        ps.sort()
        cnt = 0; res = 0
        for p, v, i in ps:
            #print(">", mid, i, get(ID[i]))
            res += get(ID[i])
            add(ID[i], 1)
        #print(mid, res)
        if res > N*(N-1)/4:
            left = mid
        else:
            right = mid
    return mid

XA = solve(D)
E = [(b, a, c) if b < 0 else (-b, -a, -c) for a, b, c in D]
YA = solve(E)
print(YA, XA)

Submission status: Accepted

Solution code:
import os
import sys
import numpy as np

# >>> binary indexed tree >>>
# 必要な要素数+1 の長さの ndarray の 1 要素目以降を使う

def bit_sum(bit, i):  # [bit_sum, "i8(i8[:],i8)"],
    # (0, i]
    res = 0
    while i:
        res += bit[i]
        i -= i & -i
    return res

def bit_add(bit, i, val):  # [bit_add, "void(i8[:],i8,i8)"],
    n = len(bit)
    while i < n:
        bit[i] += val
        i += i & -i

# <<< binary indexed tree <<<


def inversion_number(arr):  # [inversion_number, "i8(f8[:])"],
    # 転倒数
    n = len(arr)
    arr = np.argsort(arr) + 1
    bit = np.zeros(n+1, dtype=np.int64)
    res = n * (n-1) >> 1
    for val in arr:
        res -= bit_sum(bit, val)
        bit_add(bit, val, 1)
    return res


# >>> numba compile >>

numba_config = [
    [bit_sum, "i8(i8[:],i8)"],
    [bit_add, "void(i8[:],i8,i8)"],
    [inversion_number, "i8(f8[:])"],
]
if sys.argv[-1] == "ONLINE_JUDGE":
    from numba import njit
    from numba.pycc import CC
    cc = CC("my_module")
    for func, signature in numba_config:
        vars()[func.__name__] = njit(signature)(func)
        cc.export(func.__name__, signature)(func)
    cc.compile()
    exit()
elif os.name == "posix":
    exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
else:
    from numba import njit
    for func, signature in numba_config:
        vars()[func.__name__] = njit(signature, cache=True)(func)
    print("compiled", file=sys.stderr)

# <<< numba compile <<<


N = int(input())
ABC = [list(map(int, input().split())) for _ in range(N)]
A, B, C = zip(*ABC)
th = N*(N-1)//2 // 2 + 1
def solve(A, B, C):
    # y = (-Ax+C) / B
    if N < 100:
        ok = -1e10
        ng = 1e10
        n_iteration = 70
    else:
        ok = -1e4
        ng = 1e4
        n_iteration = 46
    A, B, C = zip(*sorted(zip(A, B, C), key=lambda x: -x[0]/x[1]))
    A = np.array(A)
    B = np.array(B)
    C = np.array(C)
    for _ in range(n_iteration):
        x = (ok+ng) * 0.5
        Y = (-A*x+C) / B
        inv_num = inversion_number(Y)
        if inv_num >= th:
            ok = x
        else:
            ng = x
    return ok

print(solve(A, B, C), solve(B, A, C))