Buggy python submission (verdict: Time Limit Exceeded):
from statistics import median
q0=int(input())
ind2=0
ind1=0
a=[]
b=0
for iii in range(q0):
  q=[int(_) for _ in input().split()]
  lenq=len(q)
  if lenq==1:
    a.sort()
    la=len(a)-1
    ind1=a[la//2]
    ind2=sum([abs(_a-ind1) for _a in a])+b
    print(ind1,ind2)
  elif lenq==3:
    a.append(q[1])
    b+=q[2]

Fixed submission:
import heapq as h
q_num=int(input())
bsum=0
high=[]
low=[]
asum=0
for iii in range(q_num):
  q=[int(_) for _ in input().split()]
  if q[0]==1:
    bsum+=q[2]
    if len(low)==0:
      h.heappush(low,-q[1])
    else:
      asum+=abs(q[1]+low[0])
      if -low[0]>=q[1]:
        h.heappush(low,-q[1])
      else:
        h.heappush(high,q[1])
      
    if len(low)>=len(high)+2:
      ltoh=h.heappop(low)
      h.heappush(high, -ltoh)
    elif len(high)>=len(low)+1:
      ltoh=h.heappop(high)
      asum+=-low[0]-ltoh
      h.heappush(low, -ltoh)
  else:
    print(-low[0],asum+bsum)

Buggy python submission (verdict: Time Limit Exceeded):
from statistics import median
q0=int(input())
ind2=0
ind1=0
a=[]
b=[]
for iii in range(q0):
  q=[int(_) for _ in input().split()]
  lenq=len(q)
  if lenq==1:
    a.sort()
    la=len(a)-1
    ind1=a[la//2]
    ind2=sum([abs(_a-ind1) for _a in a])+sum(b)
    print(ind1,ind2)
  elif lenq==3:
    a.append(q[1])
    b.append(q[2])

Fixed submission:
import heapq as h
q_num=int(input())
bsum=0
high=[]
low=[]
asum=0
for iii in range(q_num):
  q=[int(_) for _ in input().split()]
  if q[0]==1:
    bsum+=q[2]
    if len(low)==0:
      h.heappush(low,-q[1])
    else:
      asum+=abs(q[1]+low[0])
      if -low[0]>=q[1]:
        h.heappush(low,-q[1])
      else:
        h.heappush(high,q[1])
      
    if len(low)>=len(high)+2:
      ltoh=h.heappop(low)
      h.heappush(high, -ltoh)
    elif len(high)>=len(low)+1:
      ltoh=h.heappop(high)
      asum+=-low[0]-ltoh
      h.heappush(low, -ltoh)
  else:
    print(-low[0],asum+bsum)

Buggy python submission (verdict: Runtime Error):
from statistics import median
q0=int(input())
ind=0
a=[]
b=[]
for iii in range(q0):
  q=[int(_) for _ in input().split()]
  lenq=len(q)
  if lenq==1:
    meda=median(a)
    ind=sum([abs(_a-meda) for _a in a])+sum(b)
    i=1
    while sum([abs(_a-i-meda) for _a in a])+sum(b)==ind:
      i+=1
    print(int(meda-i+1),int(ind))
  elif lenq==3:
    a.append(q[1])
    b.append(q[2])

Fixed submission:
import heapq as h
q_num=int(input())
bsum=0
high=[]
low=[]
asum=0
for iii in range(q_num):
  q=[int(_) for _ in input().split()]
  if q[0]==1:
    bsum+=q[2]
    if len(low)==0:
      h.heappush(low,-q[1])
    else:
      asum+=abs(q[1]+low[0])
      if -low[0]>=q[1]:
        h.heappush(low,-q[1])
      else:
        h.heappush(high,q[1])
      
    if len(low)>=len(high)+2:
      ltoh=h.heappop(low)
      h.heappush(high, -ltoh)
    elif len(high)>=len(low)+1:
      ltoh=h.heappop(high)
      asum+=-low[0]-ltoh
      h.heappush(low, -ltoh)
  else:
    print(-low[0],asum+bsum)

Buggy python submission (verdict: Time Limit Exceeded):
from statistics import median
q0=int(input())
ind=0
a=[]
b=[]
for iii in range(q0):
  q=[int(_) for _ in input().split()]
  lenq=len(q)
  if lenq==1:
    meda=median(a)
    ind=sum([abs(_a-meda) for _a in a])+sum(b)
    i=1
    while sum([abs(_a-i-meda) for _a in a])+sum(b)==ind:
      i+=1
    print(int(meda-i+1),int(ind))
  elif lenq==3:
    a.append(q[1])
    b.append(q[2])

  
    
    


Fixed submission:
import heapq as h
q_num=int(input())
bsum=0
high=[]
low=[]
asum=0
for iii in range(q_num):
  q=[int(_) for _ in input().split()]
  if q[0]==1:
    bsum+=q[2]
    if len(low)==0:
      h.heappush(low,-q[1])
    else:
      asum+=abs(q[1]+low[0])
      if -low[0]>=q[1]:
        h.heappush(low,-q[1])
      else:
        h.heappush(high,q[1])
      
    if len(low)>=len(high)+2:
      ltoh=h.heappop(low)
      h.heappush(high, -ltoh)
    elif len(high)>=len(low)+1:
      ltoh=h.heappop(high)
      asum+=-low[0]-ltoh
      h.heappush(low, -ltoh)
  else:
    print(-low[0],asum+bsum)