Problem:
 Score : 600 points    Problem Statement There is a function f(x) , which is initially a constant function f(x) = 0 .  We will ask you to process Q queries in order. There are two kinds of queries, update queries and evaluation queries, as follows:   An update query 1 a b : Given two integers a and b , let g(x) = f(x) + |x - a| + b and replace f(x) with g(x) .  An evaluation query 2 : Print x that minimizes f(x) , and the minimum value of f(x) . If there are multiple such values of x , choose the minimum such value.   We can show that the values to be output in an evaluation query are always integers, so we ask you to print those values as integers without decimal points.      Constraints  All values in input are integers.  1 \leq Q \leq 2 \times 10^5  -10^9 \leq a, b \leq 10^9  The first query is an update query.         Input Input is given from Standard Input in the following format:  Q  Query_1  :  Query_Q   See Sample Input 1 for an example.      Output For each evaluation query, print a line containing the response, in the order in which the queries are given.  The response to each evaluation query should be the minimum value of x that minimizes f(x) , and the minimum value of f(x) , in this order, with space in between.        Sample Input 1 4
1 4 2
2
1 1 -8
2      Sample Output 1 4 2
1 -3  In the first evaluation query, f(x) = |x - 4| + 2 , which attains the minimum value of 2 at x = 4 .  In the second evaluation query, f(x) = |x - 1| + |x - 4| - 6 , which attains the minimum value of -3 when 1 \leq x \leq 4 . Among the multiple values of x that minimize f(x) , we ask you to print the minimum, that is, 1 .       Sample Input 2 4
1 -1000000000 1000000000
1 -1000000000 1000000000
1 -1000000000 1000000000
2      Sample Output 2 -1000000000 3000000000

Solution (Python):
from heapq import heappush, heappushpop
import sys

input = sys.stdin.readline

Q = int(input())

update_count = 0
al = []
sl = 0
ar = []
sr = 0
b = 0
for _ in range(Q):
    
    
    
    
    s = tuple(map(int, input().split()))
    if s[0] == 1:
        
        b += s[2]
        if update_count % 2 == 0:  
            x = heappushpop(ar, s[1])  
            sr += s[1] - x
            sl += x
            x *= (-1)
            heappush(al, x)  
        else:  
            x = heappushpop(al, -s[1])  
            x *= (-1)
            sl += s[1] - x
            sr += x
            heappush(ar, x)  
        update_count += 1
        
        
    else:
        
        x = -al[0]  
        cnt_l = (update_count + 1) // 2
        cnt_r = update_count - cnt_l
        print(x, (cnt_l * x - sl) + (sr - cnt_r * x) + b)

Solution (Python):
from heapq import heappush, heappop
import sys

input = sys.stdin.readline

Q = int(input())

update_count = 0
al = []
sl = 0
ar = []
sr = 0
b = 0
for _ in range(Q):
    
    
    
    
    s = tuple(map(int, input().split()))
    if s[0] == 1:
        
        b += s[2]
        if update_count % 2 == 0:
            
            heappush(ar, s[1])  
            sr += s[1]
            x = heappop(ar)  
            sr -= x
            heappush(al, -x)  
            sl += x
        else:
            
            heappush(al, -s[1])  
            sl += s[1]
            x = heappop(al)  
            sl -= (-x)
            heappush(ar, -x)  
            sr += (-x)
        update_count += 1
        
        
    else:
        
        x = heappop(al)  
        heappush(al, x)
        x *= (-1)
        cnt_l = (update_count + 1) // 2
        cnt_r = update_count - cnt_l
        print(x, (cnt_l * x - sl) + (sr - cnt_r * x) + b)

Solution (Python):
from heapq import heappush, heappop

Q = int(input())

