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:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


from heapq import heappush, heappop

def update(item, fir, lat):
    if len(fir) == 0 and len(lat) == 0:
        fir.append(-item)

    elif len(fir) == len(lat):
        if item > -fir[0]:
            heappush(lat, item)
        else:
            heappush(fir, -item)

    elif len(fir) > len(lat):
        if item < -fir[0]:
            tmp = heappop(fir)
            heappush(fir, -item)
            heappush(lat, -tmp)
        else:
            heappush(lat, item)

    elif len(fir) < len(lat):
        if item > -fir[0]:
            tmp = heappop(lat)
            heappush(fir, -tmp)
            heappush(lat, item)
        else:
            heappush(fir, -item)


q = ni()

first = []
latter = []
ab = []

for _ in range(q):
    query = ns()
    if query[0:1] == '1':
        _, a, b = map(int, query.split())

        update(a, first, latter)
        ab.append((a,b))

    else:
        ans = 0
        for a,b in ab:
            ans += abs(-first[0] - a) + b

        print(-first[0], ans)

Submission status: Wrong Answer

Solution code:
import heapq
Q = int(input())
qs = [tuple(map(int,input().split())) for i in range(Q)]

lq = []
rq = []
heapq.heapify(lq)
heapq.heapify(rq)
ans = 0

for q in qs:
    if q[0] == 2:
        print(-lq[0], ans)
        continue
    _,a,b = q
    ans += b
    heapq.heappush(lq, -a)
    heapq.heappush(rq, a)
    if -lq[0] > rq[0]:
        l = -heapq.heappop(lq)
        r = heapq.heappop(rq)
        ans += abs(l-r)
        heapq.heappush(lq,-r)
        heapq.heappush(rq,r)

Submission status: Wrong Answer

Solution code:
import heapq
Q = int(input())
qs = [tuple(map(int,input().split())) for i in range(Q)]

lq = []
rq = []
heapq.heapify(lq)
heapq.heapify(rq)
c = 0

for q in qs:
    if q[0] == 2:
        ans = c
        if len(lq) == len(rq):
            ans += rq[0] + lq[0]
        print(-lq[0], ans)
        continue
    _,a,b = q
    c += b
    if len(lq) == len(rq):
        if rq and rq[0] < a:
            r = heapq.heappop(rq)
            if rq:
                c -= (rq[0]-r) * len(rq)
                if rq[0] <= a:
                    c += a-rq[0]
                else:
                    c += (rq[0]-a) * len(rq)
            heapq.heappush(rq, a)
            a = r
        if lq:
            if -lq[0] >= a:
                c += -lq[0]-a
            else:
                c += (a+lq[0]) * len(lq)
        heapq.heappush(lq, -a)
    else:
        if lq and -lq[0] > a:
            l = -heapq.heappop(lq)
            if lq:
                c -= (l+lq[0]) * len(lq)
                if -lq[0] >= a:
                    c += -lq[0]-a
                else:
                    c += (a+lq[0]) * len(lq)
            heapq.heappush(lq, -a)
            a = l
        if rq:
            if rq[0] <= a:
                c += a-rq[0]
            else:
                c += (rq[0]-a) * len(rq)
        heapq.heappush(rq, a)

Submission status: Wrong Answer

Solution code:
import bisect

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

A_list = []
B = 0

for line in my_list:
    params = list(map(int, line.split()))
    if params[0] == 1:
        bisect.insort_left(A_list,params[1])
        B += params[2]
    else:
        index = len(A_list) // 2 if len(A_list) % 2 == 0 else len(A_list) // 2 + 1
        x = A_list[index - 1]
        ans = abs(sum(A_list) - x * len(A_list)) + B
        print(x, ans)

Submission status: Wrong Answer

Solution code:
Q = int(input())
my_list = [input() for i in range(Q)]

A_list = []
B = 0

for line in my_list:
    params = list(map(int, line.split()))
    if params[0] == 1:
        A_list.append(params[1])
        B += params[2]
    else:
        A_list.sort()
        index = len(A_list) // 2 if len(A_list) % 2 == 0 else len(A_list) // 2 + 1
        x = A_list[index - 1]
        ans = abs(sum(A_list) - x * len(A_list)) + B
        print(x, ans)

Submission status: Wrong Answer

Solution code:
q = int(input())
qur = [0] * q
for i in range(q):
    t = list(map(int, input().split()))
    if len(t) == 1:
        qur[i] = [2, 0, 0]
    else:
        qur[i] = t
