Buggy python submission (verdict: Time Limit Exceeded):
from bisect import insort_left

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

ans = 0
x = []
c = 0
n = 0

l, r = -float('inf'), float('inf')

for q in Query :
    if q[0] == '1' :
        a, b = map(int, q[2:].split())
        
        insort_left(x, a)
        c += b
        n += 1

        if a < l :
            ans += l - a
        elif r < a :
            ans += a - r
            
        l, r = x[(n - 1) // 2], x[n // 2]

    else :
        print(l, ans + c)


Fixed submission:
import heapq

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

ans = 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)

        ans += b

    else :
        print(-lq[0], ans)

Buggy python submission (verdict: Time Limit Exceeded):
Q = int(input())
Query = [input() for _ in range(Q)]

x = []
c = 0

for q in Query :
    if q[0] == '1' :
        a, b = map(int, q[2:].split())
        x.append(a)
        c += b

    else :
        x.sort()

        min_v = float('inf')

        mid_l, mid_r = (len(x) - 1) // 2, len(x) // 2

        for mid in range(mid_l, mid_r + 1) :
            tmp = 0
            xmid = x[mid]

            for xi in x :
                tmp += abs(xi - xmid)
            
            if tmp < min_v :
                min_v = tmp
                min_k = x[mid]
        
        print(min_k, min_v + c)


Fixed submission:
import heapq

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

ans = 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)

        ans += b

    else :
        print(-lq[0], ans)

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import insort_left

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

x = []
c = 0
i = 0

for q in Query :

    if q[0] == '1' :
        a, b = map(int, q[2:].split())
        
        insort_left(x, a)
        c += b
        i += 1

    else :
        min_v = float('inf')

        mid_l, mid_r = (i - 1) // 2, i // 2
        for mid in range(mid_l, mid_r + 1) :
            tmp = 0
            xmid = x[mid]

            for xi in x :
                tmp += abs(xi - xmid)
            
            if tmp < min_v :
                min_v = tmp
                min_k = x[mid]
        
        print(min_k, min_v + c)


Fixed submission:
import heapq

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

ans = 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)

        ans += b

    else :
        print(-lq[0], ans)

Buggy python submission (verdict: Time Limit Exceeded):
Q = int(input())
Query = [input() for _ in range(Q)]

x = []
c = 0

for q in Query :
    if q[0] == '1' :
        a, b = map(int, q[2:].split())
        x.append(a)
        c += b

    else :
        x.sort()

        min_v = float('inf')

        mid_l, mid_r = (len(x) - 1) // 2, len(x) // 2

        for mid in range(mid_l, mid_r + 1) :
            tmp = 0
            xmid = x[mid]

            for xi in x :
                tmp += abs(xi - xmid)
            
            if tmp < min_v :
                min_v = tmp
                min_k = x[mid]
        
        print(min_k, min_v + c)


Fixed submission:
import heapq

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

ans = 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)

        ans += b

    else :
        print(-lq[0], ans)