update_count = 0
al = []
sl = 0
ar = []
sr = 0
b = 0
for _ in range(Q):
    
    
    
    
    s = tuple(map(int, input().split()))
    if s[0] == 1:
        
        b += s[2]
        if update_count % 2 == 0:
            
            heappush(ar, s[1])  
            sr += s[1]
            x = heappop(ar)  
            sr -= x
            heappush(al, -x)  
            sl += x
        else:
            
            heappush(al, -s[1])  
            sl += s[1]
            x = heappop(al)  
            sl -= (-x)
            heappush(ar, -x)  
            sr += (-x)
        update_count += 1
        
        
    else:
        
        x = heappop(al)  
        heappush(al, x)
        x *= (-1)
        cnt_l = (update_count + 1) // 2
        cnt_r = update_count - cnt_l
        print(x, (cnt_l * x - sl) + (sr - cnt_r * x) + b)

Solution (Python):
from heapq import heappop,heappush
Q=int(input())
M=[input() for i in range(Q)]
A=[]

B=[]

a=0
b=0
sumb=0
n=0
for q in M:
    if q[0]=='1':
        num,x,y=map(int,q.split())
        sumb+=y
        n+=1
        m=(n+1)//2
        if n==1:
            heappush(A,-x)
            a+=x
            
            continue
        if -A[0]>=x:
            heappush(A,-x)
            a+=x
            if len(A)>m:
                z=heappop(A)
                a+=z
                heappush(B,-z)
                b+=-z
        else:
            heappush(B,x)
            b+=x
            if len(B)>n-m:
                z=heappop(B)
                b-=z
                heappush(A,-z)
                a+=z
        
    else:
        if n%2==0:
            print(-A[0],sumb+b-a)
        else:
            print(-A[0],sumb+b-a-A[0])

Solution (Python):
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)

Solution (Python):
from heapq import*
L,R=[],[]
B=t=0
Q,*E=open(0)
for e in E:
	if' 'in e:_,a,b=map(int,e.split());t^=1;a*=2*t-1;c=heappushpop([L,R][t],a);heappush([R,L][t],-c);B+=b+a-c-c
	else:print(-L[0],B-L[0]*t)

Solution (Python):

from heapq import *

q = int(input())
sum_a = 0
sum_b = 0
L = []
R = []
for _ in range(q):
    qi = list(map(int, input().split()))
    if qi[0] == 1:
        a = qi[1]
        heappush(L, -a)
        heappush(R, a)
        if -L[0] > R[0]:
            LtoR = -heappop(L)
            RtoL = heappop(R)
            sum_a += LtoR - RtoL
            heappush(L, -RtoL)
            heappush(R, LtoR)
        sum_b += qi[2]
    else:
        print(-L[0], sum_a + sum_b)

Solution (Python):
import heapq
import sys

inp = sys.stdin.readline

Q = int(input())
B = 0

q, a, b = map(int, inp().split())
L, R = [-a], [a]
L_sum, R_sum = a, a
B = b