fx = 0
x = 0
cnt = 0
sa = 0
sb = 0
alist = []


def sumx(x, alist):
    s = 0
    for i in alist:
        s += abs(x-i)
    return s


for o, a, b in qur:
    if o == 1:
        alist.append(a)
        sa += a
        sb += b
        cnt += 1
        x = sa // cnt
        fx = sumx(x, alist) + sb
    else:
        print(x, end=" ")
        print(fx)

Submission status: Wrong Answer

Solution code:
Q = int(input())

al = []
bsum = 0
for _ in range(Q):
    query = list(map(int, input().split()))
    if len(query) == 1:  # show query
        ans = 10**15
        ans_pos = 0
        for i in range(len(al)):
            asum = 0
            for j in range(len(al)):
                asum += abs(al[j]-al[i])
            if asum < ans:
                ans_pos = al[i]
                ans = asum
        print(ans_pos, asum + bsum)
    else:  # update query
        _, a, b = query
        al.append(a)
        al.sort()
        bsum += b

Submission status: Wrong Answer

Solution code:
import heapq

A = []
count = 0
result = 0
rows = []

for _ in range(int(input().strip())):
  q = list(map(int, input().strip().split(' ')))
  if len(q) == 1:
    median_pos = (count - 1) // 2
    x = A[median_pos]
    rows.append('{} {}'.format(x, result))
  else:
    a = q[1]
    if count > 0:
      median_pos = (count - 1) // 2
      l = A[median_pos]
      r = A[median_pos + 1 - count % 2]
      if a < l:
        result += l - a
      elif a > r:
        result += a - r

    result += q[2]
    heapq.heappush(A, a)
    count = count + 1

for row in rows:
  print(row)

Submission status: Wrong Answer

Solution code:
import heapq

N = int(input().strip())

_, a, result = map(int, input().strip().split(' '))
A = [a]
count = 1

rows = []
for _ in range(N - 1):
  q = list(map(int, input().strip().split(' ')))
  if len(q) == 1:
    median_pos = (count - 1) // 2
    x = A[median_pos]
    rows.append('{} {}'.format(x, result))
  else:
    median_pos = (count - 1) // 2
    l = A[median_pos]
    r = A[median_pos + 1 - count % 2]
    a = q[1]
    if a < l:
      result += l - a
    elif a > r:
      result += a - r
    result += q[2]

    heapq.heappush(A, a)
    count = count + 1

for row in rows:
  print(row)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input().strip())

count = 0
b = 0
counter = Counter()

for q in [[int(i) for i in input().strip().split(' ')] for _ in range(N)]:
  if len(q) == 1:
    median_pos = (count - 1) // 2

    pos = 0
    for x, n in counter.items():
      pos += n
      if pos > median_pos: break

    s = 0
    for a, n in counter.items():
      s += abs(x - a) * n

    print('{} {}'.format(x, s + b))

    # print(q)
  else:
    count = count + 1
    counter[q[1]] += 1
    b += q[2]

Submission status: Wrong Answer

Solution code:
N = int(input().strip())

count = 0
A = []
b = 0
dic = dict()

for q in [[int(i) for i in input().strip().split(' ')] for _ in range(N)]:
  if len(q) == 1:
    median = (count - 1) // 2

    pos = 0
    for x, n in sorted(dic.items()):
      pos += n
      if pos >= median:
        break

    s = 0
    for a, n in dic.items():
      s += abs(x - a) * n

    print('{} {}'.format(x, s + b))

    # print(q)
  else:
    count = count + 1
    a = q[1]
    if a in dic:
      dic[a] += 1
    else:
      dic[a] = 1

    b += q[2]

Submission status: Wrong Answer

Solution code:
N = int(input().strip())

Q = []
for _ in range(N):
  Q.append([int(i) for i in input().strip().split(' ')])

A = []
b = 0
for q in Q:
  if len(q) == 1:
    x = sum(A) // len(A)
    s = sum([abs(x - v) for v in A]) + b
    while True:
      tmp = sum([abs(x - 1 - v) for v in A]) + b
      if tmp != s:
        break
      x = x - 1

    print('{} {}'.format(x, s))
    # print(q)
  else:
    A.append(q[1])
    b += q[2]

Submission status: Wrong Answer

Solution code:
def Technique_often_used():    
    # enumerate: for i, a in enumerate(a_list):
    # q, mod = divmod(a, b)
    # Functional Programming: filter, map, reduce
    pass
