Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect,insort
import itertools
q=int(input())
query=[list(map(int,input().split())) for i in range(q)]
inf=float("inf")
a_sum=0
b_sum=0
A=[]
count=0
for u in query:
    if u[0]==2:
        if count%2==1:
            print(A[num],a_sum+b_sum-A[num])
        else:
            print(A[num-1],a_sum+b_sum)
    else:
        count+=1
        a,b=u[1],u[2]
        b_sum+=b
        c=bisect(A,a)
        num=count//2
        if c>=num:
            if count%2==0:
                a_sum+=-2*A[num-1]+a
            else:
                a_sum+=a
            A=list(itertools.chain(A[:c],[a],A[c:]))
        else:
            if count%2==0:
                a_sum+=-a
            else:
                a_sum+=-a+2*A[num-1]
            A=list(itertools.chain(A[:c],[a],A[c:]))



Fixed submission:
from heapq import heappop,heappush
q=int(input())
query=[list(map(int,input().split())) for _ in range(q)]
inf=10**12
left=[inf]
left_sum=0
right=[inf]
right_sum=0

cnt=0
b=0
for i in range(q):
    if query[i][0]==1:
        a=query[i][1]
        b+=query[i][2]
        if cnt==0:
            d=right[0]
            if a>d:
                heappush(left,-heappop(right))
                heappush(right,a)
                right_sum+=a-d
                left_sum-=d
            else:
                heappush(left,-a)
                left_sum-=a
            cnt=1
        else:
            c=-left[0]
            if a<c:
                heappush(right,-heappop(left))
                heappush(left,-a)
                right_sum+=c
                left_sum+=c-a
            else:
                heappush(right,a)
                right_sum+=a
            cnt=0
    else:
        x=-left[0]
        if cnt==0:
            print(x,b+right_sum+left_sum)
        else:
            print(x,b+x+right_sum+left_sum)

Buggy python submission (verdict: Runtime Error):
from bisect import bisect,insort
import itertools
q=int(input())
query=[list(map(int,input().split())) for i in range(q)]
inf=float("inf")
a_sum=0
b_sum=0
A=[]
count=0
for u in query:
    if u[0]==2:
        if count%2==1:
            print(A[num],a_sum+b_sum-A[num])
        else:
            print(A[num-1],a_sum+b_sum)
    else:
        count+=1
        a,b=u[1],u[2]
        b_sum+=b
        c=bisect(A,a)
        num=count//2
        if c>=num:
            if count%2==0:
                a_sum+=-2*A[num-1]+a
            else:
                a_sum+=a
            itertools.chain(A[:c],[a],A[c:])
        else:
            if count%2==0:
                a_sum+=-a
            else:
                a_sum+=-a+2*A[num-1]
            itertools.chain(A[:c],[a],A[c:])

Fixed submission:
from heapq import heappop,heappush
q=int(input())
query=[list(map(int,input().split())) for _ in range(q)]
inf=10**12
left=[inf]
left_sum=0
right=[inf]
right_sum=0

cnt=0
b=0
for i in range(q):
    if query[i][0]==1:
        a=query[i][1]
        b+=query[i][2]
        if cnt==0:
            d=right[0]
            if a>d:
                heappush(left,-heappop(right))
                heappush(right,a)
                right_sum+=a-d
                left_sum-=d
            else:
                heappush(left,-a)
                left_sum-=a
            cnt=1
        else:
            c=-left[0]
            if a<c:
                heappush(right,-heappop(left))
                heappush(left,-a)
                right_sum+=c
                left_sum+=c-a
            else:
                heappush(right,a)
                right_sum+=a
            cnt=0
    else:
        x=-left[0]
        if cnt==0:
            print(x,b+right_sum+left_sum)
        else:
            print(x,b+x+right_sum+left_sum)

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect,insort
import itertools
q=int(input())
query=[list(map(int,input().split())) for i in range(q)]
inf=float("inf")
a_sum=0
b_sum=0
A=[]
count=0
for u in query:
    if u[0]==2:
        if count%2==1:
            print(A[num],a_sum+b_sum-A[num])
        else:
            print(A[num-1],a_sum+b_sum)
    else:
        count+=1
        a,b=u[1],u[2]
        b_sum+=b
        c=bisect(A,a)
        num=count//2
        if c>=num:
            if count%2==0:
                a_sum+=-2*A[num-1]+a
            else:
                a_sum+=a
            insort(A,a)
        else:
            if count%2==0:
                a_sum+=-a
            else:
                a_sum+=-a+2*A[num-1]
            insort(A,a)

Fixed submission:
from heapq import heappop,heappush
q=int(input())
query=[list(map(int,input().split())) for _ in range(q)]
inf=10**12
left=[inf]
left_sum=0
right=[inf]
right_sum=0

