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):
class BalancingTree:
    def __init__(self, n):
        self.N = n
        self.id_size=0
        self.root = self.node(1<<(n+self.id_size), 1<<(n+self.id_size),self.id_size)
        self.val_dic={}

    def debug(self):
        def debug_info(nd_):
            return (nd_.value,(nd_.value - 1)>>self.id_size, nd_.pivot , nd_.left.value - 1 if nd_.left else -1, nd_.right.value - 1 if nd_.right else -1,nd_.cnt)

        def debug_node(nd):
            re = []
            if nd.left:
                re += debug_node(nd.left)
            if nd.value: re.append(debug_info(nd))
            if nd.right:
                re += debug_node(nd.right)
            return re
        print("Debug - root =", self.root.value - 1, debug_node(self.root)[:50])

    def rebuild(self,v):
        self.id_size+=1
        
        self.root=self.node(1<<(self.N+self.id_size), 1<<(self.N+self.id_size),self.id_size)
        check=[]
        for val in self.val_dic:
            cnt=self.val_dic[val]
            self.val_dic[val]=0
            for j in range(cnt):
                self.append(val)
        self.append(v)

    def append(self,v):
        if v not in self.val_dic:
            self.val_dic[v]=0
        id=self.val_dic[v]
        if id>=2**self.id_size:
            self.rebuild(v)
        else:
            V=(v<<self.id_size)+id
            self.val_dic[v]+=1
            self._append(V)

    def _append(self, v):
        v += 1
        nd = self.root
        while True:
            if v == nd.value:
                return 0
            else:
                nd.cnt+=1
                nd.sum+=(v-1)>>self.id_size
                mi, ma = min(v, nd.value), max(v, nd.value)
                if mi < nd.pivot:
                    nd.value = ma
                    if nd.left:
                        nd = nd.left
                        v = mi
                    else:
                        p = nd.pivot
                        nd.left = self.node(mi, p - (p&-p)//2,self.id_size)
                        break
                else:
                    nd.value = mi
                    if nd.right:
                        nd = nd.right
                        v = ma
                    else:
                        p = nd.pivot
                        nd.right = self.node(ma, p + (p&-p)//2,self.id_size)
                        break

    def kth(self,k):
        cnt=k
        nd=self.root
        while True:
            if nd.left:
                if nd.left.cnt<k:
                    k-=nd.left.cnt+1
                    if nd.right:
                        nd=nd.right
                    else:
                        raise IndexError("BalancingTree doesn't hold kth number")
                elif nd.left.cnt==k:
                    return (nd.value-1)>>self.id_size
                else:
                    nd=nd.left
            else:
                if k==0:
                    return (nd.value-1)>>self.id_size
                if nd.right:
                    k-=1
                    nd=nd.right
                else:
                    raise IndexError("BalancingTree doesn't hold kth number")

    def kth_sum(self,k):
        if k==-1:
            return 0
        cnt=k
        res_sum=0
        nd=self.root
        while True:
            if nd.left:
                if nd.left.cnt<k:
                    k-=nd.left.cnt+1
                    res_sum+=nd.left.sum+((nd.value-1)>>self.id_size)
                    if nd.right:
                        nd=nd.right
                    else:
                        raise IndexError("BalancingTree doesn't hold kth number")
                elif nd.left.cnt==k:
                    res_sum+=nd.left.sum+((nd.value-1)>>self.id_size)
                    return res_sum
                else:
                    nd=nd.left
            else:
                if k==0:
                    return res_sum+((nd.value-1)>>self.id_size)
                if nd.right:
                    k-=1
                    res_sum+=((nd.value-1)>>self.id_size)
                    nd=nd.right
                else:
                    print(cnt,self.size,nd.value-1,nd.right)
                    self.debug()
                    raise IndexError("BalancingTree doesn't hold kth number")

    def kth_sum_big(self,k):
        res_sum=self.sum
        if self.size>k:
            res_sum-=self.kth_sum(self.size-k-2)
            return res_sum
        else:
            raise IndexError("BalancingTree doesn't hold kth number")

    def leftmost(self, nd):
        while nd.left:
            nd=nd.left
        return nd

    def rightmost(self, nd):
        while nd.right:
            nd=nd.right
        return nd

    def find_l(self, v):
        v += 1
        nd = self.root
        prev = 0
        if nd.value < v: prev = nd.value
        while True:
            if v <= nd.value:
                if nd.left:
                    nd = nd.left
                else:
                    return (prev - 1)>>self.id_size
            else:
                prev = nd.value
                if nd.right:
                    nd = nd.right
                else:
                    return (prev - 1)>>self.id_size

    def find_r(self, v):
        v += 1
        nd = self.root
        prev = 0
        if nd.value > v: prev = nd.value
        while True:
            if v < nd.value:
                prev = nd.value
                if nd.left:
                    nd = nd.left
                else:
                    return (prev - 1)>>self.id_size
            else:
                if nd.right:
                    nd = nd.right
                else:
                    return (prev - 1)>>self.id_size

    @property
    def max(self):
        if self.size:
            return self.find_l((1<<(self.N+self.id_size))-1)
        return 0

    @property
    def min(self):
        if self.size:
            return self.find_r(-1)
        return 0

    @property
    def sum(self):
        return self.root.sum-((self.root.value-1)>>self.id_size)

    @property
    def size(self):
        return self.root.cnt-1

    def delete(self,v):
        id=self.val_dic[v]-1
        if id==-1:
            raise IndexError("You are an idiot")
        V=(v<<self.id_size)+id
        self._delete(V)
        self.val_dic[v]-=1

    def _delete(self, v, nd = None, prev = None):
        v += 1
        if not nd: nd = self.root
        if not prev: prev = nd
        while v != nd.value:
            prev = nd
            nd.cnt-=1
            nd.sum-=(v-1)>>self.id_size
            if v <= nd.value:
                if nd.left:
                    nd = nd.left
                else:
                    return
            else:
                if nd.right:
                    nd = nd.right
                else:
                    return
        nd.cnt-=1
        nd.sum-=(v-1)>>self.id_size
        if (not nd.left) and (not nd.right):
            if not prev.left:
                prev.right=None
            elif not prev.right:
                prev.left=None
            else:
                if nd.pivot==prev.left.pivot:
                    prev.left=None
                else:
                    prev.right=None
        elif nd.right:
            nd.value = self.leftmost(nd.right).value
            self._delete(nd.value - 1, nd.right, nd)
        else:
            nd.value = self.rightmost(nd.left).value
            self._delete(nd.value - 1, nd.left, nd)


    def __contains__(self, v: int) -> bool:
        return self.find_r(v - 1) == v

    def __len__(self):
        return self.size

    class node:
        def __init__(self, v, p, m):
            self.value = v
            self.pivot = p
            self.left = None
            self.right = None
            self.cnt=1
            self.sum=(v-1)>>m

import sys

input=sys.stdin.readline

A=BalancingTree(31)
B=0
S=0

for _ in range(int(input())):
    q=list(map(int,input().split()))
    if q[0]==1:
        a,b=q[1:]
        A.append(a+10**9)
        B+=b
        S+=a
    else:
        n=A.size
        mid=A.kth((n+1)//2-1)-10**9
        smallsum=A.kth_sum((n+1)//2-1)
        smallsum-=((n+1)//2)*10**9
        print(mid,S-2*smallsum+B+(n%2)*mid)

Solution (Python):
import heapq
Q = int(input())

A_left, A_right = [], []
A_left_sum, A_right_sum = 0, 0
heapq.heapify(A_left)
heapq.heapify(A_right)

B_sum = 0
for _ in range(Q):
    query = list(map(int,input().split()))

    if query[0] == 1:
        now = query[1]
        B_sum += query[2]

        l, r = len(A_left), len(A_right)
        
        if l <= r:
            heapq.heappush(A_right, now)
            A_right_sum += now

            out = heapq.heappop(A_right)
            A_right_sum -= out

            heapq.heappush(A_left, -out)
            A_left_sum += out
        else:
            heapq.heappush(A_left, -now)
            A_left_sum += now

            out = -heapq.heappop(A_left)
            A_left_sum -= out

            heapq.heappush(A_right, out)
            A_right_sum += out
        
    else:
        m = -A_left[0]
        
        
        
        
        ans = len(A_left) * m - A_left_sum - len(A_right) * m + A_right_sum + B_sum
        print(m, ans)

Solution (Python):
import heapq

q = int(input())
big, small = [], []
heapq.heapify(big)
heapq.heapify(small)
sumb = 0
sumdist = 0
i = 0
for _ in range(q):
    query = list(map(int, input().split()))
    if query[0] == 1:
        i += 1
        a, b = query[1], query[2]
        sumb += b
        if i % 2 == 1:
            if i == 1:
                median = a
            else:
                if big[0] <= a:
                    median = heapq.heappushpop(big, a)
                    sumdist += abs(a - median)
                elif a <= -small[0]:
                    median = -heapq.heappushpop(small, -a)
                    sumdist += abs(a - median)
                else:
                    median = a
        else:
            sumdist += abs(a - median)
            heapq.heappush(big, max(a, median))
            heapq.heappush(small, -min(a, median))
            median = -small[0]
    else:
        print(median, sumdist + sumb)

Solution (Python):
import heapq
Q = int(input())



left, right = [], []

Lsum, Rsum = 0,0
Lcnt, Rcnt = 0,0
B = 0
for _ in range(Q):
  q = list(map(int, input().split()))
  if len(q) == 1:
    
    
    l = (-1) *left[0]
    
    
    
    print(l, Rsum//2 - Lsum//2 + B)
    
  else:
    
    _,a,b = q
    B += b
    
    heapq.heappush(left,(-1)*a)
    heapq.heappush(right,a)
    Lsum += a
    Lcnt += 1
    Rsum += a
    Rcnt += 1
    
    l = (-1)*left[0]
    r = right[0]
    
    
    if l>=r:
      Lsum = Lsum - l + r
      Rsum = Rsum - r + l
      l,r = r,l
    _ = heapq.heappop(left)
    _ = heapq.heappop(right)
    heapq.heappush(left,(-1)*l)
    heapq.heappush(right,r)

Solution (Python):
import heapq
Q = int(input())



left, right = [], []

Lsum, Rsum = 0,0
Lcnt, Rcnt = 0,0
B = 0
for _ in range(Q):
  q = list(map(int, input().split()))
  if len(q) == 1:
    
    
    l = (-1) *left[0]
    
    
    
    print(l, Rsum//2 - Lsum//2 + B)
    
  else:
    
    _,a,b = q
    B += b
    
    heapq.heappush(left,(-1)*a)
    heapq.heappush(right,a)
    Lsum += a
    Lcnt += 1
    Rsum += a
    Rcnt += 1
    
    l = (-1)*left[0]
    r = right[0]
    
    
    if l>=r:
      Lsum = Lsum - l + r
      Rsum = Rsum - r + l
      l,r = r,l
    _ = heapq.heappop(left)
    _ = heapq.heappop(right)
    heapq.heappush(left,(-1)*l)
    heapq.heappush(right,r)

Solution (Python):
import heapq
Q = int(input())



left, right = [], []

Lsum, Rsum = 0,0
Lcnt, Rcnt = 0,0
B = 0
for _ in range(Q):
  q = list(map(int, input().split()))
  if len(q) == 1:
    
    
    l = (-1) * heapq.heappop(left)
    heapq.heappush(left,(-1)*l)
    
    print(l, Rsum//2 - Lsum//2 + B)
    
  else:
    
    _,a,b = q
    B += b
    
    heapq.heappush(left,(-1)*a)
    heapq.heappush(right,a)
    Lsum += a
    Lcnt += 1
    Rsum += a
    Rcnt += 1
    
    l = (-1) * heapq.heappop(left)
    r = heapq.heappop(right)
    if l>=r:
      Lsum = Lsum - l + r
      Rsum = Rsum - r + l
      l,r = r,l
    heapq.heappush(left,(-1)*l)
    heapq.heappush(right,r)

Solution (Python):
import heapq
Q = int(input())



left, right = [], []

Lsum, Rsum = 0,0
Lcnt, Rcnt = 0,0
B = 0
for _ in range(Q):
  q = list(map(int, input().split()))
  if len(q) == 1:
    
    
    l = (-1) * heapq.heappop(left)
    heapq.heappush(left,(-1)*l)
    
    print(l, Rsum//2 - Lsum//2 + B)
    
  else:
    
    _,a,b = q
    B += b
    
    heapq.heappush(left,(-1)*a)
    heapq.heappush(right,a)
    Lsum += a
    Lcnt += 1
    Rsum += a
    Rcnt += 1
    
    l = (-1) * heapq.heappop(left)
    r = heapq.heappop(right)
    if l>=r:
      Lsum = Lsum - l + r
      Rsum = Rsum - r + l
      l,r = r,l
    heapq.heappush(left,(-1)*l)
    heapq.heappush(right,r)

Solution (Python):
import heapq
Q = int(input())

A_left, A_right = [], []
A_left_sum, A_right_sum = 0, 0
heapq.heapify(A_left)
heapq.heapify(A_right)

B_sum = 0
for _ in range(Q):
    query = list(map(int,input().split()))

    if query[0] == 1:
        now = query[1]
        B_sum += query[2]

        l, r = len(A_left), len(A_right)
        if l <= r:
            heapq.heappush(A_right, now)
            A_right_sum += now

            out = heapq.heappop(A_right)
            A_right_sum -= out

            heapq.heappush(A_left, -out)
            A_left_sum += out
        else:
            heapq.heappush(A_left, -now)
            A_left_sum += now

            out = -heapq.heappop(A_left)
            A_left_sum -= out

            heapq.heappush(A_right, out)
            A_right_sum += out
    else:
        m = -A_left[0]
        ans = len(A_left) * m - A_left_sum - len(A_right) * m + A_right_sum + B_sum
        print("{0} {1}".format(m,ans))

Solution (Python):
class SegTree():
    def segfunc(self, x, y):
        return x+y

    def __init__(self, ide, n, init_val):
        self.ide_ele = ide
        self.num = 2**(n-1).bit_length()
        self.seg = [self.ide_ele] * 2 * self.num
        for i in range(n):
            self.seg[i+self.num-1] = init_val[i]    
        for i in range(self.num-2,-1,-1):
            self.seg[i] = self.segfunc(self.seg[2*i+1],self.seg[2*i+2]) 
    def update(self, k, x):
        k += self.num-1
        self.seg[k] = x
        while k:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[k*2+1], self.seg[k*2+2])
    def query(self, p, q):
        if q<=p:
            return self.ide_ele
        p += self.num-1
        q += self.num-2
        res = self.ide_ele
        while q-p>1:
            if p&1 == 0:
                res = self.segfunc(res, self.seg[p])
            if q&1 == 1:
                res = self.segfunc(res, self.seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = self.segfunc(res, self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
        return res

def main():
    q = int(input())
    ans = []
    query = [list(map(int, input().split())) for _ in range(q)]
    a_arr = []
    for arr in query:
        if arr[0] == 1:
            a_arr.append(arr[1])
    a_arr.sort()
    dic = {}
    rev_dic = {}
    p = 0
    for v in a_arr:
        if not v in dic:
            dic[v] = p
            rev_dic[p] = v
            p += 1
    seg_arr = [0]*p
    seg = SegTree(0, p, seg_arr)
    b_sum = 0
    cnt = 0
    add = 0
    f = False
    range_L, range_R = -1, -1
    for arr in query:
        if arr[0] == 1:
            x = dic[arr[1]]
            b_sum += arr[2]
            seg_arr[x] += 2
            seg.update(x, seg_arr[x])
            cnt += 1
            if f:
                if range_L <= x <= range_R:
                    add += 0
                elif x < range_L:
                    add += rev_dic[range_L] - arr[1]
                else:
                    add += arr[1] - rev_dic[range_R]
        L, R = -1, p-1
        while L+1 < R:
            P = (L+R+1)//2
            if seg.query(0, P+1)-cnt >= 0:
                R = P
            else:
                L = P
        range_L = R
        L, R = 0, p
        while L+1 < R:
            P = (L+R)//2
            if seg.query(P, p)-cnt >= 0:
                L = P
            else:
                R = P
        range_R = L
        f = True
        if arr[0] == 2:
            ans.append([rev_dic[range_L], b_sum + add])
    for a, b in ans:
        print(a, b)

if __name__ == "__main__":
    main()

Solution (Python):
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  

Q = I()

from heapq import heapify,heappop,heappush

s,t = 0,0  
left,right = [],[]  
heapify(left)
heapify(right)
l,r = 0,0  
for i in range(Q):
    A = LI()
    if A[0] == 2:
        if l == r:
            x = -heappop(left)
            heappush(left,-x)
        else:
            x = heappop(right)
            heappush(right,x)
        print(*[x,s+t])
    else:
        c,a,b = A
        t += b
        if l == r:
            if l == 0:
                heappush(right,a)
            else:
                x = -heappop(left)
                y = heappop(right)
                if a >= x:
                    heappush(left,-x)
                    heappush(right,y)
                    heappush(right,a)
                    if a >= y:
                        s += a-y
                else:
                    heappush(left,-a)
                    heappush(right,x)
                    heappush(right,y)
                    s += x-a
            r += 1
        else:
            if l == 0:
                y = heappop(right)
                s += abs(y-a)
                if a < y:
                    heappush(left,-a)
                    heappush(right,y)
                else:
                    heappush(left,-y)
                    heappush(right,a)
            else:
                x = -heappop(left)
                y = heappop(right)
                s += abs(y-a)
                if a < y:
                    heappush(left,-x)
                    heappush(left,-a)
                    heappush(right,y)
                else:
                    heappush(left,-x)
                    heappush(left,-y)
                    heappush(right,a)
            l += 1

Solution (Python):
from heapq import heappop, heappush

n = int(input())
_, a, b = map(int, input().split())
l = []
r = []
med_val = a
sum_l = 0
sum_r = 0
sum_b = b

for _ in range(n-1):
    query = input().split()
    if query[0] == '1':
        _, a, b = map(int, query)
        if len(l) < len(r):
            if a <= med_val:
                heappush(l, -a)
                sum_l += a
            else:
                heappush(l, -med_val)
                sum_l += med_val
                heappush(r, a)
                sum_r += a
                med_val = heappop(r)
                sum_r -= med_val
        else:
            if med_val < a:
                heappush(r, a)
                sum_r += a
            else:
                heappush(r, med_val)
                sum_r += med_val
                heappush(l, -a)
                sum_l += a
                med_val = -heappop(l)
                sum_l -= med_val
        sum_b += b
    else:
        f = len(l) * med_val - sum_l + sum_r - len(r) * med_val + sum_b
        print("{} {}".format(med_val, f))

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

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


"""
前回の最小区間を覚えておいて，差分で最小値を更新する
"""

def main():

    
    from bisect import bisect_left, bisect_right, insort_right
    class SquareSkipList:
        
        

        def __init__(self, values=None, sorted_=False, square=1000, seed=42):
            
            
            
            
            

            self.cnt=0
            inf = float("inf")
            self.square = square
            if values is None:
                self.rand_y = seed
                self.layer1 = [inf]
                self.layer0 = [[]]
            else:
                self.layer1 = layer1 = []
                self.layer0 = layer0 = []
                if not sorted_:
                    values.sort()
                y = seed
                l0 = []
                for v in values:
                    y ^= (y & 0x7ffff) << 13
                    y ^= y >> 17
                    y ^= (y & 0x7ffffff) << 5
                    if y % square == 0:
                        layer0.append(l0)
                        l0 = []
                        layer1.append(v)
                    else:
                        l0.append(v)
                layer1.append(inf)
                layer0.append(l0)
                self.rand_y = y

        def add(self, x):  
            
            y = self.rand_y
            y ^= (y & 0x7ffff) << 13
            y ^= y >> 17
            y ^= (y & 0x7ffffff) << 5
            self.rand_y = y

            if y % self.square == 0:
                layer1, layer0 = self.layer1, self.layer0
                idx1 = bisect_right(layer1, x)
                layer1.insert(idx1, x)
                layer0_idx1 = layer0[idx1]
                idx0 = bisect_right(layer0_idx1, x)
                layer0.insert(idx1+1, layer0_idx1[idx0:])  
                del layer0_idx1[idx0:]
            else:
                idx1 = bisect_right(self.layer1, x)
                insort_right(self.layer0[idx1], x)

            self.cnt+=1

        def remove(self, x):  
            
            idx1 = bisect_left(self.layer1, x)
            layer0_idx1 = self.layer0[idx1]
            idx0 = bisect_left(layer0_idx1, x)
            if idx0 == len(layer0_idx1):
                del self.layer1[idx1]
                self.layer0[idx1] += self.layer0.pop(idx1+1)
            else:
                del layer0_idx1[idx0]

            self.cnt-=1

        def search_higher_equal(self, x):  
            idx1 = bisect_left(self.layer1, x)
            layer0_idx1 = self.layer0[idx1]
            idx0 = bisect_left(layer0_idx1, x)
            if idx0 == len(layer0_idx1):
                return self.layer1[idx1]
            return layer0_idx1[idx0]

        def search_higher(self, x):  
            idx1 = bisect_right(self.layer1, x)
            layer0_idx1 = self.layer0[idx1]
            idx0 = bisect_right(layer0_idx1, x)
            if idx0 == len(layer0_idx1):
                return self.layer1[idx1]
            return layer0_idx1[idx0]

        def search_lower(self, x):  
            
            idx1 = bisect_left(self.layer1, x)
            layer0_idx1 = self.layer0[idx1]
            idx0 = bisect_left(layer0_idx1, x)
            if idx0 == 0:  
                return self.layer1[idx1-1]
            return layer0_idx1[idx0-1]

        def pop(self, idx):
            
            
            
            self.cnt-=1
            layer0 = self.layer0
            s = -1
            for i, l0 in enumerate(layer0):
                s += len(l0) + 1
                if s >= idx:
                    break
            if s==idx:
                layer0[i] += layer0.pop(i+1)
                return self.layer1.pop(i)
            else:
                return layer0[i].pop(idx-s)


        def all(self):
            print(self.layer1)
            print(self.layer0)

        def len(self):
            return self.cnt

    


    
    inf=10**9+1
    Q=I()
    ssl1 = SquareSkipList(square=2000)
    ssl1.add(-inf)
    ssl2 = SquareSkipList(square=2000)
    ssl2.add(inf)
    
    s1=0
    s2=0
    
    q,a,b=MI()
    mx=a
    m=b
    
    
    for _ in range(Q-1):
        q=LI()
        if q[0]==1:
            a=q[1]
            m+=q[2]
            aa=ssl1.search_lower(inf+1)
            bb=ssl2.search_higher(-inf-1)
            
            
            
            if a<aa:
                ssl1.add(a)
                s1+=a
            elif a>bb:
                ssl2.add(a)
                s2+=a
            else:
                
                if a>mx:
                    a,mx=mx,a
                
                
                ssl2.add(mx)
                s2+=mx
                bb=mx
                mx=a
            l1=ssl1.len()
            l2=ssl2.len()

            
            if l1>l2:
                ssl2.add(mx)
                s2+=mx
                ssl1.remove(aa)
                s1-=aa
                mx=aa      
            elif l2-l1>=2:
                ssl1.add(mx)
                s1+=mx
                ssl2.remove(bb)
                s2-=bb
                mx=bb

        else:
            temp=m
            l1=ssl1.len() -1
            l2=ssl2.len() -1
            temp+=l1*mx-s1
            temp+=s2-l2*mx
            print(mx,temp)
                    
                
            
            
            
            
        
        
    

main()

Solution (Python):
import sys
import heapq
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
inf = 10**18
L = [-(-inf)]
R = [inf]
Lsum = 0
Rsum = 0
const = 0


"""
[], []
[x], []
[x], [y]
[x, z], [y]
...
"""

xmed = None

for _ in range(N):
    f, *arg = map(int, input().split())
    if f == 1:
        a, b = arg
        const += b
        if xmed is None:
            xmed = a
            while -L[0] > xmed or xmed > R[0]:
                while xmed < -L[0]:
                    Lsum += xmed
                    xmed = -heapq.heappushpop(L, -xmed)
                    Lsum -= xmed
                while xmed > R[0]:
                    Rsum += xmed
                    xmed = heapq.heappushpop(R, xmed)
                    Rsum -= xmed
        else:
            if a < xmed:
                a, xmed = xmed, a
            heapq.heappush(L, -xmed)
            heapq.heappush(R, a)
            Lsum += xmed
            Rsum += a
            xmed = None
            while -L[0] > R[0]:
                lx = -heapq.heappop(L)
                rx = heapq.heappop(R)
                heapq.heappush(L, -rx)
                heapq.heappush(R, lx)
                Lsum += rx - lx
                Rsum += lx - rx
    else:
        if xmed is None:
            xres = -L[0]
        else:
            xres = xmed
        F = const
        F += Rsum - xres * (len(R) - 1)
        F += xres * (len(L) - 1) - Lsum
        print(xres, F)

Solution (Python):
import heapq
import collections

cnt=1
cnts=collections.defaultdict(int)
median=0
left_cnt=0
right_cnt=0
left_sum=0
right_sum=0
left_pos=[]
right_pos=[]
b=0
q=int(input())
initial=list(map(int,input().split()))
median=initial[1]
b+=initial[2]
cnts[median]=1
for _ in range(q-1):
  query=list(map(int,input().split()))
  if query[0]==1:
    cnt+=1
    b+=query[2]
    if query[1]==median:
      cnts[median]+=1
    elif query[1]<median:
      left_cnt+=1
      left_sum+=query[1]
      cnts[query[1]]+=1
      if cnts[query[1]]==1:
        heapq.heappush(left_pos,-query[1])
    elif query[1]>median:
      right_cnt+=1
      right_sum+=query[1]
      cnts[query[1]]+=1
      if cnts[query[1]]==1:
        heapq.heappush(right_pos,query[1])
    if left_cnt+1<=(cnt+1)//2<=left_cnt+cnts[median]:
      continue
    elif left_cnt+1>(cnt+1)//2:
      heapq.heappush(right_pos,median)
      right_cnt+=cnts[median]
      right_sum+=median*cnts[median]
      median=-heapq.heappop(left_pos)
      left_cnt-=cnts[median]
      left_sum-=median*cnts[median]
    elif (cnt+1)//2>left_cnt+cnts[median]:
      heapq.heappush(left_pos,-median)
      left_cnt+=cnts[median]
      left_sum+=median*cnts[median]
      median=heapq.heappop(right_pos)
      right_cnt-=cnts[median]
      right_sum-=median*cnts[median]
  elif query[0]==2:
    value=b
    if left_cnt!=0:
      value+=abs(left_sum-median*left_cnt)
    if right_cnt!=0:
      value+=abs(right_sum-median*right_cnt)
    print(median,value)

Solution (Python):
import heapq


def main():
    Q = int(input())
    query_list = [list(map(int, input().split(' '))) for _ in range(Q)]
    
    que_left, que_right = [], []  
    
    sum_a_cost = 0
    sum_b = 0
    for query in query_list:
        if query[0] == 1:
            a, b = query[1], query[2]
            
            if len(que_right) - len(que_left) == 1:
                sum_a_cost += abs(a - que_right[0])
            elif 0 < len(que_left) == len(que_right):
                if a > que_right[0]:
                    sum_a_cost += a - que_right[0]
                elif a < - que_left[0]:
                    sum_a_cost += - que_left[0] - a
            sum_b += b
            
            if len(que_right) == 0 or a >= que_right[0]:
                heapq.heappush(que_right, a)
            else:
                
                heapq.heappush(que_left, - a)
            
            if len(que_right) - len(que_left) == - 1:
                heapq.heappush(que_right, - heapq.heappop(que_left))
            elif len(que_right) - len(que_left) == 2:
                heapq.heappush(que_left, - heapq.heappop(que_right))
        else:
            x = que_right[0] if len(que_right) - len(que_left) == 1 else (- que_left[0])
            f = sum_a_cost + sum_b
            print('{} {}'.format(x, f))


if __name__ == '__main__':
    main()