def naming_conventions():
    # [s_1, s_2, s_3, ..., s_k] is named s_k
    # [[s_11, s_12, ..., s_1k], ..,[s_j1, s_j2, ..., s_jk] is named s_jk
    # [[b1,c1],[b2,c2],..,[bm,cm]] is named bc
    # if there is something strange in a list then I add _ to the list's name (ex:s_jk_)
    pass
def visual_studio_code_shortcut():    
    # visual studio code shortcut https://qiita.com/TakahiRoyte/items/cdab6fca64da386a690b
    # delete line: Ctrl+Shift+k
    # choose same words: Ctrl+Shift+l
    pass
import sys
from itertools import combinations, permutations # https://docs.python.org/ja/3/library/itertools.html
from collections import deque, Counter # https://docs.python.org/ja/3/library/collections.html#collections.deque
from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest # https://docs.python.org/ja/3/library/heapq.html
from copy import deepcopy, copy # https://docs.python.org/ja/3/library/copy.html
from functools import reduce
from fractions import gcd # Deprecated since version 3.5: Use math.gcd() instead.
def gcds(numbers):
    return reduce(gcd, numbers)
def lcm(x, y):
    return (x * y) // gcd(x, y)
def lcms(numbers): #
    return reduce(lcm, numbers, 1)

# set the inputs
    # open(0).read() is a convenient method: 
    # ex) n, m, *x = map(int, open(0).read().split())
    #     min(x[::2]) - max(x[1::2])
    # ex2) *x, = map(int, open(0).read().split())
    #     don't forget to add comma after *x if only one variable is used
    # ex1) n, k = R()
    # ex2) v = list(R())
    # ex3) bc = [list(R()) for i in range(m)]

R = lambda: map(int, input().split())
q = int(input())
queries = [list(R()) for i in range(q)]

# q = 4
# queries=[[1,4,2],[2],[1,1,-8],[2]]

l = []
r = []
ans = 0
for query in queries:
    if query[0] == 1:
        a = heappushpop(l,-query[1])
        b = heappushpop(r, query[1])
        heappush(l,-b)
        heappush(r,-a)
        ans += abs(b+a) + query[2]
    else:
        print(-l[-1],ans)

Submission status: Wrong Answer

Solution code:
import heapq

Q = int(input())
q = [list(map(int, input().split())) for _ in range(Q)]


ql = []
qr = []

push = heapq.heappush
pop = heapq.heappop

push(qr, 10000000000)
push(ql, -10000000000)
a = 0
m = q[0][1]
b = q[0][2]
l = q[0][1]
r = q[0][1]
for i in q[1:]:
  if i[0] == 1:
    b += i[2]
    if i[1] < l:
      a += abs(i[1] - l)
    elif r < i[1]:
      a += abs(i[1] - r)
    if len(ql) <= len(qr):
      v = [m, pop(qr), i[1]]
    else:
      v = [m, -pop(ql), i[1]]
    v.sort()
    ll = v[0]
    m = v[1]
    rr = v[2]
    
    push(ql, -ll)
    push(qr, rr)
    if len(ql) > len(qr):
      l = ll
      r = m
    else:
      l = m
      r = m

  else:
    print(l, a + b)

Submission status: Wrong Answer

Solution code:
import heapq

Q = int(input())
q = [list(map(int, input().split())) for _ in range(Q)]


ql = []
qr = []

push = heapq.heappush
pop = heapq.heappop

push(qr, 10000000000)
push(ql, -10000000000)
a = 0
m = q[0][1]
b = q[0][2]
l = q[0][1]
r = q[0][1]
for i in q[1:]:
  if i[0] == 1:
    b += i[2]
    if i[1] < l:
      a += abs(i[1] - l)
    elif r < i[1]:
      a += abs(i[1] - r)
    if len(ql) <= len(qr):
      v = [m, pop(qr), i[1]]
    else:
      v = [m, -pop(ql), i[1]]
    v.sort()
    ll = v[0]
    m = v[1]
    rr = v[2]
    
    push(ql, -ll)
    push(qr, rr)
    if len(ql) <= len(qr):
      l = ll
      r = m
    else:
      l = m
      r = m

  else:
    print(l, a + b)

Submission status: Wrong Answer

Solution code:
import heapq

Q = int(input())
q = [list(map(int, input().split())) for _ in range(Q)]


ql = []
qr = []

push = heapq.heappush
pop = heapq.heappop