cnt=0
b=0
for i in range(q):
    if query[i][0]==1:
        a=query[i][1]
        b+=query[i][2]
        if cnt==0:
            d=right[0]
            if a>d:
                heappush(left,-heappop(right))
                heappush(right,a)
                right_sum+=a-d
                left_sum-=d
            else:
                heappush(left,-a)
                left_sum-=a
            cnt=1
        else:
            c=-left[0]
            if a<c:
                heappush(right,-heappop(left))
                heappush(left,-a)
                right_sum+=c
                left_sum+=c-a
            else:
                heappush(right,a)
                right_sum+=a
            cnt=0
    else:
        x=-left[0]
        if cnt==0:
            print(x,b+right_sum+left_sum)
        else:
            print(x,b+x+right_sum+left_sum)

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect,insort
import itertools
q=int(input())
query=[list(map(int,input().split())) for i in range(q)]
inf=float("inf")
a_sum=0
b_sum=0
A=[]
count=0
for u in query:
    if u[0]==2:
        if count%2==1:
            print(A[num],a_sum+b_sum-A[num])
        else:
            print(A[num-1],a_sum+b_sum)
    else:
        count+=1
        a,b=u[1],u[2]
        b_sum+=b
        c=bisect(A,a)
        num=count//2
        if c>=num:
            if count%2==0:
                a_sum+=-2*A[num-1]+a
            else:
                a_sum+=a
            insort(A,a)
        else:
            if count%2==0:
                a_sum+=-a
            else:
                a_sum+=-a+2*A[num-1]
            insort(A,a)

Fixed submission:
from heapq import heappop,heappush
q=int(input())
query=[list(map(int,input().split())) for _ in range(q)]
inf=10**12
left=[inf]
left_sum=0
right=[inf]
right_sum=0

cnt=0
b=0
for i in range(q):
    if query[i][0]==1:
        a=query[i][1]
        b+=query[i][2]
        if cnt==0:
            d=right[0]
            if a>d:
                heappush(left,-heappop(right))
                heappush(right,a)
                right_sum+=a-d
                left_sum-=d
            else:
                heappush(left,-a)
                left_sum-=a
            cnt=1
        else:
            c=-left[0]
            if a<c:
                heappush(right,-heappop(left))
                heappush(left,-a)
                right_sum+=c
                left_sum+=c-a
            else:
                heappush(right,a)
                right_sum+=a
            cnt=0
    else:
        x=-left[0]
        if cnt==0:
            print(x,b+right_sum+left_sum)
        else:
            print(x,b+x+right_sum+left_sum)

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect,insort_left
import itertools
q=int(input())
query=[list(map(int,input().split())) for i in range(q)]
inf=float("inf")
a_sum=0
b_sum=0
A=[]
count=0
for u in query:
    if u[0]==2:
        if count%2==1:
            num=count//2
            print(A[num][0],a_sum+b_sum-A[num][0])
        else:
            num=count//2
            print(A[num-1][0],a_sum+b_sum)
    else:
        count+=1
        a,b=u[1],u[2]
        b_sum+=b
        c=bisect(A,[a,-inf])
        num=count//2
        if c>=num:
            A=list(itertools.chain(A[:c],[[a,a]],A[c:]))
            a_sum+=a
        else:
            A=list(itertools.chain(A[:c],[[a,-a]],A[c:]))
            a_sum+=-a
        if num==0:
            continue
        if A[num-1][1]==A[num-1][0]:
            a_sum+=-2*A[num-1][0]
            A[num-1][1]=-A[num-1][0]
        if A[num][1]!=A[num][0]:
            a_sum+=2*A[num][0]
            A[num][1]=A[num][0]

Fixed submission:
from heapq import heappop,heappush
q=int(input())
query=[list(map(int,input().split())) for _ in range(q)]
inf=10**12
left=[inf]
left_sum=0
right=[inf]
right_sum=0

cnt=0
b=0
for i in range(q):
    if query[i][0]==1:
        a=query[i][1]
        b+=query[i][2]
        if cnt==0:
            d=right[0]
            if a>d:
                heappush(left,-heappop(right))
                heappush(right,a)
                right_sum+=a-d
                left_sum-=d
            else:
                heappush(left,-a)
                left_sum-=a
            cnt=1
        else:
            c=-left[0]
            if a<c:
                heappush(right,-heappop(left))
                heappush(left,-a)
                right_sum+=c
                left_sum+=c-a
            else:
                heappush(right,a)
                right_sum+=a
            cnt=0
    else:
        x=-left[0]
        if cnt==0:
            print(x,b+right_sum+left_sum)
        else:
            print(x,b+x+right_sum+left_sum)