for i in range(Q - 1):
    q = list(map(int, inp().split()))
    if len(q) == 3:
        A = q[1]
        B += q[2]

        if A <= -L[0]:
            heapq.heappush(L, -A)
            M = -heapq.heappushpop(L, -A)
            heapq.heappush(R, M)

            L_sum += (2 * A - M)
            R_sum += M
        else:
            heapq.heappush(R, A)
            M = heapq.heappushpop(R, A)
            heapq.heappush(L, -M)

            R_sum += (2 * A - M)
            L_sum += M
    else:
        N = len(L)
        X = -L[0]
        print(X, (abs(L_sum - X * N) + abs(R_sum - X * N)) // 2 + B)

Solution (Python):
from heapq import*

class median_tree(object):
    def __init__(self):
        self.lower_than_med=[]
        self.higher_than_med=[]
        self.count=0
        self.low=0
        self.high=0
        self.median=0
    def push(self,x):
        self.count=1-self.count
        if self.count:
            y=heappushpop(self.higher_than_med,x)
            heappush(self.lower_than_med,-y)
            self.low +=-y
            self.high+=x-y
        else:
            y=heappushpop(self.lower_than_med,-x)
            heappush(self.higher_than_med,-y)
            self.low -=x+y
            self.high-=y
        self.median=-self.lower_than_med[0]

from heapq import*
n=int(input())
m=median_tree()

B=0
for i in range(n):
    I=input()
    if I[0]=="1":
        a,b,c=map(int,I.split())
        B+=c
        m.push(b)
    else:
        print(m.median,m.count*m.median+B+m.low+m.high)

Solution (Python):
from heapq import*

class median_tree(object):
    def __init__(self):
        self.lower_than_med=[]
        self.higher_than_med=[]
        self.count=0
        self.low=0
        self.high=0
        self.median=0
    def push(self,x):
        self.count=1-self.count
        if self.count:
            y=heappushpop(self.higher_than_med,x)
            heappush(self.lower_than_med,-y)
            self.low +=-y
            self.high+=x-y
        else:
            y=heappushpop(self.lower_than_med,-x)
            heappush(self.higher_than_med,-y)
            self.low -=x+y
            self.high-=y
        self.median=-self.lower_than_med[0]

from heapq import*
n=int(input())
m=median_tree()

B=0
for i in range(n):
    I=input()
    if I[0]=="1":
        a,b,c=map(int,I.split())
        B+=c
        m.push(b)
    else:
        print(m.median,m.count%2*m.median+B+m.low+m.high)

Solution (Python):
from heapq import*
L,R=[],[]
n=int(input())
B=0
cnt=0
l,r=0,0
for i in range(n):
    I=input()
    if I[0]=="1":
        a,b,c=map(int,I.split())
        B+=c
        cnt+=1
        
        if cnt%2:
            x=heappushpop(R,b)
            r+=b-x
            heappush(L,-x)
            l+=-x
        else:
            x=heappushpop(L,-b)
            l+=-b-x
            heappush(R,-x)
            r+=-x
        
        
    else:
        med=-L[0]


        print(med,cnt%2*med+B+l+r)

Solution (Python):
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)

Solution (Python):
import sys
from itertools import accumulate
from collections import Counter
from bisect import bisect as br, bisect_left as bl
class DammyMap:
    
    def __init__(self, A, B, issum = False):
        
        self.X, self.comp = self.compress(B)
        self.size = len(self.X)
        self.tree = [0] * (self.size + 1)
        self.p = 2**(self.size.bit_length() - 1)
        self.dep = self.size.bit_length()
        
        CA = Counter(A)
        S = [0] + list(accumulate([CA[self.X[i]] for i in range(self.size)]))
        for i in range(1, 1+self.size):
            self.tree[i] = S[i] - S[i - (i&-i)]
        if issum:
            self.sumtree = [0] * (self.size + 1)
            Ssum = [0] + list(accumulate([CA[self.X[i]]*self.X[i] for i in range(self.size)]))
            for i in range(1, 1+self.size):
                self.sumtree[i] = Ssum[i] - Ssum[i - (i&-i)]
    def compress(self, L):
        
        L2 = list(set(L))
        L2.sort()
        C = {v : k for k, v in enumerate(L2, 1)}
        
        return L2, C
    
    def leng(self):
        
        return self.count(self.size)
    
    def count(self, i):
        
        i = self.comp[i]
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
    
    def less(self, v):
        
        i = bl(self.X, v)
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
    
    def leq(self, v):
        
        i = br(self.X, v)
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        
        i = self.comp[i]
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
        
        
    def get(self, v):
        
        if v <= 0:
            return -1
        s = 0
        k = self.p
        for _ in range(self.dep):
            if s + k <= self.size and self.tree[s+k] < v:
                s += k
                v -= self.tree[s]
            k //= 2
        return self.X[s]
    
    def addsum(self, i, x):
        
        x *= i
        i = self.comp[i]
        while i <= self.size:
            self.sumtree[i] += x
            i += i & -i
    
    def countsum(self, i):
        
        i = self.comp[i]
        s = 0
        while i > 0:
            s += self.sumtree[i]
            i -= i & -i
        return s
    
    def getsum(self, v):
        
        x = self.get(v)
        return self.countsum(x) - x*(self.count(x) - v)

Q = int(input())

sumi = 0
geta = 0
k = 0
Query = [list(map(int, sys.stdin.readline().split())) for _ in range(Q)]
A = [q[1] for q in Query if len(q) == 3]