push(qr, 10000000000)
push(ql, -10000000000)
a = 0
m = q[0][1]
b = q[0][2]
l = q[0][1]
r = q[0][1]
for i in q[1:]:
  if i[0] == 1:
    b += i[2]
    if i[1] < l:
      a += abs(i[1] - l)
    elif r < i[1]:
      a += abs(i[1] - r)
    if len(ql) <= len(qr):
      v = [m, pop(qr), i[1]]
    else:
      v = [m, -pop(ql), i[1]]
    v.sort()
    ll = v[0]
    m = v[1]
    rr = v[2]
    if len(ql) <= len(qr):
      l = ll
      r = m
    else:
      l = m
      r = m

    push(ql, -ll)
    push(qr, rr)
  else:
    print(l, a + b)

Submission status: Wrong Answer

Solution code:
Q=int(input())
A=[]
B=0
j=0
Que0=list(map(int,input().split(" ")))
A=[Que0[1]]
B=Que0[2]
min=0
for i in range (1,Q):
    Query=list(map(int,input().split(" ")))
    l=len(A)
    if Query[0]==1:
        if l%2==0 :
            if Query[1]<A[int(l/2)-1]:
                min=min+A[int(l/2)-1]-Query[1]
            elif Query[1]>A[int(l/2)]:
                min=min+Query[1]-A[int(l/2)]
        else:
            min=int(abs(A[int((l-1)/2)]-Query[1]))
        j=0
        while Query[1]>A[j]:
            j=j+1
            if j>=l:
                break
        A.insert(j,Query[1])
        B=B+Query[2]
    else:
        s=int((l-1)/2)
        x=int(A[s])
        print(x,end=" ")
        print(int(min+B))

Submission status: Wrong Answer

Solution code:
import numpy as np
Q=int(input())
A=[]
B=0
j=0
Que0=list(map(int,input().split(" ")))
A=np.append(A,Que0[1])
B=Que0[2]
A=np.sort(A)
min=0
for i in range (1,Q):
    Query=list(map(int,input().split(" ")))
    l=len(A)
    if Query[0]==1:
        if l%2==0 :
            if Query[1]<A[int(l/2)-1]:
                min=min+A[int(l/2)-1]-Query[1]
            elif Query[1]>A[int(l/2)]:
                min=min+Query[1]-A[int(l/2)]
        else:
            min=int(abs(A[int((l-1)/2)]-Query[1]))
        A=np.append(A,Query[1])
        B=B+Query[2]
        A=np.sort(A)
    else:
        s=int((l-1)/2)
        x=int(A[s])
        print(x,end=" ")
        print(int(min+B))

Submission status: Wrong Answer

Solution code:
import numpy as np
Q=int(input())
A=[]
B=[]
j=0
Que0=list(map(int,input().split(" ")))
A=np.append(A,Que0[1])
B=np.append(B,Que0[2])
A=np.sort(A)
min=0
for i in range (1,Q):
    Query=list(map(int,input().split(" ")))
    if Query[0]==1:
        if len(A)%2==0 :
            if Query[1]<A[int(len(A)/2)-1]:
                min=min+A[int(len(A)/2)-1]-Query[1]
            elif Query[1]>A[int(len(A)/2)]:
                min=min+Query[1]-A[int(len(A)/2)]
        else:
            min=int(abs(A[int((len(A)-1)/2)]-Query[1]))
        A=np.append(A,Query[1])
        B=np.append(B,Query[2])
        A=np.sort(A)
    else:
        s=int((len(A)-1)/2)
        x=int(A[s])
        print(x,end=" ")
        print(int(min+sum(B)))

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop

Q = int(input())

update_count = 0
al = []
sl = 0
ar = []
sr = 0
b = 0
for _ in range(Q):
    # print(al, sl)
    # print(ar, sr)
    # print(b)
    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
        # 左キューalの最大値が中央値になっている
        # 左キューにheappushする際,負値に変換したので,heappopで最大値*(-1)が求まる
    else:
        # 求値クエリ
        x = heappop(al)  # 中央値
        heappush(al, x)
        x *= (-1)
        print(x, sl + sr - x * update_count + b)

Submission status: Wrong Answer

Solution code:
from heapq import*
L,R=[],[]
B=t=0
Q,*E=open(0)
print('じっけん')
for e in E:
	try:_,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
	except:print(-L[0],B-L[0]*t)

Submission status: Wrong Answer

Solution code:
arr= []
sum= []
idx=0
t= 0
res= 0
pos= 0
str=[]
q=int(input())
for i in range(q):
	str.append(input())
