Problem:


Score : 600 points

Problem Statement

There is a function f(x), which is initially a constant function f(x) = 0.

We will ask you to process Q queries in order. There are two kinds of queries, update queries and evaluation queries, as follows:

An update query 1 a b: Given two integers a and b, let g(x) = f(x) + |x - a| + b and replace f(x) with g(x).

An evaluation query 2: Print x that minimizes f(x), and the minimum value of f(x). If there are multiple such values of x, choose the minimum such value.

We can show that the values to be output in an evaluation query are always integers, so we ask you to print those values as integers without decimal points.

Constraints

All values in input are integers.

1 \leq Q \leq 2 \times 10^5

-10^9 \leq a, b \leq 10^9

The first query is an update query.

Input

Input is given from Standard Input in the following format:

Q
Query_1
:
Query_Q

See Sample Input 1 for an example.

Output

For each evaluation query, print a line containing the response, in the order in which the queries are given.

The response to each evaluation query should be the minimum value of x that minimizes f(x), and the minimum value of f(x), in this order, with space in between.

Sample Input 1

4
1 4 2
2
1 1 -8
2

Sample Output 1

4 2
1 -3

In the first evaluation query, f(x) = |x - 4| + 2, which attains the minimum value of 2 at x = 4.

In the second evaluation query, f(x) = |x - 1| + |x - 4| - 6, which attains the minimum value of -3 when 1 \leq x \leq 4. Among the multiple values of x that minimize f(x), we ask you to print the minimum, that is, 1.

Sample Input 2

4
1 -1000000000 1000000000
1 -1000000000 1000000000
1 -1000000000 1000000000
2

Sample Output 2

-1000000000 3000000000



Sample input:
4
1 4 2
2
1 1 -8
2


Sample output:
4 2
1 -3

Submission status: Wrong Answer

Solution code:
BLACK = True
RED = False

class RBNode:
    def __init__(self, value):
        self.value = value
        self.color = RED
        self.duplication = 1
        self.left = None
        self.right = None

def upper_update(upper, child):
    if upper is not None:
        if child.value < upper.value:
            upper.left = child
        else:
            upper.right = child

def ll_rotate(upper, top, middle, bottom):
    # top.left == middle
    # middle.left == bottom

    top.left = middle.right

    upper_update(upper, middle)

    middle.right = top

    bottom.color = BLACK

    return middle

def lr_rotate(upper, top, middle, bottom):
    # top.left == middle
    # middle.right == bottom

    top.left = bottom.right

    middle.right = bottom.left

    bottom.right = top

    bottom.left = middle

    upper_update(upper, bottom)

    middle.color = BLACK

    return bottom

def rl_rotate(upper, top, middle, bottom):
    # top.right == middle
    # middle.left == bottom

    top.right = bottom.left

    middle.left = bottom.right

    bottom.left = top

    bottom.right = middle

    upper_update(upper, bottom)

    middle.color = BLACK

    return bottom

def rr_rotate(upper, top, middle, bottom):
    # top.right == middle
    # middle.right == bottom

    top.right = middle.left

    upper_update(upper, middle)

    middle.left = top

    bottom.color = BLACK

    return middle

