Buggy python submission (verdict: Time Limit Exceeded):
import heapq
Q = int(input())
Query = [[int(_) for _ in input().split()] for _ in range(Q)]
H1 = []
H2 = []
a = b = 0
for query in Query:
    if query[0] == 1:
        m0 = query[1]
        if len(H1) == len(H2):
            if len(H2):
                m1 = heapq.heappop(H2)
                m0, m1 = sorted([m0, m1])
                heapq.heappush(H1, -m0)
                heapq.heappush(H2, m1)
            else:
                heapq.heappush(H1, -m0)
        else:
            m1 = -heapq.heappop(H1)
            m0, m1 = sorted([m0, m1])
            heapq.heappush(H1, -m0)
            heapq.heappush(H2, m1)
        b += query[2]
    else:
        x = -H1[0]
        print(x, x * len(H1) + sum(H1) + sum(H2) - x * len(H2) + b)


Fixed submission:
import heapq
import sys
input = sys.stdin.readline
Q = int(input())
Query = [[int(_) for _ in input().split()] for _ in range(Q)]
H1 = []
H2 = []
a = b = sum1 = sum2 = 0
for query in Query:
    if query[0] == 1:
        m0 = query[1]
        if len(H1) == len(H2):
            if len(H2):
                m1 = heapq.heappop(H2)
                sum2 -= m1
                m0, m1 = sorted([m0, m1])
                heapq.heappush(H1, -m0)
                heapq.heappush(H2, m1)
                sum1 -= m0
                sum2 += m1
            else:
                heapq.heappush(H1, -m0)
                sum1 -= m0
        else:
            m1 = -heapq.heappop(H1)
            sum1 += m1
            m0, m1 = sorted([m0, m1])
            heapq.heappush(H1, -m0)
            heapq.heappush(H2, m1)
            sum1 -= m0
            sum2 += m1
        b += query[2]
    else:
        x = -H1[0]
        print(x, x * len(H1) + sum1 + sum2 - x * len(H2) + b)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
Q = int(input())
Query = [[int(_) for _ in input().split()] for _ in range(Q)]
H1 = []
H2 = []
a = b = 0
for query in Query:
    if query[0] == 1:
        m0 = query[1]
        if len(H1) == len(H2):
            if len(H2):
                m1 = heapq.heappop(H2)
                m0, m1 = sorted([m0, m1])
                heapq.heappush(H1, -m0)
                heapq.heappush(H2, m1)
            else:
                heapq.heappush(H1, -m0)
        else:
            m1 = -heapq.heappop(H1)
            m0, m1 = sorted([m0, m1])
            heapq.heappush(H1, -m0)
            heapq.heappush(H2, m1)
        b += query[2]
    else:
        x = -H1[0]
        print(x, x * len(H1) + sum(H1) + sum(H2) - x * len(H2) + b)


Fixed submission:
import heapq
import sys
input = sys.stdin.readline
Q = int(input())
Query = [[int(_) for _ in input().split()] for _ in range(Q)]
H1 = []
H2 = []
a = b = sum1 = sum2 = 0
for query in Query:
    if query[0] == 1:
        m0 = query[1]
        if len(H1) == len(H2):
            if len(H2):
                m1 = heapq.heappop(H2)
                sum2 -= m1
                m0, m1 = sorted([m0, m1])
                heapq.heappush(H1, -m0)
                heapq.heappush(H2, m1)
                sum1 -= m0
                sum2 += m1
            else:
                heapq.heappush(H1, -m0)
                sum1 -= m0
        else:
            m1 = -heapq.heappop(H1)
            sum1 += m1
            m0, m1 = sorted([m0, m1])
            heapq.heappush(H1, -m0)
            heapq.heappush(H2, m1)
            sum1 -= m0
            sum2 += m1
        b += query[2]
    else:
        x = -H1[0]
        print(x, x * len(H1) + sum1 + sum2 - x * len(H2) + b)