T = DammyMap([], A, issum = True)
for q in Query:
    if q[0] == 1:
        k += 1
        geta += q[2]
        a = q[1]
        sumi += a
        T.add(a, 1)
        T.addsum(a, 1)
    else:
        med = T.get(-(-k//2))
        smallsum = T.getsum(-(-k//2))
        print(med, geta + (k%2)*med + sumi - 2*smallsum)

Solution (Python):
from heapq import*
L,R=[],[]
B=t=0
Q,*E=open(0)
for e in E:
	if' 'in e:_,a,b=map(int,e.split());t=1-t;a*=2*t-1;c=heappushpop([L,R][t],a);heappush([R,L][t],-c);B+=b+a-c-c
	else:print(-L[0],B-L[0]*t)

Solution (Python):

import heapq



def main():
    Q = int(input())
    sum_b = 0
    sum_al = 0
    sum_ar = 0
    hl = []
    hr = []
    for _ in range(Q):
        buf = input()
        if buf[0] == '1':
            _, a, b = map(int, buf.split())
            sum_b += b
            if len(hl) == 0:
                heapq.heappush(hl, -a)
                sum_al += a
                continue
            if len(hr) == 0:
                heapq.heappush(hr, a)
                sum_ar += a
                if -hl[0] > hr[0]:
                    hl[0], hr[0] = -hr[0], -hl[0]
                    sum_al, sum_ar = sum_ar, sum_al
                continue

            if a < -hl[0]:
                heapq.heappush(hl, -a)
                sum_al += a
            elif a > hr[0]:
                heapq.heappush(hr, a)
                sum_ar += a
            else:
                
                heapq.heappush(hl, -a)
                sum_al += a
                
                

            while len(hr) > len(hl):
                tmp = heapq.heappop(hr)
                sum_ar -= tmp
                heapq.heappush(hl, -tmp)
                sum_al += tmp
            while len(hl) > len(hr)+1:
                tmp = heapq.heappop(hl)
                sum_al -= -tmp
                heapq.heappush(hr, -tmp)
                sum_ar += -tmp

        else:
            tmp_al = -hl[0]*len(hl)-sum_al if len(hl) != 0 else 0
            tmp_ar = sum_ar-(-hl[0])*len(hr) if len(hl) != 0 else 0
            
            print(-hl[0], tmp_al+tmp_ar+sum_b)

if __name__ == '__main__':
    main()

Solution (Python):
from heapq import heappush as hp, heappushpop as hppp
import sys
Q = int(input())

sumis = 0
sumib = 0
S = []
B = []

geta = 0
k = 0
med = 0

for _ in range(Q):
    
    q = sys.stdin.readline().split()
    if q[0] == '1':
        k += 1
        m = int(q[1])
        geta += int(q[2])
        if k % 2 == 1:
            if med < m:
                x = hppp(B, m)
                sumib += m - x
                hp(S, -x)
                sumis += x
            else:
                hp(S, -m)
                sumis += m
        else:
            if med < m:
                hp(B, m)
                sumib += m
            else:
                x = -hppp(S, -m)
                sumis += m - x
                hp(B, x)
                sumib += x
        med = -S[0]
        
    else:
        print(med, geta + med*(k%2) - sumis + sumib)

Solution (Python):
import heapq as hq
Q = int(input())
minval = 0
argminval = -(10**9)

L, R = [10**9], [10**9]
lenL, lenR = 0, 0

for _ in range(Q):
    qi = list(map(int, input().split()))
    if qi[0] == 1:
        ai, bi = qi[1], qi[2]
        LC, RC = -1*L[0], R[0] 
        if lenL == lenR:
            if ai < RC:
                
                hq.heappush(L, -1*ai)
            else:
                
                hq.heappop(R)
                hq.heappush(L, -1*RC)
                hq.heappush(R, ai)
            lenL += 1
            
            argminval = -1*L[0]
            minval += abs(argminval - ai) + bi
        else:
            if ai < LC:
                
                hq.heappop(L)
                hq.heappush(L, -1*ai)
                hq.heappush(R, LC)
            else:
                
                hq.heappush(R, ai)
            lenR += 1
            
            minval += abs(argminval - ai) + bi
            argminval = -1*L[0]
    else:
        print("{} {}".format(argminval, minval))

Solution (Python):

"""
Created on Tue May 28 22:22:21 2019

@author: Yamazaki Kenichi
"""
import heapq

Q = int(input())
Q2 = [input() for i in range(Q)]

ans = []
Al,Ar = [-(-(10**9+1))],[10**9+1]
d, a, b = map(int,Q2[0].split())
heapq.heappush(Al,-a)
B = b

for i in range(1,Q):
    if Q2[i][0] == '1':

        d, a, b = map(int,Q2[i].split())
        if len(Al) == len(Ar):
            if a < Ar[0]:
                heapq.heappush(Al,-a)
            else:
                heapq.heappush(Ar,a)
                heapq.heappush(Al,-(heapq.heappop(Ar)))
            C = abs(a - (-Al[0]))
        else:
            C = abs(a - (-Al[0]))
            if a < Ar[0]:
                heapq.heappush(Al,-a)
                heapq.heappush(Ar,-(heapq.heappop(Al)))
            else:
                heapq.heappush(Ar,a)
        B += (b + C)

    else:

        ans.append([(-Al[0]),B])

for c in ans:
    print(' '.join(map(str,c)))

Solution (Python):

"""
Created on Tue May 28 22:22:21 2019

@author: Yamazaki Kenichi
"""
import heapq

Q = int(input())
Q2 = [input() for i in range(Q)]

ans = []
Al,Ar = [-(-(10**9+1))],[10**9+1]
B = 0
flg = False
for q in Q2:
    if q[0] == '1':

        d, a, b = map(int,q.split())
        if not flg:
            heapq.heappush(Al,-a)
            B += b
            flg = True
            continue
        

        if len(Al) == len(Ar):
            if a < Ar[0]:

                heapq.heappush(Al,-a)




                C = abs(a - (-Al[0]))
            else:
                heapq.heappush(Ar,a)
                heapq.heappush(Al,-(heapq.heappop(Ar)))
                C = abs(a - (-Al[0]))
        else:
            if a < Ar[0]:
                C = abs(a - (-Al[0]))
                heapq.heappush(Al,-a)
                heapq.heappush(Ar,-(heapq.heappop(Al)))


            else:
                C = abs(a - (-Al[0]))
                heapq.heappush(Ar,a)

        B += (b + C)

    else:

        ans.append([(-Al[0]),B])
        
for c in ans:
    print(' '.join(map(str,c)))

Solution (Python):
from heapq import heappop, heappush
Q = int(input())
maxh = []
minh = []
sum1 = sum2 = b = med = 0
for i in range(Q):
  q = list(map(int, input().split()))
  if q[0]==1:
    b += q[2]
    if len(maxh)==0 or q[1]<-maxh[0]:
      heappush(maxh, -q[1])
      sum1 += q[1]
      if len(maxh)>len(minh)+1:
        t = -heappop(maxh)
        heappush(minh, t)
        sum1 -= t
        sum2 += t
    else:
      heappush(minh, q[1])
      sum2 += q[1]
      if len(maxh)<len(minh):
        t = heappop(minh)
        heappush(maxh, -t)
        sum1 += t
        sum2 -= t
    med = -maxh[0]
  else:
    ans = len(maxh)*med-sum1+sum2-len(minh)*med+b
    print(med, ans)

Solution (Python):

import heapq as hq

Q = int(input())



low = []
high = []

_,mid,val = map(int,input().split())

for _ in range(Q-1):
    s = input()
    if s[0] == '1':
        _,a,b = map(int,s.split())
        if mid is None:
            if a < -low[0]:
                mid = -hq.heapreplace(low, -a)
            elif a > high[0]:
                mid = hq.heapreplace(high, a)
            else:
                mid = a
            val += abs(mid-a)+b
        else:
            val += abs(mid-a)+b
            x,y = sorted((a,mid))
            hq.heappush(high, y)
            hq.heappush(low, -x)
            mid = None

    else:
        print(-low[0] if mid is None else mid, val)

Solution (Python):
import sys, heapq
F = sys.stdin
def single_input(): return F.readline().strip("\n")
def line_input(): return F.readline().strip("\n").split()
  
def solve():
    Q = int(single_input())
    n, a, b = map(int, line_input())
    left, right = [-a], [a]
    heapq.heapify(left)
    heapq.heapify(right)
    minans =  b
    ans = ""
    for i in range(1, Q):
        queri = [int(i) for i in line_input()]
        if queri[0] == 1:
            a, b = queri[1:]
            minans += b
            if -1 * left[0] <= a <= right[0]:
                heapq.heappush(left, -a)
                heapq.heappush(right, a)
            elif a < -1 * left[0]:
                minans += (-1 * left[0]) - a
                heapq.heappush(left, -a)
                heapq.heappush(left, -a)
                heapq.heappush(right, -1 * heapq.heappop(left))
            else:
                minans += a - right[0]
                heapq.heappush(left, -1 * heapq.heappop(right))
                heapq.heappush(right, a)
                heapq.heappush(right, a)
        else: ans += str(-1 * left[0]) + " " + str(minans) + "\n"
    print(ans)

    return 0
  
if __name__ == "__main__":
    solve()

Solution (Python):
import sys, math, collections, heapq, itertools
from bisect import bisect_left
F = sys.stdin
def single_input(): return F.readline().strip("\n")
def line_input(): return F.readline().strip("\n").split()
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0: a, b = b, a % b
    return b
  
def solve():
    Q = int(single_input())
    n, a, b = map(int, line_input())
    left, right = [-a], [a]
    heapq.heapify(left)
    heapq.heapify(right)
    minans =  b
    for i in range(1, Q):
        queri = [int(i) for i in line_input()]
        if queri[0] == 1:
            a, b = queri[1:]
            minans += b
            if -1 * left[0] <= a <= right[0]:
                heapq.heappush(left, -a)
                heapq.heappush(right, a)
            elif a < -1 * left[0]:
                minans += (-1 * left[0]) - a
                heapq.heappush(left, -a)
                heapq.heappush(left, -a)
                heapq.heappush(right, -1 * heapq.heappop(left))
            else:
                minans += a - right[0]
                heapq.heappush(left, -1 * heapq.heappop(right))
                heapq.heappush(right, a)
                heapq.heappush(right, a)
        else: print(-1 * left[0], minans)

    return 0
  
if __name__ == "__main__":
    solve()

Solution (Python):
import sys, math, collections, heapq, itertools
from bisect import bisect_left
F = sys.stdin
def single_input(): return F.readline().strip("\n")
def line_input(): return F.readline().strip("\n").split()
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0: a, b = b, a % b
    return b
  
def solve():
    Q = int(single_input())
    n, a, b = map(int, line_input())
    left, right = [-a], [a]
    heapq.heapify(left)
    heapq.heapify(right)
    minans =  b
    for i in range(1, Q):
        queri = [int(i) for i in line_input()]
        if queri[0] == 1:
            a, b = queri[1:]
            minans += b
            left_upper = -1 * heapq.heappop(left)
            right_lower = heapq.heappop(right)
            if left_upper <= a <= right_lower:
                heapq.heappush(left, -a)
                heapq.heappush(left, -1 * left_upper)
                heapq.heappush(right, a)
                heapq.heappush(right, right_lower)
            elif a < left_upper:
                minans += left_upper - a
                heapq.heappush(left, -a)
                heapq.heappush(left, -a)
                heapq.heappush(right, left_upper)
                heapq.heappush(right, right_lower)
            else:
                minans += a - right_lower
                heapq.heappush(left, -1 * left_upper)
                heapq.heappush(left, -1 * right_lower)
                heapq.heappush(right, a)
                heapq.heappush(right, a)
        else:
            left_lower = -1 * heapq.heappop(left)
            print(left_lower, minans)
            heapq.heappush(left, -1 * left_lower)
    return 0
  
if __name__ == "__main__":
    solve()

Solution (Python):
import heapq

Q = int(input())


def update(ans, a, b):
    heapq.heappush(lq, -a)
    heapq.heappush(rq, a)
    lmax, rmin = -lq[0], rq[0]
    ans += b
    if lmax > rmin:
        lmax, rmin = rmin, lmax
        ans += rmin - lmax
        heapq.heappop(lq)
        heapq.heappop(rq)
        heapq.heappush(lq, -lmax)
        heapq.heappush(rq, rmin)
    return ans


def query():
    return str(-lq[0]) + ' ' + str(ans)


lq = []
rq = []
ans = 0

for i in range(Q):
    q = list(map(str, input().split()))
    if len(q) == 1:
        print(query())
    else:
        one, a, b = q
        ans = update(ans, int(a), int(b))

Solution (Python):
from heapq import heappop, heappush, heappushpop

n = int(input())
q = [tuple(int(x) for x in input().split()) for _ in range(n)]

L = []
R = []
a = 1
b = q[0][2]

ans = 0

heappush(L, -q[0][1])

for i in range(1, n):
    temp = q[i]
    if temp[0] == 1:
        a += 1
        if a % 2 == 0:
            ans += abs(temp[1] + L[0])
            p = heappushpop(L, - temp[1])
            heappush(R, - p)
        else:
            ans += abs(temp[1] + L[0])
            tl = L[0]
            p = heappushpop(R, temp[1])
            heappush(L, - p)
            if tl != L[0]:
                ans -= abs(tl - L[0])
        b += temp[2]
    else:
        m = - L[0]
        print(m, ans + b)

Solution (Python):
import sys
input = sys.stdin.readline

import heapq
MIN=[]
MAX=[]
ANS=0
SCORE=0

Queries=int(input())
for i in range(Queries):
    Q=list(map(int,input().split()))

    if Q[0]==1:
        ANS+=Q[2]
        heapq.heappush(MIN,Q[1])
        heapq.heappush(MAX,-Q[1])

        if MIN[0]<-MAX[0]:
            x=heapq.heappop(MIN)
            y=-heapq.heappop(MAX)

            SCORE+=(y-x)
            heapq.heappush(MIN,y)
            heapq.heappush(MAX,-x)

    else:
        print(-MAX[0],ANS+SCORE)

Solution (Python):
import heapq

Q = int(input())
Query = [input() for _ in range(Q)]

ans = 0

lq = []
rq = []

for q in Query :
    if q[0] == '1' :
        a, b = map(int, q[2:].split())
        
        heapq.heappush(lq, -a)
        heapq.heappush(rq, a)

        lmax, rmin = -lq[0], rq[0]
        if lmax > rmin :
            lmax, rmin = rmin, lmax
            ans += rmin - lmax

            heapq.heappop(lq)
            heapq.heappop(rq)
            heapq.heappush(lq, -lmax)
            heapq.heappush(rq, rmin)

        ans += b

    else :
        print(-lq[0], ans)

Solution (Python):
import sys
input = sys.stdin.readline
inf = float('inf')
mod = 10**9+7


def INT_(n): return int(n)-1


def MI(): return map(int, input().split())


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [input() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')


def main():
    from heapq import heappush, heappushpop, heappop
    Q = I()
    
    high = []
    
    low = []

    _, a, b = MI()
    heappush(low, -a)

    debug = [a]

    
    def solve(n):
        ans = 0
        for a in debug:
            ans += abs(a - n)

        return B + ans

    B = b
    ans = 0
    cnt = 1
    for _ in range(Q - 1):
        inp = input()
        if inp[0] == "1":
            _, a, b = map(int, inp.split())
            B += b
            debug.append(a)
            cnt += 1

            
            if cnt % 2 == 0:
                ans += abs(-low[0]-a)
                even = True
            else:
                even = False

            
            if a > -low[0]:
                heappush(high, a)
            else:
                heappush(low, -a)

            
            if len(low) < len(high):
                heappush(low, -heappop(high))
            elif len(low) > len(high) + 1:
                heappush(high, -heappop(low))

            
            if not even:
                ans += abs(-low[0] - a)

        else:
            print(-low[0], ans + B)
            
        
    


if __name__ == '__main__':
    main()