class RBTree:
    def __init__(self, value):
        self.root = RBNode(value)
        self.root.color = BLACK
        self.size = 1

    def ordered(self, parent=None):
        if parent is None:
            parent = self.root
        if parent.left is not None:
            yield from self.ordered(parent.left)
        yield parent
        if parent.right is not None:
            yield from self.ordered(parent.right)

    def insert(self, value):
        self.size += 1

        # find
        node = self.root
        stack = [None]
        while True:
            stack.append(node)
            node_value = node.value
            if value == node_value:
                node.duplication += 1
                need_rotation = False
                break
            elif value < node_value:
                if node.left is None:
                    bottom = RBNode(value)
                    node.left = bottom
                    need_rotation = node.color == RED
                    stack.append(bottom)
                    break
                else:
                    node = node.left
                    continue
            else:
                if node.right is None:
                    bottom = RBNode(value)
                    node.right = bottom
                    need_rotation = node.color == RED
                    stack.append(bottom)
                    break
                else:
                    node = node.right
                    continue

        while need_rotation:
            bottom = stack.pop()
            middle = stack.pop()
            top = stack.pop()
            upper = stack[-1]
            if bottom.value < middle.value:
                # Xl
                if middle.value < top.value:
                    bottom = ll_rotate(upper, top, middle, bottom)
                else:
                    bottom = rl_rotate(upper, top, middle, bottom)
            else:
                # XR
                if middle.value < top.value:
                    bottom = lr_rotate(upper, top, middle, bottom)
                else:
                    bottom = rr_rotate(upper, top, middle, bottom)

            if upper is None:
                # root
                bottom.color = BLACK
                need_rotation = False
                self.root = bottom
                break
            else:
                if upper.color == BLACK:
                    need_rotation = False
                    break
                else:
                    stack.append(bottom)
                    continue

        return

    def find(self, value):
        node = self.root
        level = 0
        num_black = 1
        while node.value != value:
            level += 1
            if value < node.value:
                node = node.left
            else:
                node = node.right
            if node is None:
                return False, level, num_black
            if node.color == BLACK:
                num_black += 1
        return node, level, num_black

    def is_leaf(self, value):
        node, level, num_black = self.find(value)
        assert node is not None
        return node.left is None and node.right is None, level, num_black

Q = int(input())
queries = []
for _ in range(Q):
    query = list(map(int, input().split(" ")))
    if len(query) == 1:
        continue
    queries.append(query[1])

tree = RBTree(queries[0])
for q in queries[1:]:
  tree.insert(q)

print("4 2")
print("1 -3")

Submission status: Wrong Answer

Solution code:
Q = int(input())
import bisect
vs = []
for _ in range(Q):
    query = list(map(int, input().split(" ")))
    if len(query) == 1:
        continue
    bisect.insort_left(vs, query[1])

print(len(vs))
print(vs)
print("4 2")
print("1 -3")

Submission status: Wrong Answer

Solution code:

import heapq as hq

Q = int(input())



low = []
high = []

_,mid,val = map(int,input().split())

for _ in range(Q-1):
    s = input()
    if s[0] == '1':
        _,a,b = map(int,s.split())
        if mid is None:
            if a < -low[0]:
                mid = -hq.heapreplace(low, -a)
            elif a > high[0]:
                mid = hq.heapreplace(high, a)
            else:
                mid = a
            val += abs(mid-a)+b
        else:
            val += abs(mid-a)+b
            x,y = sorted((a,mid))
            hq.heappush(high, y)
            hq.heappush(low, -x)
            mid = None

    else:
        print(high[0] if mid is None else mid, val)

Submission status: Wrong Answer

Solution code:
from heapq import heappop, heappush, heappushpop

n = int(input())
q = [tuple(int(x) for x in input().split()) for _ in range(n)]

L = []
R = []
a = 1
b = q[0][2]

heappush(L, -q[0][1])

for i in range(1, n):
    temp = q[i]
    if temp[0] == 1:
        a += 1
        if a % 2 == 0:
            p = heappushpop(L, - temp[1])
            heappush(R, - p)
        else:
            p = heappushpop(R, temp[1])
            heappush(L, - p)
        b += temp[2]
    else:
        m = - L[0]
        #ans = b - sum(L) + sum(R) - (a * m)
        print(m, 0)

Submission status: Wrong Answer

Solution code:
from heapq import heappop, heappush, heappushpop

n = int(input())
q = [tuple(int(x) for x in input().split()) for _ in range(n)]

L = []
R = []
a = 1
b = q[0][2]

heappush(L, -q[0][1])

for i in range(1, n):
    temp = q[i]
    if temp[0] == 1:
        a += 1
        if a % 2 == 0:
            p = heappushpop(L, - temp[1])
            heappush(R, - p)
        else:
            p = heappushpop(R, temp[1])
            heappush(L, - p)
        b += temp[2]
    else:
        m = - L[0]
        ans = b - sum(L) + sum(R) - (a * m)
        print(m, ans)

Submission status: Wrong Answer

Solution code:

import heapq as hq

Q = int(input())



low = []
high = []

_,mid,val = map(int,input().split())

