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

n = int(input())
s = list(map(int, input().split()))
a = [s[1]]
ans = s[2]
p = 0

for i in range(n-1):
    q = input()
    if q[0]=='1':
        c,d = map(int,q[2:].split())
        if len(a)%2==1:
            ans+=abs(a[p]-c)+d
            bisect.insort(a,c)
        else:
            p+=1
            bisect.insort(a,c)
            ans+=abs(a[p]-c)+d
    else:
        print(a[p], ans)

Fixed submission:
import heapq

n = int(input())
s = list(map(int, input().split()))

# 中央値より左・右の管理
l=[]
r=[]
heapq.heapify(l)
heapq.heapify(r)
lenl=0
lenr=0
# 中央値
x = s[1]

# b含めた答え
ans = s[2]

for i in range(n-1):
    q = list(map(int,input().split()))
    if q[0]==1:
        ans += q[2]
        if (lenl+lenr)%2==0:
            lenr+=1
            ans+=abs(x-q[1])
            if x<=q[1]:
                heapq.heappush(r,q[1])
            else:
                heapq.heappush(l,-q[1])
                heapq.heappush(r,x)
                x = -heapq.heappop(l)
        else:
            lenl+=1
            if x<q[1]:
                heapq.heappush(l,-x)
                heapq.heappush(r,q[1])
                x=heapq.heappop(r)
            else:
                heapq.heappush(l,-q[1])
            ans+=abs(x-q[1])
    if q[0]==2:
        print(x, ans)

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

n = int(input())
s = list(map(int, input().split()))
a = [s[1]]
ans = s[2]
p = 0

for i in range(n-1):
    q = list(map(int,input().split()))
    if q[0]==1:
        ans += q[2]
        b = bisect.bisect_left(a, q[1])
        if len(a)%2==1:
            ans+=abs(a[p]-q[1])
            a=a[:b]+[q[1]]+a[b:]
        else:
            p+=1
            a=a[:b]+[q[1]]+a[b:]
            ans+=abs(a[p]-q[1])
    if q[0]==2:
        print(a[p], ans)

Fixed submission:
import heapq

n = int(input())
s = list(map(int, input().split()))

# 中央値より左・右の管理
l=[]
r=[]
heapq.heapify(l)
heapq.heapify(r)
lenl=0
lenr=0
# 中央値
x = s[1]

# b含めた答え
ans = s[2]

for i in range(n-1):
    q = list(map(int,input().split()))
    if q[0]==1:
        ans += q[2]
        if (lenl+lenr)%2==0:
            lenr+=1
            ans+=abs(x-q[1])
            if x<=q[1]:
                heapq.heappush(r,q[1])
            else:
                heapq.heappush(l,-q[1])
                heapq.heappush(r,x)
                x = -heapq.heappop(l)
        else:
            lenl+=1
            if x<q[1]:
                heapq.heappush(l,-x)
                heapq.heappush(r,q[1])
                x=heapq.heappop(r)
            else:
                heapq.heappush(l,-q[1])
            ans+=abs(x-q[1])
    if q[0]==2:
        print(x, ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [list(map(int, input().split()))for i in range(n)]

l = [[s[0][1]]]

for i in range(1,n):
    if s[i][0]==1:
        l.append(l[-1]+[s[i][1]])
        l[-1].sort()
    else:
        l.append(l[-1])

ans = s[0][2]
p = 0

for i in range(1,n):
    q = s[i]
    if q[0]==1:
        ans += q[2]
        if len(l[i-1])%2==1:
            ans+=abs(l[i-1][p]-q[1])
        else:
            p+=1
            ans+=abs(l[i][p]-q[1])
    if q[0]==2:
        print(l[i][p], ans)


Fixed submission:
import heapq

n = int(input())
s = list(map(int, input().split()))

# 中央値より左・右の管理
l=[]
r=[]
heapq.heapify(l)
heapq.heapify(r)
lenl=0
lenr=0
# 中央値
x = s[1]

# b含めた答え
ans = s[2]

for i in range(n-1):
    q = list(map(int,input().split()))
    if q[0]==1:
        ans += q[2]
        if (lenl+lenr)%2==0:
            lenr+=1
            ans+=abs(x-q[1])
            if x<=q[1]:
                heapq.heappush(r,q[1])
            else:
                heapq.heappush(l,-q[1])
                heapq.heappush(r,x)
                x = -heapq.heappop(l)
        else:
            lenl+=1
            if x<q[1]:
                heapq.heappush(l,-x)
                heapq.heappush(r,q[1])
                x=heapq.heappop(r)
            else:
                heapq.heappush(l,-q[1])
            ans+=abs(x-q[1])
    if q[0]==2:
        print(x, ans)

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

n = int(input())
s = list(map(int, input().split()))
a = [s[1]]
ans = s[2]
p = 0

for i in range(n-1):
    q = list(map(int,input().split()))
    if q[0]==1:
        ans += q[2]
        if len(a)%2==1:
            ans+=abs(a[p]-q[1])
            bisect.insort(a,q[1])
        else:
            p+=1
            bisect.insort(a,q[1])
            ans+=abs(a[p]-q[1])
    if q[0]==2:
        print(a[p], ans)

Fixed submission:
import heapq

n = int(input())
s = list(map(int, input().split()))

# 中央値より左・右の管理
l=[]
r=[]
heapq.heapify(l)
heapq.heapify(r)
lenl=0
lenr=0
# 中央値
x = s[1]

# b含めた答え
ans = s[2]

for i in range(n-1):
    q = list(map(int,input().split()))
    if q[0]==1:
        ans += q[2]
        if (lenl+lenr)%2==0:
            lenr+=1
            ans+=abs(x-q[1])
            if x<=q[1]:
                heapq.heappush(r,q[1])
            else:
                heapq.heappush(l,-q[1])
                heapq.heappush(r,x)
                x = -heapq.heappop(l)
        else:
            lenl+=1
            if x<q[1]:
                heapq.heappush(l,-x)
                heapq.heappush(r,q[1])
                x=heapq.heappop(r)
            else:
                heapq.heappush(l,-q[1])
            ans+=abs(x-q[1])
    if q[0]==2:
        print(x, ans)