for j in range(q):
	inp= list(map(int, str[j].split(' ')))
	if(inp[0]==2):
		print(arr[idx], sum[idx]+res)
		continue
	t+= 1
	for i in range(t-1):
		if(arr[i]<inp[1]):
			continue
		arr.insert(i, inp[1])
		sum.insert(i, 0)
		pos=0
		break
	if(len(arr)!=t):
		arr.append(inp[1])
		sum.append(0)
		pos= t-1
		
	for i in range(t):
			temp= abs(arr[i]-arr[pos])
			sum[pos]+= temp
			sum[i]+= temp

	for i in range(t-1):
		if(sum[i]<sum[idx]):
			idx= i
	res+= inp[2]

Submission status: Wrong Answer

Solution code:
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)
                if len(high)>1:
                    asum-=abs(high[0]+low[0])
            elif len(high)>=len(low)+1:
                ltoh=h.heappop(high)
                h.heappush(low, -ltoh)
                asum+=high[0]+low[0]
    else:
        print(-low[0],asum+bsum)

Submission status: Wrong Answer

Solution code:
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, -A)

            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)

Submission status: Wrong Answer

Solution code:
import heapq

Q = int(input())
B = 0

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

for i in range(Q - 1):
    q = list(map(int, input().split()))
    if len(q) == 3:
        print(L, R)
        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, -A)

            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)

Submission status: Wrong Answer

Solution code:
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());L,R=R,L;t=1-t;a*=2*t-1;c=heappushpop(L,a);heappush(R,-c);B+=b+a-c-c
	else:w=-min(L+R);print(w,B+w*t)

Submission status: Wrong Answer

Solution code:
from heapq import*
R=L=[]
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)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import heapq


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
                #if len(hl) <= len(hr):
                heapq.heappush(hl, -a)
                sum_al += a
                #else:
                #    heapq.heappush(hr, a)

            while len(hr) > len(hl):
                tmp = heapq.heappop(hr)
                sum_ar -= tmp
                heapq.heappush(hl, -tmp)
                sum_al += tmp
            while len(hl) > len(hl)+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, sum_al, hr, sum_ar)
            print(-hl[0], tmp_al+tmp_ar+sum_b)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import heapq


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
                #if len(hl) <= len(hr):
                heapq.heappush(hl, -a)
                sum_al += a
                #else:
                #    heapq.heappush(hr, a)

            while len(hr) > len(hl):
                tmp = heapq.heappop(hr)
                sum_ar -= tmp
                heapq.heappush(hl, -tmp)
                sum_al += tmp
            while len(hl) > len(hl)+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, hr, sum_al, sum_ar)
            print(-hl[0], tmp_al+tmp_ar+sum_b)

    pass

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
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':
#        input
        d, a, b = map(int,q.split())
        if not flg:
            heapq.heappush(Al,-a)
            B += b
            flg = True
            continue
        
#        C = abs(a - (-Al[0]))
        if len(Al) == len(Ar):
            if a < Ar[0]:
                C = abs(a - (-Al[0]))
                heapq.heappush(Al,-a)
#                C = abs(a - (-Al[0]))
#            elif a < Ar[0]:
#                heapq.heappush(Al,-(heapq.heappop(Ar)))
#                heapq.heappush(Ar,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)))
#            elif a < A[]
            else:
                heapq.heappush(Ar,a)
                C = abs(a - (-Al[0]))
        B += (b + C)
#        print(Al,Ar,a,B,b)
    else:
#        output
        ans.append([(-Al[0]),B])
        
for c in ans:
    print(' '.join(map(str,c)))

Submission status: Wrong Answer

Solution code:
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:
      heappush(maxh, -q[1])
      sum1 += q[1]
    elif len(minh)==0:
      if q[1]<-maxh[0]:
        heappush(maxh, -q[1])
        t = -heappop(maxh)
        heappush(minh, t)
        sum1 += q[1]-t
        sum2 += t
      else:
        heappush(minh, q[1])
        sum2 += q[1]
    else:
      if q[1]<-maxh[0]:
        t = -heappop(maxh)
        heappush(minh, t)
        heappush(maxh, -q[1])
        sum1 += q[1]-t
        sum2 += t
      else:
        t = heappop(minh)
        heappush(maxh, -t)
        heappush(minh, q[1])
        sum1 += t
        sum2 += q[1]-t
    med = -maxh[0]
  else:
    ans = len(maxh)*med-sum1+sum2-len(minh)*med+b
    print(med, ans)