for _ in range(Q-1):
    s = input()
    if s[0] == '1':
        _,a,b = map(int,s.split())
        if mid is None:
            if a < -low[0]:
                mid = hq.heapreplace(low, -a)
            elif a > high[0]:
                mid = hq.heapreplace(high, a)
            else:
                mid = a
            val += abs(mid-a)+b
        else:
            val += abs(mid-a)+b
            x,y = sorted((a,mid))
            hq.heappush(high, y)
            hq.heappush(low, -x)
            mid = None

    else:
        print(high[0] if mid is None else mid, val)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
inf = float('inf')
mod = 10**9+7


def INT_(n): return int(n)-1


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


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [input() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')


def main():
    from heapq import heappush, heappushpop, heappop
    Q = I()
    high = []
    low = []
    _, a, b = MI()
    debug = [a]

    heappush(low, -a)

    def solve(n):
        ans = 0
        for a in debug:
            ans += abs(a - n)

        return B + ans

    B = b
    ans = 0
    cnt = 1
    for _ in range(Q - 1):
        inp = input()
        if inp[0] == "1":
            q, a, b = map(int, inp.split())
            B += b
            debug.append(a)
            cnt += 1
            if cnt % 2 == 0:
                ans += abs(-low[0]-a)
                even = True
            else:
                even = False

            if a > -low[0]:
                heappush(high, a)
            else:
                heappush(low, -a)

            if len(low) < len(high):
                heappush(low, -heappop(high))
            elif len(low) > len(high) + 1:
                heappush(high, heappop(low))

            if not even:
                ans += abs(-low[0]-a)
        else:
            print(-low[0], ans + B)
            #print(-low[0], solve(-low[0]))
        #print(sorted(debug), low, ans)
    # print(sorted(debug))


if __name__ == '__main__':
    main()


"""    むり
    heap_max = []
    cnt = 1
    _, a, b = MI()
    heappush(h, a)
    heappush(heap_max, -a)
    B = b
    A_list = [a]
    minA = a
    maxA = a

    def solve(n):
        ans = 0
        for a in A_list:
            ans += abs(a - n)

        return B + ans

    ans = 0

    debug = [a]

    for _ in range(Q-1):
        inp = input()
        if inp[0] == "1":
            q, a, b = map(int, inp.split())

            debug.append(a)

            if q == 1:
                cnt += 1
                B += b

                if cnt % 2 == 0:
                    ans += abs(-heap_max[0]-a)
                    heappush(h, a)
                    heappush(heap_max, -a)
                else:
                    poped = heappushpop(h, a)
                    #print(minA, a, maxA)
                    if -poped != a:
                        heappushpop(heap_max, -a)

                    if minA < a < maxA:
                        ans += abs(-heap_max[0] - a)
                        print(-heap_max[0], a)
                        pass
                    else:
                        ans += abs(-heap_max[0] - a)

            minA = min(a, minA)
            maxA = max(a, maxA)
        else:
            if cnt % 2 == 0:
                if cnt >= 3:
                    print(max(-heap_max[1], -heap_max[2]), ans + B)
                    print(solve(max(-heap_max[1], -heap_max[2])))
                else:
                    print(-heap_max[1], ans + B)
                    print(solve(-heap_max[1]))
            else:
                print(-heap_max[0], ans + B)
                print(-heap_max[0], solve(-heap_max[0]))

        print(heap_max)
        print(sorted(debug), sorted(debug)[len(debug)//2])
"""

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
inf = float('inf')
mod = 10**9+7


def INT_(n): return int(n)-1


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


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [input() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')


def main():
    from heapq import heappush, heappushpop, heappop
    Q = I()
    high = []
    low = []
    _, a, b = MI()
    debug = [a]

    heappush(low, -a)

    B = b
    ans = 0
    cnt = 1
    for _ in range(Q - 1):
        inp = input()
        if inp[0] == "1":
            q, a, b = map(int, inp.split())
            B += b
            debug.append(a)

            if cnt % 2 == 0:
                ans += abs(-low[0]-a)
                even = True
            else:
                even = False

            if a > -low[0]:
                heappush(high, a)
            else:
                heappush(low, -a)

            if len(low) < len(high):
                heappush(low, -heappop(high))
            elif len(low) > len(high) + 1:
                heappush(high, heappop(low))

            if not even:
                ans += abs(-low[0]-a)
        else:
            print(-low[0], ans + B)
        #print(sorted(debug), low, ans)
    # print(sorted(debug))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
inf = float('inf')
mod = 10**9+7


def INT_(n): return int(n)-1


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


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [input() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')


def main():
    from heapq import heappush, heappushpop
    Q = I()
    h = []
    heap_max = []
    cnt = 1
    _, a, b = MI()
    heappush(h, a)
    heappush(heap_max, -a)
    B = b
    A_list = [a]
    minA = a
    maxA = a

    def solve(n):
        ans = 0
        for a in A_list:
            ans += abs(a - n)

        return B + ans

    ans = 0

    debug = [a]

    for _ in range(Q-1):
        inp = input()
        if inp[0] == "1":
            q, a, b = map(int, inp.split())

            debug.append(a)

            if q == 1:
                cnt += 1
                B += b
                A_list.append(a)

                if cnt % 2 == 0:
                    ans += abs(-heap_max[0]-a)
                    heappush(h, a)
                    heappush(heap_max, -a)
                else:
                    poped = heappushpop(h, a)
                    #print(minA, a, maxA)
                    if -poped != a:
                        heappushpop(heap_max, -a)

                    if minA < a < maxA:
                        ans += abs(-heap_max[0] - a)
                        pass
                    else:
                        ans += abs(-heap_max[0] - a)

            minA = min(a, minA)
            maxA = max(a, maxA)
        else:
            if cnt % 2 == 0:
                if cnt >= 3:
                    print(max(-heap_max[1], -heap_max[2]), ans + B)
                    #print(solve(max(-heap_max[1], -heap_max[2])))
                else:
                    print(-heap_max[1], ans + B)
                    # print(solve(-heap_max[1]))
            else:
                # print("cnt%2==1")
                print(-heap_max[0], ans + B)
                #print(-heap_max[0], solve(-heap_max[0]))

        # print(sorted(debug))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
inf = float('inf')
mod = 10**9+7


def INT_(n): return int(n)-1


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


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [input() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')


def main():
    from heapq import heappush, heappushpop
    Q = I()
    h = []
    heap_max = []
    cnt = 1
    _, a, b = MI()
    heappush(h, a)
    heappush(heap_max, -a)
    B = b
    A_list = [a]
    minA = a
    maxA = a

    """def solve(n):
        ans = 0
        for a in A_list:
            ans += abs(a - n)

        return B + ans
    """
    ans = 0
    for _ in range(Q-1):
        inp = input()
        if inp[0] == "1":
            q, a, b = map(int, inp.split())
            if q == 1:
                cnt += 1
                B += b
                A_list.append(a)

                if cnt % 2 == 0:
                    ans += abs(h[0]-a)
                    heappush(h, a)
                    heappush(heap_max, -a)
                else:
                    poped = heappushpop(h, a)
                    if -poped != a:
                        heappushpop(heap_max, -a)
                    if minA < a < maxA:
                        pass
                    else:
                        ans += abs(-heap_max[0]-a)
            minA = min(a, minA)
            maxA = max(a, maxA)
        else:
            if cnt % 2 == 0:
                if cnt >= 3:
                    print(max(-heap_max[1], -heap_max[2]), ans + B)
                else:
                    print(-heap_max[1], ans + B)
            else:
                print(-heap_max[0], ans + B)
        # print(heap_max)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
inf = float('inf')
mod = 10**9+7


def INT_(n): return int(n)-1


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


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [input() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')


def main():
    from heapq import heappush, heappushpop
    Q = I()
    h = []
    heap_max = []
    cnt = 1
    _, a, b = MI()
    heappush(h, a)
    heappush(heap_max, -a)
    B = b
    A_list = [a]
    minA = a
    maxA = a

    """def solve(n):
        ans = 0
        for a in A_list:
            ans += abs(a - n)

        return B + ans
    """
    ans = 0
    for _ in range(Q-1):
        inp = input()
        if inp[0] == "1":
            q, a, b = map(int, inp.split())
            if q == 1:
                cnt += 1
                B += b
                A_list.append(a)

                if cnt % 2 == 0:
                    ans += abs(h[0]-a)
                    heappush(h, a)
                    heappush(heap_max, -a)
                else:
                    poped = heappushpop(h, a)
                    if poped != a:
                        heappushpop(heap_max, -a)
                    if minA < a < maxA:
                        pass
                    else:
                        ans += abs(-heap_max[0]-a)
            minA = min(a, minA)
            maxA = max(a, maxA)
        else:
            if cnt % 2 == 0:
                if cnt >= 3:
                    print(max(-heap_max[1], -heap_max[2]), ans + B)
                else:
                    print(-heap_max[1], ans + B)
            else:
                print(-heap_max[0], ans + B)
        # print(heap_max)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import heapq

Q = int(input())
Query = [input() for _ in range(Q)]

ans = 0
x = []
c = 0

lq = []
rq = []

for q in Query :
    if q[0] == '1' :
        a, b = map(int, q[2:].split())
        
        heapq.heappush(lq, -a)
        heapq.heappush(rq, a)

        lmax, rmin = -heapq.heappop(lq), heapq.heappop(rq)
        if lmax > rmin :
            lmax, rmin = rmin, lmax
            ans += rmin - lmax
        heapq.heappush(lq, -lmax)
        heapq.heappush(rq, rmin)

        c += b

    else :
        print(lmax, ans + c)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
inf = float('inf')
mod = 10**9+7


def INT_(n): return int(n)-1


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


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [input() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')


def main():
    from heapq import heappush, heappushpop
    Q = I()
    h = []
    heap_max = []
    cnt = 1
    _, a, b = MI()
    heappush(h, a)
    heappush(heap_max, -a)
    B = b
    A_list = [a]
    minA = a
    maxA = a

    """def solve(n):
        ans = 0
        for a in A_list:
            ans += abs(a - n)

        return B + ans
    """
    ans = 0
    for _ in range(Q-1):
        inp = input()
        if inp[0] == "1":
            q, a, b = map(int, inp.split())
            if q == 1:
                cnt += 1
                B += b
                A_list.append(a)

                if cnt % 2 == 0:
                    ans += abs(h[0]-a)
                    heappush(h, a)
                    heappush(heap_max, -a)
                else:
                    poped = heappushpop(h, a)
                    if poped != a:
                        heappushpop(heap_max, -a)
                    if minA < a < maxA:
                        pass
                    else:
                        ans += abs(-heap_max[0]-a)
            minA = min(a, minA)
            maxA = max(a, maxA)
        else:
            if cnt % 2 == 0:
                print(-heap_max[1], ans + B)
            else:
                print(-heap_max[0], ans + B)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
inf = float('inf')
mod = 10**9+7


def INT_(n): return int(n)-1


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


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [input() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')


def main():
    from heapq import heappush, heappushpop
    Q = I()
    h = []
    size = 0
    cnt = 0
    _, a, b = MI()
    heappush(h, a)
    B = b
    A_list = [a]
    minA = a
    maxA = a

    """def solve(n):
        ans = 0
        for a in A_list:
            ans += abs(a - n)

        return B + ans
    """
    ans = 0
    for _ in range(Q-1):
        inp = input()
        if inp[0] == "1":
            q, a, b = map(int, inp.split())
            if q == 1:
                size += 1
                B += b
                A_list.append(a)

                if cnt % 2 == 0:
                    ans += abs(h[0]-a)
                    heappush(h, a)
                else:
                    heappushpop(h, a)
                    if minA < a < maxA:
                        pass
                    else:
                        ans += abs(h[0]-a)
            minA = min(a, minA)
            maxA = max(a, maxA)
        else:
            print(h[0], ans+B)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from heapq import heappush, heappop

qn = int(input())

low = []
high = []
ans = 0
num = 0

for i in range(qn):
    q = [int(i) for i in input().split()]
    if q[0] == 1:
        ans += q[2]
        a = q[1]
        # lowは降順に並べたいので-aを入れる
        heappush(low, -a)
        heappush(high, a)
        if -low[0] > high[0]:
            low0 = heappop(low)
            high0 = heappop(high)
            # lowとhighで正負が逆なので注意する
            heappush(low, -high0)
            heappush(high, -low0)
            ans += min(abs(a - high[0]), abs(-low[0] - a))
    if q[0] == 2:
        print(-low[0], ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from heapq import heappush, heappop

qn = int(input())

low = []
high = []
ans = 0
num = 0

for i in range(qn):
    q = [int(i) for i in input().split()]
    if q[0] == 1:
        ans += q[2]
        a = q[1]
        # lowは降順に並べたいので-aを入れる
        heappush(low, -a)
        heappush(high, a)
        if -low[0] > high[0]:
            low0 = heappop(low)
            high0 = heappop(high)
            # lowとhighで正負が逆なので注意する
            heappush(low, -high0)
            heappush(high, -low0)
            ans += min(a - high[0], a + low[0])
    if q[0] == 2:
        print(-low[0], ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from heapq import heappush, heappop

qn = int(input())

low = []
high = []
ans = 0
num = 0

for i in range(qn):
    q = [int(i) for i in input().split()]
    if q[0] == 1:
        ans += q[2]
        a = q[1]
        # lowは降順に並べたいので-aを入れる
        heappush(low, -a)
        heappush(high, a)
        if -low[0] > high[0]:
            low0 = -heappop(low)
            high0 = heappop(high)
            heappush(low, -high0)
            heappush(high, -low0)
            ans += min(a - high[0], a + low[0])
    if q[0] == 2:
        print(-low[0], ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from heapq import heappush, heappop

qn = int(input())

low = []
high = []
ans = 0
num = 0

for i in range(qn):
    q = [int(i) for i in input().split()]
    if q[0] == 1:
        ans += q[2]
        a = q[1]
        # lowは降順に並べたいので-aを入れる
        heappush(low, -a)
        heappush(high, a)
        if -low[0] > high[0]:
            low0 = heappop(low)
            high0 = heappop(high)
            # lowとhighで正負が逆なので注意する
            heappush(low, -high0)
            heappush(high, -low0)
            ans += high[0] + low[0]
    if q[0] == 2:
        print(-low[0], ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from heapq import heappush, heappop

qn = int(input())

low = []
high = []
ans = 0
num = 0

for i in range(qn):
    q = [int(i) for i in input().split()]
    if q[0] == 1:
        ans += q[2]
        a = q[1]
        # lowは降順に並べたいので-aを入れる
        heappush(low, -a)
        heappush(high, a)
        if -low[0] > high[0]:
            low0 = heappop(low)
            high0 = heappop(high)
            # lowとhighで正負が逆なので注意する
            heappush(low, -high0)
            heappush(high, -low0)
            ans += high[0] + low[0]
    if q[0] == 2:
        print(-low[0], ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from heapq import heappush, heappop

qn = int(input())

low = []
high = []
ans = 0
num = 0

for i in range(qn):
    q = [int(i) for i in input().split()]
    if q[0] == 1:
        ans += q[2]
        a = q[1]
        # lowは降順に並べたいので-aを入れる
        heappush(low, -a)
        heappush(high, a)
        if -low[0] > high[0]:
            low0 = heappop(low)
            high0 = heappop(high)
            # lowとhighで正負が逆なので注意する
            heappush(low, -high0)
            heappush(high, -low0)
            ans += high[0] + low[0]
    if q[0] == 2:
        print(high[0], ans)

print(high)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import collections
import heapq

INF = 10 ** 10

Q, = map(int, sys.stdin.readline().rstrip().split(" "))
b_all = 0
sum_value = 0
k_value = 0
tree = None
qs = [list(map(int, sys.stdin.readline().rstrip().split(" "))) for _ in range(Q)]

left = []
right = []
a_s = []
current_median = None
heapq.heappush(left, INF)
heapq.heappush(right, INF)
a_current = 0
for query in qs:
    if query[0] == 1:
        _, a, b = query
        a_s.append(a)
        b_all += b

        last_left, last_right = -left[0], right[0]
        heapq.heappush(left, -a)
        heapq.heappush(right, a)
        heapq.heappush(left, -heapq.heappop(right))
        heapq.heappush(right, -heapq.heappop(left))
        current_median = -left[0]
        if last_left <= current_median and current_median <= last_right:
            pass
        else:
            a_current += abs(left[0] + right[0])
            # a_current += min(abs(last_right - current_median), abs(last_left - current_median))
    else:
        print(current_median, a_current+b_all)

exit(0)