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: Wrong Answer

Solution code:
import time
sTime = time.time()
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, tl):
    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 and time.time() - sTime < tl:
        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**38)<<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, 2.4), calc(Y, 4.8))

Submission status: Wrong Answer

Solution code:
import time
sTime = time.time()
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, tl):
    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 and time.time() - sTime < tl:
        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**35)<<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, 2.4), calc(Y, 4.8))

Submission status: Wrong Answer

Solution code:
import time
sTime = time.time()
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, tl):
    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 and time.time() - sTime < tl:
        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, 2.4), calc(Y, 4.8))

Submission status: Wrong Answer

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
    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
        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: Wrong Answer

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+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**35)<<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.7
        else:
            r = m
            rc = ((N*(N-1)//4 - c) * 2 + 1) ** 0.7
    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: Wrong Answer

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+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**35)<<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: Wrong Answer

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+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**32)<<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: Wrong Answer

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+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**35)<<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: Wrong Answer

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 = -1<<64, 1<<64
    while r - l > 1:
        m = (l+r) // 2
        A = [a&((1<<16)-1) for a in sorted([(s*m+t<<16)+i for i, (s, t) in enumerate(Z)])]
        if bit(A) > N*(N-1)//4:
            l = m
        else:
            r = m
    return l / 2**32

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

Submission status: Wrong Answer

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 = -1<<64, 1<<64
    while r - l > 1:
        m = (l+r) // 2
        A = [a&((1<<16)-1) for a in sorted([(s*m+t<<16)+i for i, (s, t) in enumerate(Z)])]
        if bit(A) > N*(N-1)//4:
            l = m
        else:
            r = m
    return l / 2**32

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

