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 heapq
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def ii(): return int(stdin.readline())
def li(): return map(int, stdin.readline().split())
Q = ii()
points = []
cons = 0
def update(_opcode, point, delta):
    global cons
    cons += delta
    points.append(point)

def cal():
    points.sort()
    w = 0
    l, r = 0, len(points) - 1
    while l < r:
        w += (points[r] - points[l])
        l += 1
        r -= 1
    print("{} {}".format(points[l - 1], w + cons))

for _ in range(Q):
    ops = tuple(li())
    if len(ops) == 3:
        update(*ops)
    else:
        cal()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
from math import factorial as f
from fractions import gcd as g

Q = int(raw_input ())
C = []
c = 0
X = 0

def solve():
    if len(C) == 0: return c
    x = X // len(C)
    return (x, c + sum(abs(x - i) for i in C))


for i in range(Q):
    l = [int(i) for i in raw_input ().split()]
    if len(l) == 1:
        x, y = solve()
        print x, y
    else:
        c += l[-1]
        C.append(l[1])
        X += C[-1]
    # print C, c, X

Submission status: Wrong Answer

Solution code:
Q = int(input())
A,B = 0,0
a_list = []
e = 0
for i in range(Q):
    query = list(map(int,input().split(" ")))
    
    if query[0] == 1:
        a,b = query[1],query[2]
        a_list.append(a)
        A += a
        B += b
        e += 1
    else:
        x = A // e
        print("{0} {1}".format(x, B + sum(list(map(lambda v: abs(v - x) ,a_list)))))

Submission status: Wrong Answer

Solution code:
import bisect as bs

a = []
l = 0
sum0 = 0
sum1 = 0

