Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
import bisect
q=int(input())
h=[]
b=0 #bの和
s=0 #絶対偏差の和
med=0
for _ in range(q):
    Tmp=tuple(map(int,input().split()))
    if Tmp[0]==1:
        b+=Tmp[2]
        if len(h)%2:
            s+=abs(Tmp[1]-med)
        else:
            if h:
                med_next=h[(len(h)-1)//2+1]
                if Tmp[1]<=med:
                    s+=abs(Tmp[1]-med)
                elif Tmp[1]>=med_next:
                    s+=abs(Tmp[1]-med_next)
            else:
                med=Tmp[1]
        bisect.insort(h,Tmp[1])
        med=h[(len(h)-1)//2]
    else:
        print(med,s+b)

Fixed submission:
import sys
input=sys.stdin.readline
from heapq import heappush,heappop
q=int(input())
_,a,b=map(int,input().split())
Small=[-a]; Large=[]
cnt=1
med=a
c=b
s=0
for i in range(q-1):
    query=tuple(map(int,input().split()))
    if query[0]==1:
        _,a,b=query
        c+=b
        if cnt%2:
            s+=abs(a-med)
            if a<-Small[0]:
                heappush(Small,-a)
                heappush(Large,-heappop(Small))
            else:
                heappush(Large,a)
        else:
            if a<=-Small[0]:
                heappush(Small,-a)
                med=-Small[0]
                s+=med-a
            elif a<=Large[0]:
                heappush(Small,-a)
            else:
                heappush(Large,a)
                med=heappop(Large)
                s+=a-med
                heappush(Small,-med)
        cnt+=1
        med=-Small[0]
    else:
        print(med,s+c)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
import bisect
q=int(input())
h=[]
l=0 #hの要素数
b=0 #bの和
s=0 #絶対偏差の和
med=0
for _ in range(q):
    Tmp=tuple(map(int,input().split()))
    if Tmp[0]==1:
        b+=Tmp[2]
        if l%2:
            s+=abs(Tmp[1]-med)
        else:
            if l:
                med_next=h[(l-1)//2+1]
                if Tmp[1]<=med:
                    s+=abs(Tmp[1]-med)
                elif Tmp[1]>=med_next:
                    s+=abs(Tmp[1]-med_next)
            else:
                med=Tmp[1]
        l+=1
        bisect.insort(h,Tmp[1])
        med=h[(l-1)//2]
    else:
        print(med,s+b)

Fixed submission:
import sys
input=sys.stdin.readline
from heapq import heappush,heappop
q=int(input())
_,a,b=map(int,input().split())
Small=[-a]; Large=[]
cnt=1
med=a
c=b
s=0
for i in range(q-1):
    query=tuple(map(int,input().split()))
    if query[0]==1:
        _,a,b=query
        c+=b
        if cnt%2:
            s+=abs(a-med)
            if a<-Small[0]:
                heappush(Small,-a)
                heappush(Large,-heappop(Small))
            else:
                heappush(Large,a)
        else:
            if a<=-Small[0]:
                heappush(Small,-a)
                med=-Small[0]
                s+=med-a
            elif a<=Large[0]:
                heappush(Small,-a)
            else:
                heappush(Large,a)
                med=heappop(Large)
                s+=a-med
                heappush(Small,-med)
        cnt+=1
        med=-Small[0]
    else:
        print(med,s+c)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
import bisect
q=int(input())
h=[]
l=0 #hの要素数
b=0 #bの和
s=0 #絶対偏差の和
med=0
for _ in range(q):
    Tmp=list(map(int,input().split()))
    if Tmp[0]==1:
        b+=Tmp[2]
        if l%2:
            s+=abs(Tmp[1]-med)
        else:
            if l:
                med_next=h[(l-1)//2+1]
                if Tmp[1]<=med:
                    s+=abs(Tmp[1]-med)
                elif Tmp[1]>=med_next:
                    s+=abs(Tmp[1]-med_next)                
        l+=1
        bisect.insort(h,Tmp[1])
        med=h[(l-1)//2]
    else:
        print(med,s+b)

Fixed submission:
import sys
input=sys.stdin.readline
from heapq import heappush,heappop
q=int(input())
_,a,b=map(int,input().split())
Small=[-a]; Large=[]
cnt=1
med=a
c=b
s=0
for i in range(q-1):
    query=tuple(map(int,input().split()))
    if query[0]==1:
        _,a,b=query
        c+=b
        if cnt%2:
            s+=abs(a-med)
            if a<-Small[0]:
                heappush(Small,-a)
                heappush(Large,-heappop(Small))
            else:
                heappush(Large,a)
        else:
            if a<=-Small[0]:
                heappush(Small,-a)
                med=-Small[0]
                s+=med-a
            elif a<=Large[0]:
                heappush(Small,-a)
            else:
                heappush(Large,a)
                med=heappop(Large)
                s+=a-med
                heappush(Small,-med)
        cnt+=1
        med=-Small[0]
    else:
        print(med,s+c)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
import bisect
q=int(input())
h=[]
l=0 #hの要素数
b=0 #bの和
s=0 #絶対偏差の和
med=0
for _ in range(q):
    Tmp=list(map(int,input().split()))
    if Tmp[0]==1:
        b+=Tmp[2]
        if l%2:
            s+=abs(Tmp[1]-med)
        else:
            if l:
                med_next=h[(l-1)//2+1]
                if Tmp[1]<=med:
                    s+=abs(Tmp[1]-med)
                elif Tmp[1]>=med_next:
                    s+=abs(Tmp[1]-med_next)                
        l+=1
        bisect.insort(h,Tmp[1])
        med=h[(l-1)//2]
    else:
        print(med,s+b)

Fixed submission:
import sys
input=sys.stdin.readline
from heapq import heappush,heappop
q=int(input())
_,a,b=map(int,input().split())
Small=[-a]; Large=[]
cnt=1
med=a
c=b
s=0
for i in range(q-1):
    query=tuple(map(int,input().split()))
    if query[0]==1:
        _,a,b=query
        c+=b
        if cnt%2:
            s+=abs(a-med)
            if a<-Small[0]:
                heappush(Small,-a)
                heappush(Large,-heappop(Small))
            else:
                heappush(Large,a)
        else:
            if a<=-Small[0]:
                heappush(Small,-a)
                med=-Small[0]
                s+=med-a
            elif a<=Large[0]:
                heappush(Small,-a)
            else:
                heappush(Large,a)
                med=heappop(Large)
                s+=a-med
                heappush(Small,-med)
        cnt+=1
        med=-Small[0]
    else:
        print(med,s+c)