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:
Q = int(input())

dum, a, b = list(map(int, input().split()))
aL = a
aR = a
B = b

for i in range(Q-1):
    q = input()
    if q == '2':
        print(aL, B)
    else:
        dum, a, b = list(map(int, q.split()))
        if a < aL:
            B += aL - a
            aR = aL
            aL = a
        elif a > aR:
            B += a - aR
            aL = aR
            aR = a
        else:
            aL = a
            aR = a
        B += b

Submission status: Wrong Answer

Solution code:
import heapq

q = int(input())
b_cur = 0
lefts, rights = [], []
heapq.heapify(lefts)
heapq.heapify(rights)

for i in range(q):
    query = input()
    if len(query) > 1:
        _, a, b = map(int, query.split())
        if len(lefts) == 0 and len(rights) == 0:
            heapq.heappush(rights, a)
        elif len(lefts) == 0:
            heapq.heappush(lefts, -a)
        elif len(lefts) == len(rights):
            med_l, med_r = -heapq.heappop(lefts), heapq.heappop(rights)
            if a <= med_l:
                heapq.heappush(lefts, -a)
                heapq.heappush(rights, med_l)
                heapq.heappush(rights, med_r)
            else:
                heapq.heappush(rights, a)
                heapq.heappush(lefts, -med_l)
                heapq.heappush(rights, med_r)
        else:
            med_l, med_r = -heapq.heappop(lefts), heapq.heappop(rights)
            if a < med_r:
                heapq.heappush(lefts, -a)
                heapq.heappush(lefts, -med_l)
                heapq.heappush(rights, med_r)
            else:
                heapq.heappush(rights, a)
                heapq.heappush(lefts, -med_r)
                heapq.heappush(lefts, -med_l)
        b_cur += b
    else:
        if len(lefts) == len(rights):
            ans = (-lefts[0], b_cur+(rights[0]+lefts[0]))
        else:
            ans = (rights[0], b_cur)
        print(*ans)

Submission status: Wrong Answer

Solution code:
import bisect

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]
    ei = bisect.bisect_left(es,e)
    es.insert(ei,e)
    es.sort()
    B+=b

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
from collections import defaultdict
from functools import reduce

# s = input()
Q = int(input())
# A = list(map(int, input().split()))
# n, m, k = map(int, input().split())


a = None
size = 0
b = 0
a_sum = 0

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

    if query[0] == 1:
      size += 1
      a_sum += query[1]
      if a is None:
        a = query[1]
      else:
        a = min(a, query[1])
      b += query[2]

    else:
      print(a, a_sum - size*a +b)

Submission status: Wrong Answer

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

from bisect import bisect
from collections import defaultdict

# 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 = []
    count = defaultdict(lambda:0)
    sumB = 0
    lenA = 0
    imid = -1
    sumL = 0
    sumR = 0
    for i in range(Q):
        q = list(map(int, input().split()))
        if q[0] == 1:
            a, b = q[1], q[2]
            sumB += b
            idx = bisect(A, q[1])
            A.insert(idx, q[1])
            if lenA % 2 == 1:
                if idx < imid:
                    sumR += A[imid+1]
                    sumL += a
                elif idx == imid:
                    sumR += A[imid+1]
                else:
                    sumR += a
            else:
                imid += 1
                if idx < imid:
                    sumL += a
                elif idx == imid:
                    if imid > 0:
                        sumL += A[imid-1]
                else:
                    sumR += a
                    if imid > 0:
                        sumL += A[imid-1]
            lenA += 1
        else:
            xmin = A[imid]
            fmin = sumB
            fmin += xmin * imid - sumL
            fmin += sumR - xmin * (lenA - imid - 1)
            print(xmin, fmin)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import heapq
N = int(input())
st = input()
n, a, b = map(int,st.split())

