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:
# -*- coding: utf-8 -*-
"""
Created on Sat May 25 21:57:15 2019

@author: Yamazaki Kenichi
"""
import bisect

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

ans = []
A = []
B = 0
C = 0
counta = 0
d, prea, b = map(int,Q2[0].split()) 
for q in Q2:
    if q[0] == '1':
#        input
        d, a, b = map(int,q.split()) 
        bisect.insort_left(A,a)
#        if A[(len(A)-1)//2] > a:
#            C = abs(prea - a)
#        else:
#            C = abs(A[(len(A)-1)//2] - a)
        C = abs(A[(len(A)-1)//2] - a) if counta % 2 == 1 else abs(prea - a)
        B += (b + C)
#        C = abs(prea - a)
        prea = A[(len(A)-1)//2]
        counta += 1
    else:
#        output
        tmp = A[(len(A)-1)//2]
        ans.append([tmp,B])
for c in ans:
    print(' '.join(map(str,c)))

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left as bl
d=[]
c,r=0,0
for i in range(int(input())):
    s=list(map(str,input().split()))
    if s[0]=="1":
        e,f=int(s[1]),int(s[2])
        c+=f
        d.insert(bl(d,e),e)
        r+=1
    else:
        if r%2==0:
            s=d[r//2-1]
            p=sum(d[r//2:])-sum(d[:r//2])
        else:
            s=d[r//2]
            p=sum(d[r//2+1:])-sum(d[:r//2])
        print(s,p+c)
print(d)

Submission status: Wrong Answer

Solution code:
Q = int(input())
A=0
B=0
j=0
for i in range(Q):
    s = input()
    if s[0] == "1":
        j+=1
        x, a, b = map(int, s.split())
        A += a
        B += b
    else:
        
        average = A/(j)
        print(int(average), int(A - average + B))

Submission status: Wrong Answer

Solution code:
import bisect
Q=int(input())
A=[]
B=0
s,t,lA=0,0,0
for i in range(Q):
  S=input()
  if S[0]=="1":
    a,b=map(int,S[2:].split())
    k=bisect.bisect_left(A,a)
    if lA%2==1:
      if k>=lA//2+1:
        t+=a
        s+=A[lA//2]
      else:
        s+=a
        t+=A[lA//2]
    else:
      if lA==0:
        z=0
      elif k>lA//2:
        t+=a-A[lA//2]
      elif k<lA//2:
        s+=a-A[lA//2]
    bisect.insort_left(A,a)
    lA+=1
    B+=b
  else:
    if lA%2==0:
      
      print(A[lA//2-1],t-s+B)
    else:
      print(A[lA//2],t-s+B)

Submission status: Wrong Answer

Solution code:
# coding:utf-8

import math
import re

def main(params):
    q = params[0]
    queries = params[1:]
    currentB = 0
    listA = []
    for i in queries:
        line = i.split()
        if len(line) > 1:
            code, a, b = i.split()
            code = int(code)
            a = int(a)
            b = int(b)
            currentB += b
            listA.append(a)
        else:
            listA.sort()
            target = len(listA)/2
            if len(listA)%2 != 0:
                target -= 1
            t = 0
            for j in listA:
                t += abs(listA[target] - j)
            t += currentB
            print listA[target],t


if __name__ == "__main__":
    q = raw_input()
    q = int(q)
    cnt = q # TODO: edit here
    params = [q]
    for i in range(cnt):
        param = raw_input()
        params.append(param)
    main(params)

Submission status: Wrong Answer

Solution code:
import heapq

q = int(input())

alist = []
n = 0
bsum = 0
count = 0

for i in range(q):
    query = input()
    if query[0] == '1':
        que = query.split()
        a = int(que[1])
        b = int(que[2])
        heapq.heappush(alist, a)
        bsum += b
        n += 1
        if count == 0:
            f = 0
            m = n//2
            mid = alist[n//2]
            count += 1
        else:
            f += abs(mid - alist[n//2]) * (m - (n-2 - m)) + abs(alist[n//2] - a)
            mid = alist[n//2]
            m = n // 2
    else:
        if len(alist) == 0:
            print(0, 0)
            continue
        x = alist[n//2]
        print(x, f+bsum)

Submission status: Wrong Answer

Solution code:
import statistics
q = int(input())
query = [list(map(int,input().split())) for i in range(q)]
a = []
b = 0
c = 0

for i in range(q):
    if query[i][0] == 1:
        a.append(query[i][1])
        b += query[i][2]
    else:
        a2 = statistics.median(a)
        c = 0
        for j in range(len(a)):
            c += abs(a[j]-a2)
        print(a2,c+b)

Submission status: Wrong Answer

Solution code:
class func:
    def __init__(self):
        self.a = []
        self.b = 0

    def renew(self, a, b):
        tmp_len = len(self.a)
        if tmp_len == 0:
            self.a.append(a)
        else:
            for i in range(tmp_len):
                if self.a[i] >= a:
                    self.a.insert(i, a)
        self.b += b

    def calc(self, x):
        ans = 0
        for i in self.a:
            ans += abs(x - i)
        ans += self.b
        return ans

    def min_f(self):
        x = self.a[int(len(self.a)/2)-1]
        return x, self.calc(x)

Q = int(input())

f = func()

ans = []

for i in range(Q):
    query = input()
    if query[0] == "1":
        tmp, a, b = map(int, query.split())
        f.renew(a, b)
    else:
        x, f_x = f.min_f()
        ans.append([x, f_x])

for row in ans:
    print(row[0], row[1])

Submission status: Wrong Answer

Solution code:
def solve():
    F = [0, 0]
    cnt = 0
    fb = 0
    for _ in range(int(input())):
        Q = input()
        if Q == '2':
            if cnt == 0:
                print(0, 0)
            else:
                print(F[0], F[1] + fb)
        else:
            _, a, b = map(int, Q.split())
            if cnt != 0:
                if F[0] > a:
                    F[1] += abs(F[0] - a) * cnt
                    F[0] = a
                else:
                    F[1] += abs(a - F[0])
            else:
                F = [a, 0]
            cnt += 1
            fb += b
solve()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
b=0
ma=0
m=0
for i in range(n):
    q=list(map(int,input().split()))
    if q[0]==1:
        a.append(q[1])
        a.sort()
        b+=q[2]
        if len(a)%2==0:
            ind=len(a)//2-1
            ma=a[ind]
            m=-sum(a[:ind])+sum(a[ind:])+b
        else:
            ind=len(a)//2
            ma=a[ind]
            m=-sum(a[:ind-1])+sum(a[ind:])+b
        
    elif q[0]==2:
        print(ma,m)

Submission status: Wrong Answer

Solution code:
from io import StringIO
from collections import *
from functools import *
import sys


def main(inputs):
    q = int(next(inputs))
    # xs = list(map(int, next(inputs).split()))
    an = []
    bn = 0
    for _ in range(q):
        s = next(inputs)
        if s[0] == "1":
            _, a, b = map(int, s.split())
            an.append(a)
            bn += b
            pass
        else:
            # (x-an[i])^2 が最小
            # 2x - 2*an[i] = 0
            # 2*n*x - 2*(an[0..n-1]) = 0
            # x = an[0..n-1] // n
            x = sum(an) // len(an)
            v = bn + sum([ abs(x - a) for a in an ])
            while True:
                if v == bn + sum([ abs(x-1 - a) for a in an ]):
                    x = x - 1
                else:
                    break
                pass
            print("{} {}".format(x, v))
            pass
        pass
    pass


def gen_inputs(str_=None):
    inputs = StringIO(str_) if str_ else sys.stdin
    while True:
        a = inputs.readline().rstrip()
        yield a
        pass
    pass


if __name__ == "__main__":
    main(gen_inputs())
    pass

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import bisect


Q = int(input())
Alist = []
S = 0
Bsum = 0
Qs = [input() for _ in range(Q)]
for query in Qs:
    if query[0] == "1":
        _, a, b = map(int, query.split(" "))
        Bsum += b
        Alist.insert(bisect.bisect_left(Alist, a), a)
        S += a
    else:
        key = len(Alist)
        S2 = S
        minx = Alist[0]
        tempAns = S - key * minx
        for i, a in enumerate(Alist):
            if i % 2 == 0 and i != 0:
                continue
            tempAns2 = S2 - key * a
            if tempAns > tempAns2:
                tempAns = tempAns2
                minx = a
            S2 += - 2 * a
            key -= 2
        tempAns2 = S2 - key * a
        if tempAns > tempAns2:
            tempAns = tempAns2
            minx = a
        print(str(minx) + " " + str(tempAns+Bsum))

Submission status: Wrong Answer

Solution code:
n = int(input())
A = []
f = 0
for i in range(n):
    P = list(map(int,input().split())) 
    if P[0]== 1:
        A.append(P[1])
        f += P[2]
    else:
        A.sort()
        res = 0
        for a in A:
            res += abs(a-A[len(A)//2]) 
        print(A[len(A)//2],f+res)

Submission status: Wrong Answer

Solution code:
import sys  
input = sys.stdin.readline

Q = int(input())
ans = []
b = 0
ab = []
def ab_sum(a, center):
    length = len(a)
    a.sort()
    if length == 2:
        center = 0
        return a[1] - a[0]
    elif length == 1:
        center = 0
        return 0
    elif length % 2 == 0:
        center = length//2
        return sum(a[1+center:]) - sum(a[:center])
    else:
        center = length / 2
        return sum(a[center+1:]) - sum(a[:center])




for i in range(Q):
    a = list(map(int, input().split()))
    
    if len(a) == 1:
        if len(ab) %2 == 0:
            ab.sort()
            center = 0
            ss = ab_sum(ab, center)
            
            print(ab[center] ,b + ss)
    else:
        b += a[2]
        ab.append(a[1])

Submission status: Wrong Answer

Solution code:
import heapq

q = int(input())

alist = []
n = 0
bsum = 0
count = 0

for i in range(q):
    query = input()
    if query[0] == '1':
        que = query.split()
        a = int(que[1])
        b = int(que[2])
        heapq.heappush(alist, a)
        bsum += b
        n += 1
        if count == 0:
            f = 0
            m = n//2
            mid = alist[n//2]
            count += 1
        else:
            f += abs(mid - alist[n//2]) * (m - (n-1 - m)) + abs(alist[n//2] - a)
            mid = alist[n//2]
            m = n // 2
    else:
        if len(alist) == 0:
            print(0, 0)
            continue
        x = alist[n//2]
        print(x, f+bsum)

Submission status: Wrong Answer

Solution code:
import heapq
Q = int(input())
B = 0

L, R = [], []
L_sum, R_sum = 0, 0
fq, fa, fb = map(int, input().split())
Median = fa
B = fb


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

        A = q[1]
        if A <= Median:
            heapq.heappush(R, Median)
            R_sum += Median
            L_sum += A
            Median = -heapq.heappushpop(L, -A)
            L_sum -= Median
            #print(L, R, L_sum, R_sum)
        else:
            heapq.heappush(L, -Median)
            L_sum += Median
            R_sum += A
            Median = heapq.heappushpop(R, A)
            R_sum -= Median

    else:
        print(Median, abs(L_sum - (len(L) * Median)) + abs(R_sum - (len(R) * Median)) + B)

Submission status: Wrong Answer

Solution code:
Q = int(input())
ans = 0
a_set = set()
b_sum = 0
for i in range(Q):
    s = input()
    if s == '2':
        print(ans)
    else:
        one,a,b = map(int,s.split())
        b_sum += b
        a_set.add(a)
        a_list = list(a_set)
        if len(a_set)%2 == 1:
            min_x = a_list[len(a_set)//2]
        else:
            min_x = a_list[len(a_set)//2-1]
        ans_1 = 0
        for j in range(len(a_set)):
            ans_1 += abs(a_list[j]-min_x)
        ans = str(min_x)+" "+ str(ans_1+b_sum)

Submission status: Wrong Answer

Solution code:
def solve():
    F = [0, 0]
    cnt = 0
    fb = 0
    for _ in range(int(input())):
        Q = input()
        if Q == '2':
            if cnt == 0:
                print(0, 0)
            else:
                print(F[0], F[1] + fb)
        else:
            _, a, b = map(int, Q.split())
            if cnt != 0:
                if F[0] > a:
                    F[1] += abs(F[0] - a) * cnt
                    F[0] = a
                else:
                    F[1] += a - F[0]
            else:
                F = [a, 0]
            cnt += 1
            fb += b
solve()

Submission status: Wrong Answer

Solution code:
argQ = int(input())
flgFirst = True
aryA = []
argB = 0
for i in range(argQ):
  wk = list(map(int,input().split()))
  if wk[0] == 1:
    flgFirst = False
    aryA.append(wk[1])
    argB += wk[2]
  else:  # wk[0] == 2
    if flgFirst == True:
      ans1 = 0
      ans2 = 0
    else:
      ans1 = min(aryA)
      ans2 = argB
      for i in range(len(aryA)):
        ans2 += abs(ans1 - aryA[i])
    print(str(ans1) + " " + str(ans2))

Submission status: Wrong Answer

Solution code:
import heapq

q = int(input())

alist = []
n = 0
bsum = 0
count = 0

for i in range(q):
    query = input()
    if query[0] == '1':
        que = query.split()
        a = int(que[1])
        b = int(que[2])
        heapq.heappush(alist, a)
        bsum += b
        n += 1
        if count == 0:
            f = 0
            m = n//2
            mid = alist[n//2]
            count += 1
        else:
            f += abs(mid - alist[n//2]) * (m - (n - m)) + abs(alist[n//2] - a)
            mid = alist[n//2]
            m = n // 2
    else:
        if len(alist) == 0:
            print(0, 0)
            continue
        x = alist[n//2]
        print(x, f+bsum)

Submission status: Wrong Answer

Solution code:
from heapq import heappop, heappush

def getlist():
	return list(map(int, input().split()))

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

f, a, b = getlist()
heappush(A, a)
B += b
val = a
ans1 = 0
for i in range(Q - 1):
	x = getlist()
	if x[0] == 1:
		a, b = x[1], x[2]
		if n % 2 == 0:
			ans1 += abs(A[int(n // 2) - 1] - a)
		else:
			ans1 += abs(A[int((n + 1) // 2) - 1] - a)
		heappush(A, a)
		B += b
		n += 1

	else:
		if n % 2 == 0:
			X = A[int(n // 2) - 1]
		else:
			X = A[int((n + 1) // 2) - 1]
		print(X, ans1 + B)

Submission status: Wrong Answer

Solution code:
import bisect

points = []
b = 0

Q = int(input())

for _ in range(Q):
    query = input()
    if query.startswith('1'):
        _, an, bn = [int(x) for x in query.split()]
        bisect.insort_left(points, an)
        b += bn
    elif query.startswith('2'):
        length = len(points)
        if length % 2 == 1:
            print(points[length // 2], b)
        else:
            t = points[length // 2] - points[length // 2 - 1]
            print(points[length // 2 - 1], b + t)

Submission status: Wrong Answer

Solution code:
b=0
am=[]
num=0
asum=0

def fmin(am,b,asum,num):
  ii=asum//num
  k=0
  imax=-1000000000
  for i in am:
    if i<=ii:
      imax=max(imax,i)
      k+=int(ii)-i
    else:
      k+=i-int(ii)
  print(imax,k+b)
  return

for _ in range(int(input())):
  q=input()#2*10^5
  if q=="2":
    fmin(am,b,asum,num)
  else:
    t,a1,b1=map(int,q.split())
    am+=[a1]
    b+=b1
    asum+=a1
    num+=1

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

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

        print(a[idx], b + v)

Submission status: Wrong Answer

Solution code:
import heapq
Q = int(input())
heap = []

for _ in range(Q):
  s = input()
  if len(s) > 1:
    a= int(s.split()[1]) 
    heapq.heappush(heap,a)
  else:
    if len(heap) % 2 is 0:
      print(heap[len(heap)//2-1])
    else:
      print(heap[len(heap)//2])

Submission status: Wrong Answer

Solution code:
import heapq

q=int(input())
a=[]
heapq.heapify(a)
sum_b=0
for _ in range(q):
    qi=list(map(int,input().split()))
    if qi[0]==1:
        heapq.heappush(a,qi[1])
        sum_b+=qi[2]
    else:
        m=a[len(a)//2]
        print(m,sum_b+sum(abs(x-m) for x in a))

Submission status: Wrong Answer

Solution code:
Q = int(input())
A = []
B = 0
def insert(A, a, lower, upper):
  if upper - lower == 1:
    A = A[:upper] + [a] + A[upper:]
  else:
    mid = (lower + upper) // 2
    if A[mid] == a:
      A = A[:mid] + [a] + A[mid:]
    elif A[mid] > a:
      insert(A, a, lower, mid)
    else:
      insert(A, a, mid, upper)
for q in range(Q):
  q = [int(x) for x in input().split()]
  if q[0] == 1:
    if len(A) == 0:
      A = [q[1]]
    elif A[0] >= q[1]:
      A = [q[1]] + A
    elif A[-1] <= q[1]:
      A = A + [q[1]]
    else:
      insert(A, q[1], 0, len(A))
    B += q[2]
  else:
    if len(A) == 0:
      print(0, 0)
    else:
      k = (len(A) - 1) // 2
      print(A[k], sum([abs(a - A[k]) for a in A]) + B)

Submission status: Wrong Answer

Solution code:
def bin_search(lis, x):
    l = 0
    r = len(lis)
    while(True):
        m = (l+r)//2
        if (r-l <= 1):
            break
        elif (lis[m] <= x):
            l = m
        else:
            r = m
    return m+1

q = int(input())
b_sum = 0
a_sum = 0
a_list = []
center = 0
for i in range(q):
    s = input()
    if s[0] == '1':
        trash, a, b = map(int, s.split())
        idx = 0
        if i == 0:
            center = a
        else:
            idx = bin_search(a_list, a)
        a_list.insert(idx, a)
        if len(a_list)%2 == 1 and idx >= len(a_list)//2:
            a_sum += a_list[idx] - a_list[len(a_list)//2]
        else:
            a_sum += abs(center - a_list[idx])
        center = a_list[len(a_list)//2]
        b_sum += b
    else:
        print("%d %d" % (center, a_sum + b_sum))

Submission status: Wrong Answer

Solution code:
import heapq
Q = int(input())
B = 0

L, R = [], []
L_sum, R_sum = 0, 0
fq, fa, fb = map(int, input().split())
Median = fa
B = fb


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

        A = q[1]
        if A <= Median:
            heapq.heappush(R, Median)
            R_sum += Median
            L_sum -= A
            Median = -heapq.heappushpop(L, -A)
            L_sum += Median
            #print(L, R, L_sum, R_sum)
        else:
            heapq.heappush(L, -Median)
            L_sum -= Median
            R_sum += A
            Median = heapq.heappushpop(R, A)
            R_sum -= Median

    else:
        print(Median, abs((-L_sum) + (len(L) * Median)) + abs(R_sum - (len(R) * Median)) + B)

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
        history.sort()
        if len(history) > 0:
            x = history[int(len(history) / 2) - 1]
        else:
            x = a
        for i in range(len(history)):
            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 math
import bisect

def read():
    Q = int(input().strip())
    query = []
    for i in range(Q):
        q = list(map(int, input().strip().split()))
        if q[0] == 1:
            query.append(tuple(q))
        else:
            query.append((q[0], 0, 0))
    return Q, query


def solve(Q, query):
    A = []
    B_sum = 0
    for q, a, b in query:
        if q == 1:
            A.insert(bisect.bisect_left(A, a), a)
            B_sum += b
        elif q == 2:
            a_min = A[0]
            a_max = A[-1]
            height = math.ceil((a_max - a_min) / 2)
            x = A[max(bisect.bisect_left(A, a_max - height) - 1, 0)]
            a_sum = 0
            for a in A:
                a_sum += abs(x - a)
            y = a_sum + B_sum
            print("%d %d" % (x, y))


if __name__ == '__main__':
    inputs = read()
    solve(*inputs)

Submission status: Wrong Answer

Solution code:
import bisect as bs

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

b = 0
for i in range(int(input())):
  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(sumd+b))
    else:
      t = a[l//2]
      #print("memo",a,b,l,t,sum0,sum1)
      print(str(t)+" "+str(sumd+t+b))
  else:
    b += z[2]
    k = z[1]
    i = bs.bisect_left(a,k)
    if l%2 == 0:
      if i <= l//2:
        # sum0 += k
        sumd += -k
      else:
        t = a[l//2]
        # sum0 += t
        # sum1 += k - t
        sumd = k - 2*t
    else:
      if i < l//2+1:
        t = a[l//2]
        #sum0 += k - t
        #sum1 += t
        sumd += 2*t-k
      else:
        # sum1 += k
        sumd += k
    a.insert(i,k)
    l += 1

#print(a)
#print(b)
#print(sumd)

Submission status: Wrong Answer

Solution code:
n=int(input())
y=[]
x=0
for i in range(n):
    I=input()
    if I[0]==str(1):
        a,b,c=map(int,I.split())
        x=(x+b)/2
        y.append(c)
    else:
        x=int(x)
        if len(y)>1:
            print(int(x),sum(abs(i-x) for i in y[:-1])-c)
        else:
            print(b,y[0])

Submission status: Wrong Answer

Solution code:
import heapq

q = int(input())

alist = []
n = 0
bsum = 0
count = 0

for i in range(q):
    query = input()
    if query[0] == '1':
        que = query.split()
        a = int(que[1])
        b = int(que[2])
        heapq.heappush(alist, a)
        bsum += b
        n += 1
        if count == 0:
            f = 0
            mid = alist[n//2]
            count += 1
        else:
            f += abs(mid - alist[n//2]) * (n//2 - (n - n//2)) + abs(alist[n//2] - a)
            mid = alist[n//2]
    else:
        if len(alist) == 0:
            print(0, 0)
            continue
        x = alist[n//2]
        print(x, f+bsum)

Submission status: Wrong Answer

Solution code:
class func:
    def __init__(self):
        self.a = []
        self.b = 0

    def renew(self, a, b):
        tmp_len = len(self.a)
        if tmp_len == 0:
            self.a.append(a)
        else:
            for i in range(tmp_len):
                if self.a[i] > a:
                    self.a.insert(i, a)
        self.b += b

    def calc(self, x):
        ans = 0
        for i in self.a:
            ans += abs(x - i)
        ans += self.b
        return ans

    def min_f(self):
        x = self.a[int(len(self.a)/2)-1]
        return x, self.calc(x)

Q = int(input())

f = func()

ans = []

for i in range(Q):
    query = input()
    if query[0] == "1":
        tmp, a, b = map(int, query.split())
        f.renew(a, b)
    else:
        x, f_x = f.min_f()
        ans.append([x, f_x])

for row in ans:
    print(row[0], row[1])

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
Q = int(input())
_, a, b = map(int, input().split())
vs = [-10**9, a, 10**9]
m = b

odd = True
for _ in range(Q-1):
  q = input()
  if q[0] == '1':
    _, a, b = map(int, q.split())
    if odd:
      midx = (len(vs) - 1) // 2
      m += abs(vs[midx] - a) + b
    else:
      midx = (len(vs) - 1) // 2
      m += min(abs(vs[midx] - a), abs(vs[midx+1] - a)) + b
    idx = bisect_left(vs, a)
    vs = vs[:idx] + [a] + vs[idx:]
    odd = not odd
  else:
    midx = (len(vs) - 1) // 2
    print(vs[midx], m)

Submission status: Wrong Answer

Solution code:
def solve():
    F = [0, 0]
    cnt = 0
    fb = 0
    for _ in range(int(input())):
        Q = input()
        if Q == '2':
            if cnt == 0:
                print(0, 0)
            else:
                print(F[0], F[1] + fb)
        else:
            _, a, b = map(int, Q.split())
            if cnt != 0:
                if F[0] > a:
                    F[1] += (F[0] - a) * cnt
                    F[0] = a
                else:
                    F[1] += a - F[0]
            else:
                F = [a, 0]
            cnt += 1
            fb += b
solve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
Q = int(input())
s = 0
l = []
ans = []
for i in range(Q):
    q = input()
    if q[0]=='1':
        a,b,c = map(int,q.split())
        l.append(b)
        s += c
    else:
        l.sort()
        k = max(0,len(l)//2-1)
        g = 0
        for j in l:
            g += abs(j-l[k])
        ans.append([l[k],g+s])
for m in ans:
    print(m[0],m[1])

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
inf = float('inf')
mod = 10**9+7


def INT_(n): return int(n)-1


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


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [input() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')


def main():
    from heapq import heappush, heappushpop
    Q = I()
    h = []
    size = 0
    cnt = 0
    _, a, b = MI()
    heappush(h, a)
    B = b
    A_list = [a]

    def solve(n):
        ans = 0
        for a in A_list:
            ans += abs(a - n)

        return B+ans
    for _ in range(Q-1):
        inp = input()
        if inp[0] == "1":
            q, a, b = map(int, inp.split())
            if q == 1:
                size += 1
                B += b
                A_list.append(a)
                if cnt % 2 == 0:
                    heappush(h, a)
                else:
                    heappushpop(h, a)
        else:
            print(h[0], solve(h[0]))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def absolute_minima():
    Q = int(input())

    L, R = [], []
    sL, sR = 0, 0
    M = None
    B = 0
    N = 0

    for _ in range(Q):
        query = [int(s) for s in input().split()]

        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
            print(M, s)


if __name__ == "__main__":
    absolute_minima()

Submission status: Wrong Answer

Solution code:
Q = int(input())
s = 0
l = []
ans = []
for i in range(Q):
    q = input()
    if q[0]=='1':
        a,b,c = map(int,q.split())
        l.append(b)
        l.sort()
        s += c
    else:
        k = max(0,len(l)//2-1)
        g = 0
        for j in l:
            g += abs(j-l[k])
        ans.append([l[k],g+s])
for m in ans:
    print(m[0],m[1])

Submission status: Wrong Answer

Solution code:
Q = int(input())
b = 0
a = 0
A = []
for i in range(Q):
    q = list(map(int,input().split()))
    if q[0] == 1:
        a += q[1]
        A.append(q[1])
        b += q[2]
    elif q[0] == 2:
        x = a//i
        ans = 0
        for item in A:
            ans += abs(item-x)
        print(x,ans+b)

Submission status: Wrong Answer

Solution code:
from sys import stdin

def main():
    q = int(stdin.readline())

    alist = []
    b = 0

    for i in range(q):
        s = stdin.readline()

        if s[0] == '1':
            _,_a,_b = [int(x) for x in s.split()]
            alist.append(_a)
            b += _b
        else:
            x = min(alist)
            fx = sum(abs(x-a) for a in alist) + b
            print(x,fx)
    
if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
Q = int(input())
c = 0
b = 0
a = []
sum_a = 0
sum_a_mae = 0
sum_b = 0
def append_a(n):
	if c == 0:
		a.append(n)
		return
	l,r = 0,c
	while r - l > 1:
		p = (l+r)//2
		if a[p] >= n:
			r = p
		else:
			l = p
	a.insert(l, n)

for i in range(Q):
	s = input()
	if s[0] == '1':
		x,y,z = map(int, s.split())
		if c > 0:
			a_med = a[c//2] if c % 2 == 1 else a[c//2-1]
		else:
			a_med = 0
		sum_a += y
		sum_b += z
		append_a(y)
		c += 1
		if c % 2 == 0:
			if y < a_med:
				sum_a_mae += y
			else:
				sum_a_mae += a_med
	else:
		print(a[c//2 - (1 - c%2)], sum_b + sum_a - 2*sum_a_mae - (c%2) * a[c//2])