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



Sample input:
4
1 4 2
2
1 1 -8
2


Sample output:
4 2
1 -3

Submission status: Wrong Answer

Solution code:
def examA():
    N = I()
    ans = 0
    print(ans)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    # 0は絶対に入れない!!
    class Bit():
        def __init__(self, n):
            self.size = n
            self.tree = [0] * (n + 1)
            return

        def sum(self, i):
            i += 1
            s = 0
            while i > 0:
                s += self.tree[i]
                i -= i & -i
            return s

        def add(self, i, x=1):
            # i==0 はだめ => 全部+1するとか
            i += 1
            while i <= self.size:
                self.tree[i] += x
                i += i & -i
            return

        def search(self, x):
            # 二分探索。和がx以上となる最小のインデックス(>= 1)を返す
            # maspyさんの参考　よくわかってない
            i = 0
            s = 0
            step = 1 << ((self.size).bit_length() - 1)
            while step:
                if i + step <= self.size and s + self.tree[i + step] < x:
                    i += step
                    s += self.tree[i]
                step >>= 1
            return i

        def debug(self, k):
            return [self.sum(i) for i in range(k)]
    def compress(list1):
        list2 = sorted(set(list1))
        memo = {value: index for index, value in enumerate(list2)}
        for i in range(len(list1)):
            list1[i] = memo[list1[i]]
        return memo, len(list2)
    n = I()
    Q = [LI()for _ in range(n)]
    A = []
    for q in Q:
        if q[0]==2:
            continue
        a, b = q[1:]
        A.append(a)
    memo,N = compress(A)
    #print(memo)
    #print(N)
    bit = Bit(N+1)
    bit_a = Bit(N+1)
    location = defaultdict(int)
    num = 0
    B = 0
    ans = [[]for _ in range(N)]
    for q in Q:
        if q[0]==2:
            x = bit.search((num+1)//2)
            #print(x)
            rep = location[x]*((num+1)//2)-bit_a.sum(x)+B
            if num%2==0:
                rep += (location[x+1]-location[x])
            ans.append((location[x],rep))
            continue
        a, b = q[1:]
        B += b
        bit.add(memo[a])
        bit_a.add(memo[a],a)
        location[memo[a]] = a
        num += 1

    for v in ans:
        print(" ".join(map(str,v)))
    return

def test():
    i = I()
    li = LI()
    lsi = LSI()
    si = LS()
    print(i)
    print(li)
    print(lsi)
    print(si)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(readline())
def LI(): return list(map(int,readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examF()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Submission status: Wrong Answer

Solution code:
def examA():
    N = I()
    ans = 0
    print(ans)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    # 0は絶対に入れない!!
    class Bit():
        def __init__(self, n):
            self.size = n
            self.tree = [0] * (n + 1)
            return

        def sum(self, i):
            i += 1
            s = 0
            while i > 0:
                s += self.tree[i]
                i -= i & -i
            return s

        def add(self, i, x=1):
            # i==0 はだめ => 全部+1するとか
            i += 1
            while i <= self.size:
                self.tree[i] += x
                i += i & -i
            return

        def search(self, x):
            # 二分探索。和がx以上となる最小のインデックス(>= 1)を返す
            # maspyさんの参考　よくわかってない
            i = 0
            s = 0
            step = 1 << ((self.size).bit_length() - 1)
            while step:
                if i + step <= self.size and s + self.tree[i + step] < x:
                    i += step
                    s += self.tree[i]
                step >>= 1
            return i

        def debug(self, k):
            return [self.sum(i) for i in range(k)]
    def compress(list1):
        list2 = sorted(set(list1))
        memo = {value: index for index, value in enumerate(list2)}
        for i in range(len(list1)):
            list1[i] = memo[list1[i]]
        return memo, len(list2)
    n = I()
    Q = [LI()for _ in range(n)]
    A = []
    for q in Q:
        if q[0]==2:
            continue
        a, b = q[1:]
        A.append(a)
    memo,N = compress(A)
    #print(memo)
    #print(N)
    bit = Bit(N+1)
    location = defaultdict(int)
    num = 0
    B = 0
    ans = [[]for _ in range(N)]
    for q in Q:
        if q[0]==2:
            x = bit.search((num+1)//2)
            #print(x)
            if num%2==1:
                ans.append((location[x],B))
            else:
                ans.append((location[x],B+(location[x+1]-location[x])))
            continue
        a, b = q[1:]
        B += b
        bit.add(memo[a])
        location[memo[a]] = a
        num += 1

    for v in ans:
        print(" ".join(map(str,v)))
    return

def test():
    i = I()
    li = LI()
    lsi = LSI()
    si = LS()
    print(i)
    print(li)
    print(lsi)
    print(si)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(readline())
def LI(): return list(map(int,readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examF()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.buffer.readline
q=int(input())
from heapq import heapify, heappop, heappush
L=[]
R=[]
s=0
ans=0
l,r=-10**10,10**10
for i in range(q):
    j=tuple(map(int ,input().split()))
    if j[0]==1:
        x,y=j[1],j[2]
        s+=1
        ans+=y
        if not(l<=x<=r):ans+=abs(l-x)
        if s==1:
            heappush(L,-x)
            l,r=x,x
        elif s%2:
            if -L[0]>=x:
                heappush(L,-x)
                l,r=-L[0],-L[0]
            else:
                heappush(R,x)
                l=heappop(R)
                r=l
                heappush(L,-l)
        else:
            if -L[0]<=x:
                heappush(R,x)
            else:
                heappush(L,-x)
                heappush(R,-heappop(L))    
            l,r=-L[0],R[0]

    else:print(l,ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

from heapq import heapify,heappop,heappush
def main():
    Q = int(input())
    total_b = 0
    total_a = 0
    less_than_middle = 0
    left = []
    right = []
    cnt = 0
    for _ in range(Q):
        query = tuple(map(int,input().split()))
        if query[0] == 1:
            a,b = query[1:]
            total_b += b
            total_a += a
            cnt += 1
            heappush(right,a)
            if len(left) < cnt//2:
                x = heappop(right)
                less_than_middle += x
                heappush(left,-x)
        else:
            if cnt%2 == 0:
                x = -left[0]
                ans = total_a - 2*less_than_middle + total_b
                print(x,ans)
            else:
                x = right[0]
                ans = total_a - 2*less_than_middle - x + total_b
                print(x,ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()

from heapq import heappush, heappop

q = int(input())
left = []
right = []
bias = 0
sum_left = 0
sum_right = 0

for _ in range(q):
    query = input().split()
    if len(query) == 3:
        n, a, b = [int(x) for x in query]
        bias += b
        if not right:
            if not left:
                heappush(left, -a)
                sum_left += a
            else:
                l = -heappop(left)
                if l > a:
                    heappush(left, -a)
                    heappush(right, l)
                    sum_right += l
                    sum_left += (a - l)
                else:
                    heappush(left, -l)
                    heappush(right, a)
                    sum_right += a
            continue
        l, r = -heappop(left), heappop(right)
        if len(left) == len(right):
            if a > r:
                heappush(right, a)
                heappush(left, -l)
                heappush(left, -r)
                sum_left += r
                sum_right += (a - r)
            else:
                heappush(left, -l)
                heappush(left, -a)
                heappush(right, r)
                sum_left += a
        else:
            if a < l:
                heappush(right, r)
                heappush(right, l)
                heappush(left, -a)
                sum_left += (a - l)
                sum_right += l
            else:
                heappush(right, r)
                heappush(right, a)
                heappush(left, -l)
                sum_right += a
    else:
        median = -heappop(left)
        print(median, sum_left + sum_right + (-len(right) + len(left) - 1)*(median) + bias)
        heappush(left, -median)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()

from heapq import heappush, heappop

q = int(input())
left = []
right = []
bias = 0
sum_left = 0
sum_right = 0

for _ in range(q):
    query = input().split()
    if len(query) == 3:
        n, a, b = [int(x) for x in query]
        bias += b
        if not right:
            if not left:
                heappush(left, -a)
                sum_left += a
            else:
                l = -heappop(left)
                if l > a:
                    heappush(left, -a)
                    heappush(right, l)
                    sum_right += l
                    sum_left += (a - l)
                else:
                    heappush(left, -l)
                    heappush(right, a)
                    sum_right += a
            continue
        l, r = -heappop(left), heappop(right)
        if len(left) == len(right):
            if a > r:
                heappush(right, a)
                heappush(left, -l)
                heappush(left, -r)
                sum_left += r
                sum_right += (a - r)
            else:
                heappush(left, -l)
                heappush(left, -a)
                heappush(right, r)
                sum_left += a
        else:
            if a < l:
                heappush(right, r)
                heappush(right, l)
                heappush(left, -a)
                sum_left += (a - l)
                sum_right += l
            else:
                heappush(right, r)
                heappush(right, a)
                heappush(left, -l)
                sum_right += a
    else:
        median = -heappop(left)
        print(median, sum_left + sum_right - (-len(right) + len(left))*(median) + bias)
        heappush(left, -median)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()

from heapq import heappush, heappop

q = int(input())
left = []
right = []
bias = 0
sum_left = 0
sum_right = 0

for _ in range(q):
    query = input().split()
    if len(query) == 3:
        n, a, b = [int(x) for x in query]
        bias += b
        if not right:
            if not left:
                heappush(left, -a)
                sum_left += a
            else:
                l = -heappop(left)
                if l > a:
                    heappush(left, -a)
                    heappush(right, l)
                    sum_right += l
                    sum_left += (a - l)
                else:
                    heappush(left, -l)
                    heappush(right, a)
                    sum_right += a
            continue
        l, r = -heappop(left), heappop(right)
        if len(left) == len(right):
            if a > r:
                heappush(right, a)
                heappush(left, -l)
                heappush(left, -r)
                sum_left += r
                sum_right += (a - r)
            else:
                heappush(left, -l)
                heappush(left, -a)
                heappush(right, r)
                sum_left += a
        else:
            if a < l:
                heappush(right, r)
                heappush(right, l)
                heappush(left, -a)
                sum_left += (a - l)
                sum_right += l
            else:
                heappush(right, r)
                heappush(right, a)
                heappush(left, -l)
                sum_right += a
    else:
        median = -heappop(left)
        print(median, sum_left + sum_right - (len(right) - len(left))*(median) + bias)
        heappush(left, -median)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()

from heapq import heappush, heappop

q = int(input())
left = []
right = []
bias = 0
sum_left = 0
sum_right = 0
cnt = 0

for _ in range(q):
    query = input().split()
    if len(query) == 3:
        n, a, b = [int(x) for x in query]
        bias += b
        cnt += 1
        if not right:
            if not left:
                heappush(left, -a)
                sum_left += a
            else:
                l = -heappop(left)
                if l > a:
                    heappush(left, -a)
                    heappush(right, l)
                    sum_right += l
                    sum_left += (a - l)
                else:
                    heappush(left, -l)
                    heappush(right, a)
                    sum_right += a
            continue
        l, r = -heappop(left), heappop(right)
        if len(left) == len(right):
            if a > r:
                heappush(right, a)
                heappush(left, -l)
                heappush(left, -r)
                sum_left += r
                sum_right += (a - r)
            else:
                heappush(left, -l)
                heappush(left, -a)
                heappush(right, r)
                sum_left += a
        else:
            if a < l:
                heappush(right, r)
                heappush(right, l)
                heappush(left, -a)
                sum_left += (a - l)
                sum_right += l
            else:
                heappush(right, r)
                heappush(right, a)
                heappush(left, -l)
                sum_right += a
    else:
        median = -heappop(left)
        print(median, sum_left + sum_right - cnt*(median) + bias)
        heappush(left, -median)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()

from heapq import heappush, heappop

q = int(input())
left = []
right = []
bias = 0
sum_left = 0
sum_right = 0
cnt = 0

for _ in range(q):
    query = input().split()
    if len(query) == 3:
        n, a, b = [int(x) for x in query]
        bias += b
        cnt += 1
        if not right:
            if not left:
                heappush(left, -a)
                sum_left += a
            else:
                heappush(right, a)
                sum_right += a
            continue
        l, r = -heappop(left), heappop(right)
        if len(left) == len(right):
            if a > r:
                heappush(right, a)
                heappush(left, -l)
                heappush(left, -r)
                sum_left += r
                sum_right += (a - r)
            else:
                heappush(left, -l)
                heappush(left, -a)
                heappush(right, r)
                sum_left += a
        else:
            if a < l:
                heappush(right, r)
                heappush(right, l)
                heappush(left, -a)
                sum_left += (a - l)
                sum_right += l
            else:
                heappush(right, r)
                heappush(right, a)
                heappush(left, -l)
                sum_right += a
    else:
        median = -heappop(left)
        print(median, sum_left + sum_right - cnt*(median) + bias)
        heappush(left, -median)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()

from heapq import heappush, heappop

q = int(input())
left = [10**10]
right = [10**10]
bias = 0
sum_left = 0
sum_right = 0
cnt = 0

for _ in range(q):
    query = input().split()
    if len(query) == 3:
        n, a, b = [int(x) for x in query]
        bias += b
        cnt += 1
        l, r = -heappop(left), heappop(right)
        if len(left) == len(right):
            if a > r:
                heappush(right, a)
                heappush(left, -l)
                heappush(left, -r)
                sum_left += r
                sum_right += (a - r)
            else:
                heappush(left, -l)
                heappush(left, -a)
                heappush(right, r)
                sum_left += a
        else:
            if a < l:
                heappush(right, r)
                heappush(right, l)
                heappush(left, -a)
                sum_left += (a - l)
                sum_right += l
            else:
                heappush(right, r)
                heappush(right, a)
                heappush(left, -l)
                sum_right += a
    else:
        median = -heappop(left)
        print(median, sum_left + sum_right - cnt*(median) + bias)
        heappush(left, -median)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()

from heapq import heappush, heappop

q = int(input())
left = [10**10]
right = [10**10]
bias = 0
sum_left = 0
sum_right = 0
cnt = 0

for _ in range(q):
    query = input().split()
    if len(query) == 3:
        n, a, b = [int(x) for x in query]
        bias += b
        cnt += 1
        l, r = -heappop(left), heappop(right)
        if len(left) == len(right):
            if a > r:
                heappush(right, a)
                heappush(left, -l)
                heappush(left, -r)
                sum_left += r
                sum_right += (a - r)
            else:
                heappush(left, -l)
                heappush(left, -a)
                heappush(right, r)
                sum_left += a
        else:
            if a < l:
                heappush(right, r)
                heappush(right, l)
                heappush(left, -a)
                sum_left += (a - l)
                sum_right += l
            else:
                heappush(right, r)
                heappush(right, a)
                heappush(left, -l)
                sum_right += a
    else:
        median = -heappop(left)
        print(median, sum_left + sum_right + cnt*(median) + bias)
        heappush(left, -median)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()

from heapq import heappush, heappop

q = int(input())
left = [10**10]
right = [10**10]
bias = 0
sum_left = 0
sum_right = 0
cnt = 0

for _ in range(q):
    query = input().split()
    if len(query) == 3:
        n, a, b = [int(x) for x in query]
        bias += b
        cnt += 1
        l, r = -heappop(left), heappop(right)
        if len(left) == len(right):
            if a > r:
                heappush(right, a)
                heappush(left, -l)
                heappush(left, -r)
                sum_left += r
                sum_right += (a - r)
            else:
                heappush(left, -l)
                heappush(left, -a)
                heappush(right, r)
                sum_left += a
        else:
            if a < l:
                heappush(right, r)
                heappush(right, l)
                heappush(left, -a)
                sum_left += (a - l)
                sum_right += l
            else:
                heappush(right, r)
                heappush(right, a)
                heappush(left, -l)
                sum_right += a
    else:
        print(-left[0], sum_left + sum_right + cnt*(left[0]) + bias)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()

import heapq

q = int(input())
left = []
right = []
bias = 0
total = 0
cnt = 0 

for _ in range(q):
    query = input().split()
    if len(query) == 3:
        n, a, b = [int(x) for x in query]
        bias += b
        heapq.heappush(left, a)
        heapq.heappush(right, -a)
        cnt += 1
        total += a
    else:
        if cnt % 2 == 0:
            print(left[cnt//2 - 1], total - left[cnt//2 - 1]*cnt + bias)
        else:
            print(left[cnt//2], total - left[cnt//2]*cnt + bias)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()

q = int(input())
cnt = 0
total = 0
min_value = 10**10

for _ in range(q):
    query = input().split()
    if len(query) == 3:
        n, a, b = [int(x) for x in query]
        total += b
        if min_value <= a:
            total += a - min_value
        else:
            total += (min_value - a)*cnt
            min_value = a
        cnt += 1
    else:
        print(min_value, total)

Submission status: Wrong Answer

Solution code:
from heapq import heappush,heappop
def main():
    Q=int(input())

    ab_list=[]
    query_type=[]

    for i in range(Q):
        query=list(map(int,input().split()))
        query_type.append(query[0])
        if query[0]==1:
            ab_list.append((query[1],query[2]))

    #query_type->[1,1,2,1,2]
    #ab_list->[(a,b),(a,b),(a,b)]

    L=[]
    R=[]

    ini=0

    counter=0
    ab_pointer=0
    minF=0
    for i in query_type:
        if i==1:
            if counter==0:
                ini=ab_list[ab_pointer][0]
                counter+=1
                minF+=ab_list[ab_pointer][1]
            elif counter==1:
                L.append(-1*min(ini,ab_list[ab_pointer][0]))
                R.append(max(ini,ab_list[ab_pointer][0]))
                counter+=1
                delta=abs(-1*L[0]-R[0])
                minF+=delta+ab_list[ab_pointer][1]
            else:
                a_new=ab_list[ab_pointer][0]
                b_new=ab_list[ab_pointer][1]
                heappush(L,-1*a_new)
                heappush(R,a_new)
                Lmax=-1*heappop(L)
                Rmin=heappop(R)
                if Lmax<=Rmin:
                    heappush(L,-1*Lmax)
                    heappush(R,Rmin)
                else:
                    heappush(L,-1*Rmin)
                    heappush(R,Lmax)
                delta=abs(Lmax-Rmin)
                minF+=delta+b_new
            ab_pointer+=1
        else:
            if counter<=1:
                print(str(ini)+" "+str(minF))
            else:
                minX=-1*heappop(L)
                print(str(minX)+" "+str(minF))
                heappush(L,-1*minX)



if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

class BIT():
 
    def __init__(self, n):
        '''
        n = 要素数
        添字は i = 0 ~ n-1 となる
        '''
        self.n = n
        self.bit = [0] * (n + 1)
 
    def add(self, i, x):
        '''i番目の要素にxを加算する'''
        i = i + 1
        while i <= self.n:
            self.bit[i] += x
            i += i & -i
 
    def _sum(self, i):
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= i & -i
        return s
 
    def get(self, i, j):
        '''[i, j)の和を求める'''
        return self._sum(j) - self._sum(i)
  
def compress(list1):
    list2 = sorted(set(list1))
    memo = {value : index for index, value in enumerate(list2)}
    return memo, len(list2)

q = int(readline())
info = [list(map(int, input().split())) for i in range(q)]
 
#座圧する
li1 = []
for i in range(q):
    if info[i][0] == 1:
        li1.append(info[i][1])
        
memo, len_memo = compress(li1)

def median():
    ok = len_memo
    ng = 0
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if 2 * bit1.get(mid, len_memo) <= cnt :
            ok = mid
        else:
            ng = mid
    return memo_inv[ng]
  
#値を管理するBIT
bit = BIT(len_memo)
#要素数を管理するBIT
bit1 = BIT(len_memo)
memo_inv = dict([(v,k) for k,v in memo.items()])

s = 0
cnt = 0
for i in range(q):
  que = info[i]
  if que[0] == 1:
    a,b,c = que
    s += c
    cnt += 1
    bit.add(memo[b],b)
    bit1.add(memo[b],1)    
  else:
    d = median()
    sum1 = bit.get(0, memo[d])
    sum2 = bit.get(memo[d], len_memo)
    if cnt%2 == 1:
      print(d, -d-sum1+sum2+s)
    else:
      print(d, -2*d-sum1+sum2+s)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
from bisect import insort
q = int(readline())
ch = []
cnt = 0
s = 0
for i in range(q):
  que = list(map(int,readline().split()))
  if que[0] == 1:
    insort(ch,que[1])
    cnt += 1
    s += que[2]
  else:
    if cnt%2 == 1:
      if cnt == 1:
        print(ch[0],s)
      else:
        print(ch[cnt//2],-sum(ch[:cnt//2])+sum(ch[cnt//2+1:])+s)
    else:
      if cnt == 2:
        print(ch[0],ch[1]-ch[0]+s)
      else:
        print(ch[cnt//2-1],-sum(ch[:cnt//2-1])+sum(ch[cnt//2:])+s)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import heapq
import sys
# sys.setrecursionlimit(10**6)
buff_readline = sys.stdin.buffer.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def slv(Q):
    sb = 0

    l = []
    r = []
    sl = 0
    sr = 0

    for q in Q:
        if q[0] == 1:
            _, a, b = q
            heapq.heappush(l, -a)
            sl += a

            if len(l) > len(r) + 1:
                a = -heapq.heappop(l)
                heapq.heappush(r, a)
                sl -= a
                sr += a

            while l and r and -l[0] > r[0]:
                a = -heapq.heappop(l)
                heapq.heappush(r, a)
                sl -= a
                sr += a

                a = -heapq.heappop(r)
                heapq.heappush(l, a)
                sl += a
                sr -= a

            sb += b
        else:
            x = -l[0]
            print(x, abs(sl - len(l)*x) + abs(sr - len(r)*x) + sb)

def main():
    N = read_int()
    Q = [read_int_n() for _ in range(N)]
    slv(Q)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import heapq
import sys
# sys.setrecursionlimit(10**6)
buff_readline = sys.stdin.buffer.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def slv(Q):
    sb = 0

    l = []
    r = []
    spa = 0
    npa = 0
    sna = 0
    nna = 0

    n = 0
    for q in Q:
        if q[0] == 1:
            _, a, b = q
            if a > 0:
                spa += a
                npa += 1
            else:
                sna += a
                nna += 1
            heapq.heappush(l, -a)

            if len(l) > len(r) + 1:
                heapq.heappush(r, -heapq.heappop(l))

            while l and r and -l[0] > r[0]:
                heapq.heappush(r, -heapq.heappop(l))
                heapq.heappush(l, -heapq.heappop(r))

            sb += b
            n += 1
        else:
            x = -l[0]
            print(x, abs(spa - npa*x) + abs(sna - nna*x) + sb)

def main():
    N = read_int()
    Q = [read_int_n() for _ in range(N)]
    slv(Q)


if __name__ == '__main__':
    main()