Submission status: Wrong Answer

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**32)<<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: Wrong Answer

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<<30, 1<<30
    for i in range(64):
        m = (l+r) / 2
        A = [a&((1<<16)-1) for a in sorted([(int((s*m+t)*2**32)<<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: Wrong Answer

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<<16, 1<<16
    for i in range(50):
        m = (l+r) / 2
        A = [a&((1<<16)-1) for a in sorted([(int((s*m+t)*2**32)<<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: Wrong Answer

Solution code:
def addbit(i, x=1):
    i += 1
    while i <= N:
        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] * (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<<16, 1<<16
    for i in range(50):
        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: Wrong Answer

Solution code:
import sys
import socket

if socket.gethostname() in ['N551J', 'F551C']:
    sys.stdin = open('e1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def find_median(n, A, B, C):
    def slope(u):
        return -u[0] / u[1]

    lines = list(zip(A, B, C))
    lines.sort(key=slope)

    inf = 10 ** 20
    sa = -inf
    sb = inf
    n_steps = 100
    n_inversions_max = (n - 1) * n // 2
    for _ in range(n_steps):
        s = (sa + sb) / 2
        y = [(-a * s + c) / b for a, b, c, in lines]
        y.insert(0, 0)
        p = list(range(1, n + 1))
        p.sort(key=y.__getitem__, reverse=True)
        c = count_inversions(n, p)
        if c > n_inversions_max // 2:
            sb = s
        else:
            sa = s
    return s

def count_inversions(n, p):
    """Count the number of inversions
        t is the implicit data structure
        s[j] is the sum over ] j - j & -j, j]
    """
    res = 0
    s = [0] * (n + 1)
    for k in range(n):
        # sum over 1 .. t[p[k]]
        c = 0
        u = p[k]
        while u > 0:
            c += s[u]
            u -= u & -u
        # increment t[p[k]]
        u = p[k]
        while u <= n:
            s[u] += 1
            u += u & -u

        res += k - c
    return res


def count_inversions_slow_but_correct(n, p):
    """Count the number of inversions
        t is the implicit data structure
        s[j] is the sum over ] j - j & -j, j]
    """
    res = 0
    for i in range(n):
        for j in range(i+1, n):
            res += p[i] > p[j]
    return res


def solve():
    n = read_int()
    a, b, c = zip(*[read_int_list() for i in range(n)])
    # find the median of x-coordinates
    x = find_median(n, a, b, c)
    y = find_median(n, b, a, c)
    return x, y


def main():
    res = solve()
    print(*res)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import socket

if socket.gethostname() in ['N551J', 'F551C']:
    sys.stdin = open('e1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def find_median(n, A, B, C):
    def slope(u):
        return -u[0] / u[1]

    lines = list(zip(A, B, C))
    lines.sort(key=slope)

    inf = 10 ** 20
    sa = -inf
    sb = inf
    n_steps = 100
    for _ in range(n_steps):
        s = (sa + sb) / 2
        y = [(-a * s + c) / b for a, b, c, in lines]
        y.insert(0, 0)
        p = list(range(1, n + 1))
        p.sort(key=y.__getitem__)
        c = count_inversions(n, p)
        if 2 * c < (n - 1) * n // 2:
            sb = s
        else:
            sa = s
    return s

def count_inversions(n, p):
    """Count the number of inversions
        t is the implicit data structure
        s[j] is the sum over ] j - j & -j, j]
    """
    res = 0
    s = [0] * (n + 1)
    for k in range(n):
        # sum over 1 .. t[p[k]]
        c = 0
        u = p[k]
        while u > 0:
            c += s[u]
            u -= u & -u
        # increment t[p[k]]
        u = p[k]
        while u <= n:
            s[u] += 1
            u += u & -u

        res += k - c
    return res


def count_inversions_slow_but_correct(n, p):
    """Count the number of inversions
        t is the implicit data structure
        s[j] is the sum over ] j - j & -j, j]
    """
    res = 0
    for i in range(n):
        for j in range(i+1, n):
            res += p[i] > p[j]
    return res


def solve():
    n = read_int()
    a, b, c = zip(*[read_int_list() for i in range(n)])
    # find the median of x-coordinates
    x = find_median(n, a, b, c)
    y = find_median(n, b, a, c)
    return x, y


def main():
    res = solve()
    print(*res)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import socket

if socket.gethostname() in ['N551J', 'F551C']:
    sys.stdin = open('e1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def find_median(n, A, B, C):
    def slope(u):
        return -u[0] / u[1]

    lines = list(zip(A, B, C))
    lines.sort(key=slope)

    inf = 10 ** 20
    sa = -inf
    sb = inf
    n_steps = 300
    for _ in range(n_steps):
        s = (sa + sb) / 2
        y = [(-a * s + c) / b for a, b, c, in lines]
        y.insert(0, 0)
        p = list(range(1, n + 1))
        p.sort(key=y.__getitem__)
        c = count_inversions(n, p)
        if 2 * c < (n - 1) * n // 2:
            sb = s
        else:
            sa = s
    return s

def count_inversions(n, p):
    """Count the number of inversions
        t is the implicit data structure
        s[j] is the sum over ] j - j & -j, j]
    """
    res = 0
    s = [0] * (n + 1)
    for k in range(n):
        # sum over 1 .. t[p[k]]
        c = 0
        u = p[k]
        while u > 0:
            c += s[u]
            u -= u & -u
        # increment t[p[k]]
        u = p[k]
        while u <= n:
            s[u] += 1
            u += u & -u

        res += k - c
    return res


def count_inversions_slow_but_correct(n, p):
    """Count the number of inversions
        t is the implicit data structure
        s[j] is the sum over ] j - j & -j, j]
    """
    res = 0
    for i in range(n):
        for j in range(i+1, n):
            res += p[i] > p[j]
    return res


def solve():
    n = read_int()
    a, b, c = zip(*[read_int_list() for i in range(n)])
    # find the median of x-coordinates
    x = find_median(n, a, b, c)
    y = find_median(n, b, a, c)
    return x, y


def main():
    res = solve()
    print(*res)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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**18; right = 10**18
    def count(i):
        s = 0; j = i
        while i:
            s += data.get(i, 0)
            i -= i & -i
        while j <= N:
            data[j] = data.get(j, 0) + 1
            j += j & -j
        return s
    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([b/a, c/a, -v, None])
    VV.sort(reverse=1)
    def key(x):
        b,c,v,i=x
        return (c*10**10 - b*mid, v, i)
    for i, e in enumerate(VV):
        LI[e[1]][-1] = i+1
    half = N*(N-1)//4
    while left + 1 < right:
        mid = (left + right) // 2
        LI.sort(key=key)
        data = {}
        res = 0; cnt = 0; rest = N*(N-1)//2
        for b, c, v, i in LI:
            if res > half or rest + res < half:
                break
            res += count(i)
            rest -= cnt
            cnt += 1
        if res > half:
            left = mid
        else:
            right = mid
    return mid/10**10

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: Wrong Answer

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 count(i):
        s = 0; j = i
        while i:
            s += data.get(i, 0)
            i -= i & -i
        while j <= N:
            data[j] = data.get(j, 0) + 1
            j += j & -j
        return s
    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([b/a, c/a, -v, None])
    VV.sort(reverse=1)
    def key(x):
        b,c,v,i=x
        return (c - b*mid, v, i)
    for i, e in enumerate(VV):
        LI[e[1]][-1] = i+1
    half = N*(N-1)/4
    while right - left > EPS:
        mid = (left + right) / 2
        LI.sort(key=key)
        data = {}
        res = 0; cnt = 0; rest = N*(N-1)/2
        for b, c, v, i in LI:
            if res > half or rest + res < half:
                break
            res += count(i)
            rest -= cnt
            cnt += 1
        if res > half:
            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: Wrong Answer

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 count(i):
        s = 0; j = i
        while i:
            s += data.get(i, 0)
            i -= i & -i
        while j <= N:
            data[j] = data.get(j, 0) + 1
            j += j & -j
        return s
    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([b/a, c/a, -v, None])
    VV.sort(reverse=1)
    def key(x):
        b,c,v,i=x
        return (c - b*mid, v, i)
    for i, e in enumerate(VV):
        LI[e[1]][-1] = i+1
    half = N*(N-1)/4
    while right - left > EPS:
        mid = (left + right) / 2
        LI.sort(key=key)
        data = {}
        res = 0
        for b, c, v, i in LI:
            if res > half:
                break
            res += count(i)
        if res > half:
            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: Wrong Answer

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**5; right = 10**5
    def count(i):
        s = 0; j = i
        while i:
            s += data[i]
            i -= i & -i
        while j <= N:
            data[j] += 1
            j += j & -j
        return s
    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)
    def key(x):
        a,b,c,v,i=x
        return ((c - b*mid) / a, v, i)
    for i, e in enumerate(VV):
        LI[e[1]][-1] = i+1
    while right - left > EPS:
        mid = (left + right) / 2
        LI.sort(key=key)
        data = [0]*(N+1)
        res = sum(count(i) for a, b, c, v, i in LI)
        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: Wrong Answer

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**5; right = 10**5
    def count(i):
        s = 0; j = i
        while i:
            s += data[i]
            i -= i & -i
        while j <= N:
            data[j] += 1
            j += j & -j
        return s
    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()
        data = [0]*(N+1)
        res = sum(count(i) for p, v, i in ps)
        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: Wrong Answer

Solution code:
# coding: utf-8
import numpy as np
from itertools import combinations


def II(): return int(input())


def ILI(): return list(map(int, input().split()))


def read():
    N = II()
    matrix = [ILI() for __ in range(N)]
    return N, matrix


def solve(N, matrix):
    matrix.append([1, 0, 0])
    matrix.append([0, 1, 0])
    l_x = []
    l_y = []
    for row_1, row_2 in combinations(matrix, 2):
        A = np.array([row_1[:2], row_2[:2]])
        b = np.array([row_1[2], row_2[2]])
        x, y = np.linalg.solve(A, b)
        l_x.append(x)
        l_y.append(y)
    ans_x = sum(l_x) / len(l_x)
    ans_y = sum(l_y) / len(l_y)
    ans = " ".join(map(str, [ans_x, ans_y]))
    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from __future__ import division, print_function
from itertools import izip
input = raw_input
zip = izip
range = xrange

class Bit:
    # 参考1: http://hos.ac/slides/20140319_bit.pdf
    # 参考2: https://atcoder.jp/contests/arc046/submissions/6264201
    # 検証: https://atcoder.jp/contests/arc046/submissions/7435621
    # values の 0 番目は使わない
    # len(values) を 2 冪 +1 にすることで二分探索の条件を減らす
    def __init__(self, a):
        if hasattr(a, "__iter__"):
            le = len(a)
            self.n = 1 << le.bit_length()  # le を超える最小の 2 冪
            self.values = values = [0] * (self.n + 1)
            values[1:le + 1] = a[:]
            for i in range(1, self.n):
                values[i + (i & -i)] += values[i]
        elif isinstance(a, int):
            self.n = 1 << a.bit_length()
            self.values = [0] * (self.n + 1)
        else:
            raise TypeError

    def add(self, i, val):
        n, values = self.n, self.values
        while i <= n:
            values[i] += val
            i += i & -i

    def sum(self, i):  # (0, i]
        values = self.values
        res = 0
        while i > 0:
            res += values[i]
            i -= i & -i
        return res

    def bisect_left(self, v):  # self.sum(i) が v 以上になる最小の i
        n, values = self.n, self.values
        if v > values[n]:
            return None
        i, step = 0, n >> 1
        while step:
            if values[i + step] < v:
                i += step
                v -= values[i]
            step >>= 1
        return i + 1

def inversion_number(arr):
    n = len(arr)
    arr = sorted(range(n), key=lambda x: arr[x])
    bit = Bit(n)
    res = n * (n-1) // 2
    for val in arr:
        res -= bit.sum(val+1)
        bit.add(val+1, 1)
    return res

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
    ok = -1e10
    ng = 1e10
    A, B, C = zip(*sorted(zip(A, B, C), key=lambda x: -x[0]/x[1]))
    for _ in range(70):
        x = (ok+ng) * 0.5
        Y = [(-a*x+c)/b for a, b, c in zip(A, B, C)]
        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))