Buggy python submission (verdict: Time Limit Exceeded):
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):
    #print([L, R])
    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
        for x in L:
            ans += abs(m + x)
        for x in R:
            ans += abs(m - x)
        print(m, ans)

Fixed submission:
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]

ans = 0

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

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

Buggy python submission (verdict: Time Limit Exceeded):
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):
    #print([L, R])
    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 = heappop(L)
        heappush(L, m)
        m *= -1
        ans = b
        for x in L:
            ans += abs(m + x)
        for x in R:
            ans += abs(m - x)
        print(m, ans)

Fixed submission:
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]

ans = 0

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

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

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappop, heappush

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:
            tl = - heappop(L)
            if temp[1] >= tl:
                heappush(R, temp[1])
                heappush(L, - tl)
            else:
                heappush(L, - temp[1])
                heappush(R, tl)
        else:
            tr = heappop(R)
            if temp[1] <= tr:
                heappush(L, - temp[1])
                heappush(R, tr)
            else:
                heappush(L, - tr)
                heappush(R, temp[1])
        b += temp[2]
    else:
        m = heappop(L)
        heappush(L, m)
        m *= -1
        ans = b
        for x in L:
            ans += abs(m + x)
        for x in R:
            ans += abs(m - x)
        print(m, ans)

Fixed submission:
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]

ans = 0

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

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

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

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

a = []
b = 0

for temp in q:
    if temp[0] == 1:
        a.insert(bisect_left(a, temp[1]), temp[1])
        b += temp[2]
    else:
        #print(a)
        m = a[len(a) // 2 + len(a) % 2 - 1]
        ans = b
        for x in a:
            ans += abs(m - x)
        print(m, ans)


Fixed submission:
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]

ans = 0

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

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

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

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

a = []
b = 0

for temp in q:
    if temp[0] == 1:
        a.insert(bisect_left(a, temp[1]), temp[1])
        b += temp[2]
    else:
        #print(a)
        m = a[len(a) // 2 + len(a) % 2 - 1]
        ans = b
        for x in a:
            ans += abs(m - x)
        print(m, ans)


Fixed submission:
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]

ans = 0

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

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