minpt = [a]
minvalue = b
hq = [a]
ptnum = 1
for i in range(N-1):
  st = input()
  if st[0] == '1':#入力クエリ
    n, a, b = map(int,st.split())
    if len(minpt) == 2:#平らな区間がある
      if a < min(minpt):
        minvalue += b + abs(a -min(minpt))
        minpt = [min(minpt)] 
      elif a > max(minpt):
        minvalue += b + abs(a - max(minpt))
        minpt = [max(minpt)]
      else:
        minvalue += b
        minpt = [a]
      heapq.heappush(hq, a)
      ptnum += 1
      if ptnum%2 == 0 and hq[ptnum//2-1] != hq[ptnum//2]:
        minpt = [hq[ptnum//2-1], hq[ptnum//2]]
    else:#平らな区間がない
      #まずは平らになるかを判定する
      heapq.heappush(hq, a)
      ptnum += 1
      if ptnum%2 == 0 and hq[ptnum//2-1] != hq[ptnum//2]:
        minvalue += b + abs(a - minpt[0])
        minpt = [hq[ptnum//2-1], hq[ptnum//2]]
      else:#平らじゃないものが平らじゃないものになり続ける
        minvalue += b + abs(a - minpt[0])
        
    
  else:#シュル力クエリ
    print(min(minpt),minvalue)

Submission status: Wrong Answer

Solution code:
import bisect

Q=int(input())

b=0
a=[]
min=0
tmp=0
for i in range(Q):
    que=list(map(int,input().split()))
    if que[0]==1:
        b+=que[2]
        a.insert(  bisect.bisect_left(a,que[1]), que[1] )
        p= bisect.bisect_left(a,tmp)
        q= bisect.bisect_right(a,tmp)


        if p>len(a)-p:
            min+=abs(que[1]-tmp)-abs(a[p-1]-tmp) 
            tmp=a[p-1]
        elif q<len(a)-q:
            min+=abs(que[1]-tmp)-abs(a[q]-tmp) 
            tmp=a[q]
        else:
            min+=abs(que[1]-tmp)


    elif que[0]==2:
        print(tmp,min+b)

Submission status: Wrong Answer

Solution code:
import bisect

Q = int(input())
accb = 0
points = []
for _ in range(Q):
    q = input().split()

    if q[0] == '1':
        _, a, b = [int(i) for i in q]
        accb += b
        bisect.insort(points, a)
    else:
        acc = 0
        mid = len(points) // 2
        for j in range(mid):
            acc += points[-1-j] - points[j]
        x = points[mid]

        print("{} {}".format(x, acc + accb))

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]:
            idx = (len(A) - 1) // 2
            ans = A[idx], (sum(A[idx:]) - sum(A[:-idx]) + 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:
class BITree:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def calc(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

Q=int(input())
query=[list(map(int,input().split())) for i in range(Q)]
tmp=[]
for i in range(Q):
    seq=query[i]
    if len(seq)==1:
        continue
    else:
        tmp.append((seq[1],i))
tmp.sort()
X=[(-1,-1) for i in range(Q)]
for i,sq in enumerate(tmp):
    X[sq[1]]=(i+1,sq[0])
N=len(tmp)
Idx=BITree(N)
Clc=BITree(N)
Btm=0
nowindex=0
for i in range(Q):
    if X[i]==(-1,-1):
        left=1
        right=N
        mid=(left+right)//2
        while(left<=right):
            mid=(left+right)//2
            if Idx.calc(mid)<=(nowindex+1)//2:
                left=mid+1
            else:
                right=mid-1
        k=right
        x=(Clc.calc(k)-Clc.calc(k-1))
        ans=Clc.calc(N)-2*Clc.calc(k)-x*(Idx.calc(N)-2*Idx.calc(k))+Btm
        print(x,ans)
    else:
        Idx.add(X[i][0],1)
        Clc.add(X[i][0],X[i][1])
        Btm+=query[i][2]
        nowindex+=1

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
a = []
b_sum = 0

def f(a,x):
    return (np.array(a)-x).sum()+b_sum


for i in range(N):  
    Q = list(map(lambda x: int(x),input().split()))
    if Q[0] == 1:
        a.append(Q[1])
        b_sum += Q[2]
    else:
        x = a[int(len(a)/2)]
        print("{0} {1}".format(x,f(a,x)))

Submission status: Wrong Answer

Solution code:
q = int(input()) 
ql = [list(map(int,input().split())) for i in range(q)]
al = []
b = 0
import math
for i in range(q):
    if ql[i][0] == 1:
        al.append(ql[i][1])
        al.sort()
        b += ql[i][2]
    else:
        if 2%len(al) == 0:
            num = math.floor((len(al)/2)-1)
        else:
            num = math.floor(len(al)/2)
        x = al[num]
        ansl = []
        for k in range(len(al)):
            ansl.append(abs(x-al[k]))
        ans = sum(ansl) + b
        print(x,end = " ")
        print(ans)

Submission status: Wrong Answer

Solution code:
import statistics

Q = int(input())

a = []
b_sum = 0
minima = 0
argmin = 10**10
for i in range(Q):
    ipt = list(map(int, input().split()))
    if len(ipt) == 3:
        a.append(ipt[1])
        b_sum += ipt[2]
    else:
        argmin_new = statistics.median_low(a)
        if argmin == 10**10:
            argmin = argmin_new
        minima += a[-1] - argmin_new if argmin_new == argmin else abs(a[-1] - argmin) - (abs(argmin - argmin_new) * (len(a) % 2))
        argmin = argmin_new
        print(argmin, minima + b_sum)

Submission status: Wrong Answer

Solution code:
import heapq
N = int(input())
st = input()
n, a, b = map(int,st.split())

minpt = [a]
minvalue = b
hq = [a]
ptnum = 1
for i in range(N-1):
  st = input()
  if st[0] == '1':#入力クエリ
    n, a, b = map(int,st.split())
    if len(minpt) == 2:#平らな区間がある
      if a < min(minpt):
        minvalue += b + abs(a -min(minpt))
        minpt = [min(minpt)] 
      elif a > max(minpt):
        minvalue += b + abs(a - max(minpt))
        minpt = [max(minpt)]
      else:
        minvalue += b
        minpt = [a]
      heapq.heappush(hq, a)
      ptnum += 1
    else:#平らな区間がない
      #まずは平らになるかを判定する
      heapq.heappush(hq, a)
      ptnum += 1
      if ptnum%2 == 0 and hq[ptnum//2-1] != hq[ptnum//2]:
        minvalue += b + abs(a - minpt[0])
        minpt = [hq[ptnum//2-1], hq[ptnum//2]]
      else:#平らじゃないものが平らじゃないものになり続ける
        minvalue += b + abs(a - minpt[0])
        
    
  else:#シュル力クエリ
    print(min(minpt),minvalue)

Submission status: Wrong Answer

Solution code:
Q = int(input())
a_list = []
const = 0
output = []
for _ in range(Q):
    query = input()
    if (query[0] == "1"):
        _, a, b = list(map(int, query.split()))
        a_list.append(a)
        const += b
    else:
        sorted_a_list = sorted(a_list)
        min_x = sorted_a_list[(len(a_list)-1)//2]            
        total = sum(map(lambda a: a-min_x, sorted_a_list)) + const
        output.append([min_x, total])
for min_x, f_x in output:
    print(min_x, f_x)

Submission status: Wrong Answer

Solution code:
n=int(input())
o=lambda:map(int,input().split())
v=0
e=0
a=[];b=[]
for i in range(n):
  l=list(o())
  if len(l)>1:
    q,u,t=l
    a+=[u]
    b+=[t]
    if i==0:
      e=u
      v=t
    else:
      m=[]
      for i,p in enumerate(b):
        if p==min(b):
          u=a[i]
          t=sum(abs(c-a[i])for c in a)+sum(b)
          m+=[t]
          if min(m)==t:
            e=u
            v=t
  else:
    print(e,v)

Submission status: Wrong Answer

Solution code:
a,b=0,0
am=[]
amin=1000000000
amax=-1000000000
num=0
asum=0

def fmin(am,b,amin,amax,asum,num):
  kmin=1000000000000000000
  imin=amin
  ii=asum//num
  for i in range(ii,ii+2):
    k=0
    for j in range(num):
      k+=abs(am[j]-i)
    if kmin>k:
      kmin=k
      imin=i
  print(imin,kmin+b)
  return

for _ in range(int(input())):
  q=input()
  if q=="2":
    fmin(am,b,amin,amax,asum,num)
  else:
    t,a1,b1=map(int,q.split())
    am+=[a1]
    b+=b1
    amin=min(amin,a1)
    amax=max(amax,a1)
    asum+=a1
    num+=1

Submission status: Wrong Answer

Solution code:
import heapq
N = int(input())
st = input()
n, a, b = map(int,st.split())

minpt = [a]
minvalue = b
hq = [a]
ptnum = 1
for i in range(N-1):
  st = input()
  if st[0] == '1':#入力クエリ
    n, a, b = map(int,st.split())
    if len(minpt) == 2:#平らな区間がある
      if a < min(minpt):
        minvalue += b + abs(a -min(minpt))
        minpt = [a] 
      elif a > max(minpt):
        minvalue += b + abs(a - max(minpt))
        minpt = [a]
      else:
        minvalue += b
        minpt = [a]
      heapq.heappush(hq, a)
      ptnum += 1
    else:#平らな区間がない
      #まずは平らになるかを判定する
      heapq.heappush(hq, a)
      ptnum += 1
      if ptnum%2 == 0 and hq[ptnum//2-1] != hq[ptnum//2]:
        minvalue += b + abs(a - minpt[0])
        minpt = [hq[ptnum//2-1], hq[ptnum//2]]
      else:#平らじゃないものが平らじゃないものになり続ける
        minvalue += b + abs(a - minpt[0])
        
    
  else:#シュル力クエリ
    print(min(minpt),minvalue)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(700000)

def f(l, x):
    ret = 0
    for i in l:
        ret += abs(i-x)
    return int(ret)

def moderate(n):
    if n%1 < 5: return n//1
    else: return n//1+1

q = int(input())
s1, s2, cnt = 0, 0, 0
al = []
flag = False
for i in range(q):
    query = list(map(int, input().split()))
    if len(query) == 1:
        if cnt == 0:
            cnt, flag = 1, True
        x = int(moderate(s1/cnt))
        if cnt == 2:
            x = min(al)
        print(x, f(al, x)+s2)
        if flag:
            cnt, flag = 0, False
    else:
        a, b = query[1], query[2]
        cnt += 1
        al.append(a)
        s1 += a
        s2 += b

Submission status: Wrong Answer

Solution code:
def absolute_minima(Q: int, queries: list)->list:
    L, R = [], []
    sL, sR = 0, 0
    M = None
    B = 0
    N = 0

    res = []

    for query in queries:
        if query[0] == 1:
            _, a, b = query
            N += 1
            B += b

            if M == None:
                M = a
            else:
                if M < a:
                    R.append(a)
                    sR += a
                else:
                    L.append(a)
                    sL += a

                while len(R)-len(L) > 1:
                    L.append(M)
                    sL += M

                    M = R[0]

                    R.remove(M)
                    sR -= M

                while len(L) > len(R):
                    R.append(M)
                    sR += M

                    M = L[0]

                    L.remove(M)
                    sL -= M

        else:
            s = - sL + sR + B
            if N & 1 == 0:
                s -= M
            res.append((M, s))

    return res


if __name__ == "__main__":
    Q = int(input())
    queries = [tuple(int(s) for s in input().split()) for _ in range(Q)]

    for ans in absolute_minima(Q, queries):
        print(ans)

Submission status: Wrong Answer

Solution code:
q=int(input())
mi=1000000000000000000
z=[]
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]
        mi=min(mi,a[1])
    else:
        for j in z:
            ans+=abs(j-mi)
        print(mi,end=' ')
        print(ans+b)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

import bisect

Q = int(input())

A = []
B = 0
for _ in range(Q):
    inp = list(map(int,input().split()))
    if inp[0] == 1:
        
        index = bisect.bisect_left(A, inp[1])
        A.insert(index, inp[1])
        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:
# F問題
# 今回の式で与えられるfについて、f=Σ(|x-a_i| + b_i)とすると、(i∈[1,N], a_iはソート済みとする)
# f_min=Σa_k - Σa_l - (N-α) * a_((N+1)//2) + Σb_i  (k∈((N+1)//2,N], l∈[1,(n+1)//2], αは a_((N+1)//2)の個数)
# あるいはf_min=Σ(a_i+b_i) - 2 * Σ(a_l) - N * a_((N+1)//2) 
# その時のxはa_((N+1)//2)
# これを効率よく解けばいい

a = int(input())
list_a = []
dict_a = {}
list_sum = 0
sum_b = 0
list_count = 0
for i in range(a):
    s = input()
    if(int(s[0]) == 1):
        # 更新
        x, a, b = map(int, s.split())
        list_a.append(a)
        list_sum += a
        list_count += 1
        sum_b += b
        if(a in dict_a):
            dict_a[a] += 1
        else:
            dict_a[a] = 1
    else:
        # 求値
        list_a.sort()
        min_index = (list_count+1)//2 - 1
        dec_sum = -1 * (((dict_a[list_a[min_index]] - 1) // 2) * list_a[min_index])
        for i in range((list_count - 1) // 2):
            dec_sum += list_a[i]
        print("{} {}".format(list_a[min_index], list_sum - 2 * dec_sum - (list_count) * list_a[min_index] + sum_b))

Submission status: Wrong Answer

Solution code:
def calc(f_list, bias):
    min_val = min(f_list)
    score = sum(f_list) - min_val - ((len(f_list)-1) * min_val) + bias
    return min_val, score


if __name__ == '__main__':

    N = int(input())

    f_list = list()
    bias = 0
    for n in range(N):
        input_ = input()
        if input_ == '2':
            min_val, score = calc(f_list, bias)
            print(min_val, score)
        else:
            _, a, b = map(int, input_.strip().split())
            f_list.append(a)
            bias += b

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
Q = int(input())
m, s1, s2, q1 = 10 ** 9 + 1, 0, 0, 0
for i in range(Q):
    q = list(map(int, input().split()))
    if q[0] == 1:
        if q[1] < m:
            s1 += (m - q[1]) * q1
            m = q[1]
        s1 += q[1] - m
        s2 += q[2]
        q1 += 1
    else:
        print(m, s1 + s2)

Submission status: Wrong Answer

Solution code:
n = int(input())
li_a = []
b=0
for i in range(n):
    temp = input()
    if temp == "2":
        # li_a.sort()
        if len(li_a)%2 == 0:
            ans_a = li_a[len(li_a)//2-1]
        else:
            ans_a = li_a[(len(li_a)-1)//2]
        ans_b = 0
        for a in li_a:
            ans_b += abs(a-ans_a)
        ans_b += b
        print(ans_a,ans_b)
    else:
        z,aa,bb=temp.split(" ")
        li_a.append(int(aa))
        b+=int(bb)

Submission status: Wrong Answer

Solution code:
def calc(f_list, bias):
    min_val = min(f_list)
    score = sum(f_list) - min_val - ((len(f_list)-1) * min_val) + bias
    return min_val, score


if __name__ == '__main__':

    N = int(input())

    f_list = list()
    bias = 0
    for n in range(N):
        input_ = input()
        if input_ == '2':
            print(calc(f_list, bias))
        else:
            _, a, b = map(int, input_.strip().split())
            f_list.append(a)
            bias += b

Submission status: Wrong Answer

Solution code:
from bisect import insort_left

Q = int(input())
a_list = []
scalar = 0
for _ in range(Q):
    input_list = list(map(int,input().split()))
    if input_list[0]==1:
        a = input_list[1]
        insort_left(a_list,a)
        scalar += input_list[2]
    else:
        unique_a_list =list(set(a_list.copy())) 
        length = len(unique_a_list)
        if length%2==0:
            ans0_pos =int(length/2 - 1)

            ans0 = unique_a_list[ans0_pos]
            ans1 = sum([abs(ans0-a) for a in a_list]) + scalar
            print(str(ans0)+" "+str(ans1))
        else:
            ans0_pos = int(length/2-0.5)
            ans0 = unique_a_list[ans0_pos]
            ans1 = sum([abs(ans0-a) for a in a_list]) + scalar
            print(str(ans0)+" "+str(ans1))

Submission status: Wrong Answer

Solution code:
class BITree:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def calc(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

Q=int(input())
query=[list(map(int,input().split())) for i in range(Q)]
tmp=[]
for i in range(Q):
    seq=query[i]
    if len(seq)==1:
        continue
    else:
        tmp.append((seq[1],i))
tmp.sort()
X=[(-1,-1) for i in range(Q)]
for i,sq in enumerate(tmp):
    X[sq[1]]=(i+1,sq[0])
N=len(tmp)
Idx=BITree(N)
Clc=BITree(N)
Btm=0
nowindex=0
for i in range(Q):
    if X[i]==(-1,-1):
        left=0
        right=N
        mid=(left+right)//2
        while(left<=right):
            mid=(left+right)//2
            if Idx.calc(mid)<=(nowindex+1)//2:
                left=mid+1
            else:
                right=mid-1
        x=(Clc.calc(right)-Clc.calc(right-1))
        ans=Clc.calc(N)-2*Clc.calc(right)-x*(Idx.calc(N)-2*Idx.calc(right))+Btm
        print(x,ans)
    else:
        Idx.add(X[i][0],1)
        Clc.add(X[i][0],X[i][1])
        Btm+=query[i][2]
        nowindex+=1

Submission status: Wrong Answer

Solution code:
q=int(input())
mi=1e12
z=[]
za=0
c=0
b=0
for i in range(q):
    ans=0
    a=list(map(int,input().split()))
    if len(a)==3:
        c+=1
        z.append(a[1])
        b+=a[2]
        if mi!=1e12 and mi<=a[1]:
            za+=abs(a[1]-mi)
        elif mi!=1e12:
            za+=(c-1)*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())

asum = 0
amin = 10 ** 9
anum = 0
bsum = 0

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

Submission status: Wrong Answer

Solution code:
class BITree:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def calc(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

Q=int(input())
query=[list(map(int,input().split())) for i in range(Q)]
tmp=[]
for i in range(Q):
    seq=query[i]
    if len(seq)==1:
        continue
    else:
        tmp.append((seq[1],i))
tmp.sort()
X=[(-1,-1) for i in range(Q)]
for i,sq in enumerate(tmp):
    X[sq[1]]=(i+1,sq[0])
N=len(tmp)
Idx=BITree(N)
Clc=BITree(N)
Btm=0
nowindex=0
#print(X)
for i in range(Q):
    if X[i]==(-1,-1):
        #print(nowindex)
        left=0
        right=N
        mid=(left+right)//2
        while(left<=right):
            mid=(left+right)//2
            if Idx.calc(mid)<=(nowindex+1)//2:
                left=mid+1
            else:
                right=mid-1
        x=(Clc.calc(right)-Clc.calc(right-1))
        p,q=(Idx.calc(N)-Idx.calc(right),Idx.calc(right))
        r,s=(Clc.calc(N)-Clc.calc(right),Clc.calc(right))
        ans=Clc.calc(N)-2*Clc.calc(right)-x*(Idx.calc(N)-2*Idx.calc(right))+Btm
        print(x,ans)
    else:
        Idx.add(X[i][0],1)
        Clc.add(X[i][0],X[i][1])
        Btm+=query[i][2]
        nowindex+=1
        #print("a",[Idx.calc(i+1)-Idx.calc(i) for i in range(N)])
        #print("b",[Clc.calc(i+1)-Clc.calc(i) for i in range(N)])

Submission status: Wrong Answer

Solution code:
import bisect
Q=int(input())

median=0
alist=[]
nowb=0
nowa=0
for _ in range(Q):
  p=list(map(int,input().split()))
  if p[0]==1:
    a,b=p[1],p[2]
    bisect.insort_left(alist,a)
    l=len(alist)
    if l!=1:
      if l%2==0:
        medianid=(l-1)//2
      else:
        medianid=l//2
      #print(medianid)
      bmedian=median
      median=alist[medianid]
      if median<bmedian:
        #print('x')
        #print(bmedian,median,l,medianid)
        nowa+=(bmedian-median)*((l-1)-medianid)
        if medianid!=0:
          nowa-=(median-alist[medianid-1])*(medianid)
      elif median==bmedian:
        nowa+=abs(a-median)
      else:
        nowa+=(median-bmedian)*(medianid)
        nowa-=(alist[medianid+1]-median)*((l-1)-medianid)
        
    else:
      median=a    
    #print(alist)
    nowb+=b
  else:
    print(median,nowa+nowb)

Submission status: Wrong Answer

Solution code:
Q = int(input())

asum = 0
amin = 10 ** 9
anum = 0
bsum = 0

for i in range(Q):
    query = list(map(int, input().split()))
    if query[0] == 1:
        a = abs(query[1])
        asum += a
        amin = min(a, amin)
        anum += 1
        bsum += query[2]
    elif query[0] == 2:
        fx = asum - amin * anum + bsum
        print(amin, 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:]:
        # print(center_index)
        # print(state)
        # print(a_list)
        # print(b_sum)
        # print()
        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
            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
            a_list.insert(insert_index, que[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:
# 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つうつす
      L_size -= 1
      R_size += 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つうつす
      R_size -= 1
      L_size += 1
      x = heapq.heappop(R)
      heapq.heappush(L,-x)
      R_min = heapq.nsmallest(1,R)[0]
      L_max = 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()