q = int(input())
b = 0
for i in range(q):
  z = list(map(int,input().split()))
  if z[0] == 2:
    if l%2 == 0:
      t = a[l//2-1]
      #print("memo",a,b,l,t,sum0,sum1)
      print(str(t)+" "+str(sum1-sum0+b))
    else:
      t = a[l//2]
      #print("memo",a,b,l,t,sum0,sum1)
      print(str(t)+" "+str(sum1-sum0+t+b))
  else:
    b += z[2]
    k = z[1]
    i = bs.bisect_left(a,k)
    if l == 0:
      sum0 += k
    elif l%2 == 0:
      if i < l//2:
        sum0 += k
      else:
        sum0 += a[l//2]
        sum1 += k - a[l//2]
    else:
      if i < l//2+1:
        sum0 += k - a[l//2]
        sum1 += a[l//2]
      else:
        sum1 += k      
    a.insert(i,k)
    l += 1


#print(a)
#print(b)
#print(sum0,sum1)

Submission status: Wrong Answer

Solution code:
n = int(input())
history = []
mi = 10000000000
a = None
b = 0
for i in range(n):
    s = input()
    if s == "2":
        sum = b
        mi = min(mi, a)
        #print("a{0},b{1}".format(str(a), str(b)))
        for i in range(len(history)):
            #print("his="  + str(history[i]))
            sum += (abs(mi - history[i]))
        print("{0} {1}".format(str(mi), str(sum)))
    else:
        tra, a_in, b_in = map(int, s.split())
        if a is not None:
            history.append(a)
        a = a_in
        b = b_in + b

Submission status: Wrong Answer

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

Q = int(input())

LOWq = []
HIGHq = []
heapq.heapify(LOWq)
heapq.heapify(HIGHq)
SUM = 0
LOWsum = 0
HIGHsum = 0
LOWn = 0
HIGHn = 0
keisu = 0
ans = []
N = 0
ave = -INF

for _ in range(Q):
    inp = inpl()
    if inp[0] == 1:
        query,a,b = inp
        SUM += a   # 合計値
        keisu += b # 係数
        N += 1
        bef_ave = ave # 前平均
        ave = SUM/N # 平均
        if a >= ave:
            heapq.heappush(HIGHq,a)
            HIGHsum += a
            HIGHn += 1
        else:
            heapq.heappush(LOWq,-a)
            LOWsum += a
            LOWn += 1

        if bef_ave < ave:
            while True:
                pop = heapq.heappop(HIGHq)
                HIGHsum -= pop
                HIGHn -= 1
                if pop >= ave:
                    heapq.heappush(HIGHq,pop)
                    HIGHsum += pop
                    HIGHn += 1
                    break
                else:
                    heapq.heappush(LOWq,-pop)
                    LOWsum += pop
                    LOWn += 1
        elif bef_ave > ave:
            while True:
                pop = -heapq.heappop(LOWq)
                LOWsum -= pop
                LOWn -= 1
                if pop <= ave:
                    heapq.heappush(LOWq,-pop)
                    LOWsum += pop
                    LOWn += 1
                    break
                else:
                    heapq.heappush(HIGHq,pop)
                    HIGHsum += pop
                    HIGHn += 1
    else:
        #print(LOWsum,HIGHsum)
        #print('n',LOWn,HIGHn)
        if LOWn == 0:
            x = heapq.heappop(HIGHq)
            heapq.heappush(HIGHq,x)
        else:
            x = -heapq.heappop(LOWq)
            heapq.heappush(LOWq,-x)

        tmp = (HIGHsum - LOWsum) + (LOWn-HIGHn)*x + keisu
        ans.append([x,tmp])



for azu,nyan in ans:
    print(azu,nyan)

Submission status: Wrong Answer

Solution code:
Q = int(input())
queries = []
for _ in range(Q):
    queries.append(input())

from bisect import insort_left

ary, bry, c = [], [], 0
for query in queries:
    if query[0] == '2':
        absum = sum(abs(a - ary[c//2]) for a in ary)
        print(' '.join(map(str, (ary[c//2], absum + sum(bry)))))
    else:
        _, a, b = map(int, query.split())
        insort_left(ary, a)
        insort_left(bry, b)
        c += 1

Submission status: Wrong Answer

Solution code:
q=int(input())
mi=1e12
z=[]
za=0
b=0
for i in range(q):
    ans=0
    a=list(map(int,input().split()))
    if len(a)==3:
        z.append(a[1])
        b+=a[2]
        if mi!=1e12:
            za+=abs(a[1]-mi)
        mi=min(mi,a[1])
    else:
        print(mi,end=' ')
        print(za+b)

Submission status: Wrong Answer

Solution code:
Q = int(input())
B = 0  #bの総和
X = []
q = [list(input().split()) for _ in range(Q)]

for i in range(Q):
	if q[i][0] == "2":
		n = len(X)
		if n == 0:
			print(0, 0)
		else:
			if n % 2 == 0:
				print(X[n // 2 - 1], B + sum(X[n // 2:]) - sum(X[: n // 2]))
			else:
				print(X[n // 2], B + sum(X[n // 2 + 1:]) - sum(X[: n // 2]))
	else:
		if int(q[i][1]) not in X:
			X.append(int(q[i][1]))
			X = sorted(X)
		B += int(q[i][2])

Submission status: Wrong Answer

Solution code:
import heapq
Q = int(input())
A = []
B = 0
l = 0
for _ in [0]*Q:
    s = input().split()
    if s[0]=="1":
        heapq.heappush(A,int(s[1]))
        B += int(s[2])
        l += 1
    else:
        A.sort()
        m = A[l//2-1]
        s = sum(abs(a-m) for a in A)
        print(m,B+s)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

Q = int(input())

LOWq = []
HIGHq = []
heapq.heapify(LOWq)
heapq.heapify(HIGHq)
SUM = 0
LOWsum = 0
HIGHsum = 0
LOWn = 0
HIGHn = 0
keisu = 0
ans = []
N = 0
ave = -INF

for _ in range(Q):
    inp = inpl()
    if inp[0] == 1:
        query,a,b = inp
        SUM += a   # 合計値
        keisu += b # 係数
        N += 1
        bef_ave = ave # 前平均
        ave = SUM/N # 平均
        if a >= ave:
            heapq.heappush(HIGHq,a)
            HIGHsum += a
            HIGHn += 1
        else:
            heapq.heappush(LOWq,-a)
            LOWsum += a
            LOWn += 1

        if bef_ave < ave:
            while True:
                pop = heapq.heappop(HIGHq)
                HIGHsum -= pop
                HIGHn -= 1
                if pop >= ave:
                    heapq.heappush(HIGHq,pop)
                    HIGHsum += pop
                    HIGHn += 1
                    break
                else:
                    heapq.heappush(LOWq,-pop)
                    LOWsum += pop
                    LOWn += 1
        elif bef_ave > ave:
            while True:
                pop = -heapq.heappop(LOWq)
                LOWsum -= pop
                LOWn -= 1
                if pop <= ave:
                    heapq.heappush(LOWq,pop)
                    LOWsum += pop
                    LOWn += 1
                    break
                else:
                    heapq.heappush(HIGHq,pop)
                    HIGHsum += pop
                    HIGHn += 1
    else:
        #print(LOWsum,HIGHsum)
        #print('n',LOWn,HIGHn)
        if LOWn == 0:
            x = heapq.heappop(HIGHq)
            heapq.heappush(HIGHq,x)
        else:
            x = heapq.heappop(LOWq)
            heapq.heappush(LOWq,x)

        tmp = (HIGHsum - LOWsum) + (LOWn-HIGHn)*x + keisu
        ans.append([x,tmp])



for azu,nyan in ans:
    print(azu,nyan)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

Q = int(input())

A = []
B = 0
for _ in range(Q):
    inp = list(map(int,input().split()))
    if inp[0] == 1:
        A.append(inp[1])
        A.sort()
        B += inp[2]

    elif inp[0] == 2:
        l = len(A)
        if l == 0:
            print(0,0)
        else:
            index = l//2 - 1
            print(A[index], sum([abs(A[index] - i) for i in A]) + B)

Submission status: Wrong Answer

Solution code:
Q = int(input())

a = []
bsum = 0

for i in range(Q):
    query = list(map(int, input().split()))
    if query[0] == 1:
        a.append(query[1])
        bsum += query[2]
    elif query[0] == 2:
        x = min(a)
        fx = sum(a) - x * len(a) + bsum
        print(x, fx)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left

if __name__ == '__main__':
    q = int(input())
    query = [list(map(int, input().split())) for _ in range(q)]

    first_query = query[0]
    [_, a, b] = first_query
    a_list = [a]
    b_sum = b
    state = [a]
    center_index = 0

    for que in query[1:]:
        if que[0] == 1:
            if len(state) == 1:
                insert_index = bisect_left(a_list, que[1])
                if center_index >= insert_index:
                    state = [que[1], state[0]]
                    center_index = insert_index
                else:
                    state = [state[0], que[1]]
                    center_index = center_index
                b_sum = b_sum + que[2]
            else:
                insert_index = bisect_left(a_list, que[1])
                if center_index >= insert_index:
                    state = [state[0]]
                    center_index = center_index + 1
                elif center_index + 1 == insert_index:
                    state = [que[1]]
                    center_index = insert_index
                else:
                    state = [state[1]]
                    center_index = center_index + 1
                b_sum = b_sum + que[2]
        else:
            min_x = state[0]
            min_val = 0
            for a in a_list:
                min_val = min_val + abs(min_x - a)
            print(min_x, min_val + b_sum)

# 状態の更新
# 中央がある（中央）
# 　中央より左　→　中央がない（中央の１つ左　中央）
# 　中央より右　→　中央がない（中央　中央の１つ右）
# 中央がない（中央左　中央右）
# 　中央左より左　→　中央がある（中央左）
# 　中央左と中央右の間　→　中央がある（新しい値）
# 　中央右より右　→　中央がある（中央右）

# 求値
# 　中央、または、中央左がXとなる
# 　XとAと（Bの和）から最小値を計算する

Submission status: Wrong Answer

Solution code:
from heapq import *

def main():
    from sys import stdin, stdout

    def read():
        return stdin.readline().rstrip('\n')

    def read_array(sep=None, maxsplit=-1):
        return read().split(sep, maxsplit)

    def read_int():
        return int(read())

    def read_int_array(sep=None, maxsplit=-1):
        return [int(a) for a in read_array(sep, maxsplit)]

    def write(*args, **kwargs):
        sep = kwargs.get('sep', ' ')
        end = kwargs.get('end', '\n')
        stdout.write(sep.join(str(a) for a in args) + end)

    def write_array(array, **kwargs):
        sep = kwargs.get('sep', ' ')
        end = kwargs.get('end', '\n')
        stdout.write(sep.join(str(a) for a in array) + end)

    MOD = 10**9 + 7
    lower_heap = []
    higher_heap = []
    median = constant = sum_lower = sum_higher = 0
    for _ in range(read_int()):
        ar = read_int_array()
        if len(ar) == 3:
            constant += ar[2]
            x = ar[1]
            if not lower_heap:
                lower_heap.append(-x)
                sum_lower += x
                median = x
            elif not higher_heap:
                heappush(lower_heap, -x)
                sum_lower += x

                x = -heappop(lower_heap)
                sum_lower -= x
                heappush(higher_heap, x)
                sum_higher += x
                median = -lower_heap[0]
            elif x <= -lower_heap[0]:
                heappush(lower_heap, -x)
                sum_lower += x

                if len(lower_heap) - len(higher_heap) > 1:
                    x = -heappop(lower_heap)
                    sum_lower -= x
                    heappush(higher_heap, x)
                    sum_higher += x
                median = -lower_heap[0]
            else:
                heappush(higher_heap, x)
                sum_higher += x
                if len(higher_heap) > len(lower_heap):
                    x = heappop(higher_heap)
                    sum_higher -= x
                    heappush(lower_heap, -x)
                    sum_lower += x
                median = -lower_heap[0]
        else:
            write(median, constant + abs(sum_lower - median * len(lower_heap) + abs(sum_higher - median * len(higher_heap))))

main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from collections import defaultdict
from operator import itemgetter
import numpy as np

def solve(): 
    Q = int(input())
    q, a, b = map(int, input().split())
    A = [a]
    B = b
    count = 1
    l, c, r = None, a, None
    res_l = []

    for _ in range(Q-1):
        *q_, = map(int, input().split())
        if q_[0] == 1:
            q,a,b = q_
            if count&1:
                l, r = sorted([a,c])
            else:
                c = sorted([a,l,r])[1]
            count ^= 1
            A.append(a)
            B += b
        else:
            x = c if count&1 else l
            v = B + sum(abs(x-a) for a in A)
            res_l.append('{} {}'.format(x, v))
    res = '\n'.join(res_l)
    return str(res)

if __name__ == '__main__':
    print(solve())

Submission status: Wrong Answer

Solution code:
ql=int(input())
es=[]
B=0
for qi in range(ql):
  q=tuple(map(int,input().split()))
  if q==(2,):
    re=B
    if len(es)%2==0:
      ei=len(es)//2
    else:
      ei=(len(es)-1)//2
    emin=es[ei]
    for e in es:
      re += abs(e-emin)
    print(emin,re)
  else:
    e = q[1]
    b = q[2]
    es.append(e)
    es.sort()
    B+=b

Submission status: Wrong Answer

Solution code:
# from sys import exit
Q = int(input())
cnt = 0
ave = 0
base = 0
tans = []
for i in range(Q):
    l = [int(n) for n in input().split()]
    if l[0] == 2:
        x = tans[cnt//2]
        print(x, end=" ")
        print(sum([a - x for a in tans]) + base)
    else:
        cnt += 1
        tans.append(l[1])
        base += l[2]

Submission status: Wrong Answer

Solution code:
# b_iはほとんど無視できる
# a_iはだいたい真ん中
# 下側集合と上側集合に分けて更新していく
import sys
input = sys.stdin.readline
import heapq

Q = int(input())


L = [] # -1倍して突っ込む
R = []
L_size = 0
R_size = 0
min_value = 0
min_x = 0

INF = 10**18
L_max = -INF
R_min = INF

def f1(a,b):
  global min_value,L_max,R_min,min_x,L_size,R_size
  min_value += b
  if a < L_max:
    heapq.heappush(L,-a)
    L_size += 1
    if L_size == R_size:
      min_value += min_x - a
      return
    elif L_size == R_size + 1:
      min_x = L_max
      min_value += min_x - a
      return
    else:
      # LからRへ1つうつす
      x = -heapq.heappop(L)
      heapq.heappush(R,x)
      L_max = -heapq.nsmallest(1,L)[0]
      R_min = x
      min_x = x
      min_value += x-a
      return
  elif a > R_min:
    heapq.heappush(R,a)
    R_size += 1
    if L_size == R_size:
      min_value += a - min_x
      return
    elif R_size == L_size + 1:
      min_x = R_min
      min_value += a - min_x
      return
    else:
      # RからLへ1つうつす
      x = heapq.heappop(R)
      heapq.heappush(L,-x)
      R_min = heapq.nsmallest(1,R)[0]
      R_min = x
      min_x = x
      min_value += a-x
      return
  else:
    if L_size > R_size:
      heapq.heappush(R,a)
      R_size += 1
      R_min = a
      min_x = a
      min_value += a-L_max
      return
    elif R_size > L_size:
      heapq.heappush(L,-a)
      L_size += 1
      L_max = a
      min_x = a
      min_value += R_min - a
      return
    else: # 両方同じ大きさ
      heapq.heappush(L,-a)
      L_size += 1
      L_max = a
      min_x = a
      return

def f2():
  print(min_x,min_value)
  
for _ in range(Q):
  row = [int(x) for x in input().split()]
  if row[0] == 1:
    f1(row[1],row[2])
  else:
    f2()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from bisect import bisect

def main():
    q = II()
    Q = []
    for _ in range(q):
        Q.append(LI())
    A = []
    bias = 0
    for q in Q:
        if q == [2]:
            ans = A[(len(A) - 1) // 2], (A[-1] - A[0] + bias)
            print(*ans)
        else:
            _, a, b = q
            bias += b
            index = bisect(A, a)
            A.insert(index, a)
    return

main()

Submission status: Wrong Answer

Solution code:
Q = int(input())

a = []
b = 0

c_sum = []
cs = 0

cnt = 0
for _ in range(Q):
    t = tuple(map(int, input().split()))
    if t[0] == 1:
        # 更新
        a.append(t[1])
        cnt += 1

        cs += t[1]
        c_sum.append(cs)

        b += t[2]
    else:
        # 求値
        a.sort()
        idx = ((cnt + 1) // 2) - 1

        if cnt >= 3:
            v = c_sum[idx - 1] - idx * a[idx] + (c_sum[cnt - 1] - c_sum[idx]) - (cnt - 1 - idx) * a[idx]
        elif cnt == 1:
            v = 0
        else:
            v = a[cnt - 1] - a[idx]

        print(a[idx], b + v)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
import heapq
q=int(input())
h=[]
l=0
b=0
s=0
ans=0
med=0
for _ in range(q):
    Tmp=list(map(int,input().split()))
    if Tmp[0]==1:
        s+=Tmp[1]
        b+=Tmp[2]
        l+=1
        heapq.heappush(h,Tmp[1])
        med=h[(l-1)//2]
        ans=s-med*l+b
    else:
        print(med,ans)

Submission status: Wrong Answer

Solution code:
import heapq

q = int(input())

# 中央値との大小で集団を２つに分けて管理したいぞ
_,a,b = map(int, input().split())
a_large = []
a_small = [-a]
cnt_large = 0
cnt_small = 1
mean = 0
cons = b

for i in range(q-1):
    query = input()
    if query[0] == '1':
        _,a,b = map(int, query.split())
        cons = cons + b
        if a < -a_small[0]:
            # 最大ヒープ
            heapq.heappush(a_small, -a)
            cnt_small += 1
            if cnt_small > cnt_large + 1:
                heapq.heappush(a_large, -heapq.heappop(a_small))
                cnt_small -= 1
                cnt_large += 1
        else:
            # 最小ヒープ
            heapq.heappush(a_large, a)
            cnt_large += 1
    else:
        total = 0
        x = -a_small[0]
        for small in a_small:
            total += abs(x+small)
        for large in a_large:
            total += abs(x-large)
        total += cons
        print(x, total)

Submission status: Wrong Answer

Solution code:
#最小値はずっと同じで構わない(最初のa)、メモしながらがんばる
#メモの方法---最初のaでxを固定、それとの差を変数に加算し続ける
q=int(input())
qq,aa,bb=map(int,input().split())
x=aa
y=aa
a,b=0,bb
for i in range(1,q):
  s=input()
  if s=="2":
    print(y,a+b)
    continue
  qq,aa,bb=map(int,s.split())
  a+=abs(x-aa);b+=bb
  y=min(y,aa)

Submission status: Wrong Answer

Solution code:
#最小値はずっと同じで構わない(最初のa)、メモしながらがんばる
#メモの方法---最初のaでxを固定、それとの差を変数に加算し続ける
q=int(input())
qq,aa,bb=map(int,input().split())
x=aa
a,b=0,bb
for i in range(1,q):
  s=input()
  if s=="2":
    print(x,a+b)
    continue
  qq,aa,bb=map(int,s.split())
  a+=abs(x-aa);b+=bb

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
Q = int(input())
A, B = [], 0

fq, fa, fb = map(int, input().split())
A.append(fa)
Median, Median_i = fa, 0
B = fb

L_cnt, R_cnt = 0, 0
L_sum, R_sum = 0, 0

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

        if i <= Median_i:
            R_cnt += 1
            R_sum += A[Median_i]
        else:
            L_cnt += 1
            L_sum += A[Median_i]

        A.insert(i, q[1])
        if len(A) % 2 == 0:
            Median = A[len(A) // 2 - 1]
            Median_i = len(A) // 2 - 1
        else:
            Median = A[len(A) // 2]
            Median_i = len(A) // 2

    else:
        # print(A, Median)
        # print(L_cnt, L_sum, R_cnt, R_sum)
        # print(abs(R_sum - (R_cnt * Median)))
        print(Median, abs(L_sum - (L_cnt * Median)) + abs(R_sum - (R_cnt * Median)) + B)

Submission status: Wrong Answer

Solution code:
# b_iはほとんど無視できる
# a_iはだいたい真ん中
# 下側集合と上側集合に分けて更新していく

import heapq

Q = int(input())


L = [] # -1倍して突っ込む
R = []
L_size = 0
R_size = 0
min_value = 0
min_x = 0

INF = 10**18
L_max = -INF
R_min = INF

def f1(a,b):
  global min_value,L_max,R_min,min_x,L_size,R_size
  min_value += b
  if a < L_max:
    heapq.heappush(L,-a)
    L_size += 1
    if L_size == R_size:
      min_value = min_x - a
      return
    elif L_size == R_size + 1:
      min_x = L_max
      min_value += min_x - a
      return
    else:
      # LからRへ1つうつす
      x = -heapq.heappop(L)
      heapq.heappush(R,x)
      L_max = -heapq.nsmallest(1,L)[0]
      R_min = x
      min_x = x
      min_value += x-a
      return
  elif a > R_min:
    heapq.heappush(R,a)
    R_size += 1
    if L_size == R_size:
      min_value = a - min_x
      return
    elif R_size == L_size + 1:
      min_x = R_min
      min_value += a - min_x
      return
    else:
      # RからLへ1つうつす
      x = heapq.heappop(R)
      heapq.heappush(L,-x)
      R_min = heapq.nsmallest(1,R)[0]
      R_min = x
      min_x = x
      min_value += a-x
      return
  else:
    if L_size > R_size:
      heapq.heappush(R,a)
      R_size += 1
      R_min = a
      min_x = a
      min_value += a-L_max
      return
    elif R_size > L_size:
      heapq.heappush(L,-a)
      L_size += 1
      L_max = a
      min_x = a
      min_value += R_min - a
      return
    else: # 両方同じ大きさ
      heapq.heappush(L,-a)
      L_size += 1
      L_max = a
      min_x = a
      return

def f2():
  print(min_x,min_value)
  
for _ in range(Q):
  row = [int(x) for x in input().split()]
  if row[0] == 1:
    f1(row[1],row[2])
  else:
    f2()

Submission status: Wrong Answer

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

from bisect import bisect

# 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())
    A = []
    sumB = 0
    for i in range(Q):
        q = list(map(int, input().split()))
        if q[0] == 1:
            idx = bisect(A, q[1])
            A.insert(idx, q[1])
            sumB += q[2]
        else:
            p, r = divmod(len(A), 2)
            idx = p + r - 1
            xmin = A[idx]
            fmin = sumB
            fmin += sum(A[:idx])
            fmin += sum(A[idx+1:])
            fmin -= (len(A) - 1) * xmin
            print(xmin, fmin)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
Q=int(input())
seppen=0
XYZ=[-1000000007,1000000007]
for _ in [0]*Q:
    q,*l=map(int,input().split())
    if q==1:
        a,b=l
        seppen+=b
        if len(XYZ)==2:
            x,y=XYZ
            if a<x:
                seppen+=x-a
                XYZ=[a,x,y]
            elif x<=a<=y:
                XYZ=[x,a,y]
            else:
                seppen+=a-y
                XYZ=[x,y,a]
        else:
            x,y,z=XYZ
            if a<x:
                seppen+=y-a
                XYZ=[x,y]
            elif x<=a<y:
                seppen+=y-a
                XYZ=[a,y]
            elif y<=a<z:
                seppen+=a-y
                XYZ=[y,a]
            else:
                seppen+=a-y
                XYZ=[y,z]
    else:
        if len(XYZ)==2:
            print(XYZ[0], seppen)
        else:
            print(XYZ[1], seppen)

Submission status: Wrong Answer

Solution code:

def main():
    n = input()
    aa = []
    bb = 0
    for _ in xrange(n):
        q = raw_input()
        if q[0] == '1':
            a, b = map(int, q.split()[1:])
            aa.append(a)
            bb += b
        else:
            aa.sort()
            a = aa[(len(aa) - 1) // 2]
            print a, bb + sum(abs(i) - a for i in aa)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from heapq import heappush
a=[]
Q=int(input())
b=0
def calc(a,b):
    idx=(len(a)-1)//2
    x=a[idx]
    ans=b+sum(a[idx+1:])-sum(a[:idx])+(2*idx-len(a)+1)*x
    return " ".join([str(x),str(ans)])
for i in range(Q):
    q=input()
    if q=="2":
        print(calc(a,b))
    else:
        s,x,y=map(int,q.split())
        b+=y
        heappush(a,x)

Submission status: Wrong Answer

Solution code:
import heapq
import math

Q = int(input())
A = []
B = []

for _ in range(Q):
    nums = [int(i) for i in input().split()]
    if nums[0] == 1:
        heapq.heappush(A, nums[1])
        B.append(nums[2])
    else:
        x = A[int(math.floor((len(A) - 1) / 2))]
        res = sum([abs(x - i) for i in A]) + sum(B)
        print(x, res)