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:
#!/usr/bin/env python3



# 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():
    # Failed to predict input format
    N = int(input())
    Q = [ list(map(int,input().split())) for i in range(N) ]

    amin = float("inf")
    a_abs_sum = 0
    acnt = 0
    b = 0
    for q in Q:
        if q[0] == 1:
            amin = min(amin,q[1])
            a_abs_sum += q[1]
            acnt += 1
            b += q[2]
        else:
            print(amin, a_abs_sum - acnt*amin + b)




    pass

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
import bisect
q=[]
a=[]
b=0
l=0
ans=0
sal=0
sar=0
for _ in range(n):
    p=[int(i) for i in input().split()]
    if p[0]==1:
        b+=p[2]
        insert_index = bisect.bisect_left(a,p[1])  
        a.insert(insert_index,p[1])
        if insert_index<l//2 and l%2==0:
            sal+=p[1]-a[l//2]
        elif insert_index<l//2 and l%2==1:
            sal+=p[1]
            sar+=a[l//2+1]
        elif insert_index==l//2 and l%2==1:
            sal+=p[1]
            sar+=a[l//2+1]
        elif insert_index==l//2 and l%2==0:
            sal+=0
        elif insert_index>l//2 and l%2==0:
            sar+=p[1]-a[l//2+1]
        elif insert_index<l//2 and l%2==1:
            sar+=p[1]
            sal+=a[l//2+1]
        elif insert_index==l//2 and l%2==1:
            sar+=p[1]
            sal+=a[l//2+1]
        elif insert_index==l//2 and l%2==0:
            sar+=0
        l+=1
    if p[0]==2:
        if l%2==0:
            al=a[0:l//2]
            ar=a[l//2:l]
            print(a[l//2-1],sar-sal+b)
        else:
            al=a[0:l//2]
            ar=a[l//2+1:l]
            c=a[l//2]
            print(c,sar-sal+b)

Submission status: Wrong Answer

Solution code:
import heapq
import math

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

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

Submission status: Wrong Answer

Solution code:
q=int(input())
f=0
a=[]
for _ in range(q):
    que=list(map(int,input().split()))
    if que[0]==2:
        a=sorted(a)
        l=len(a)
        if l%2==0:
            key=a[l//2-1]
            for i in range(l):
                f+=abs(key-a[i])
        else:
            key=a[l//2]
            for i in range(l):
                f+=abs(key-a[i])
        print(key,f)
    else:
        a.append(que[1])
        f=f+que[2]

Submission status: Wrong Answer

Solution code:
import bisect
Q = int(input())
A = []
sumb = 0
N = 0
ans = []
for i in [0]*Q:
	inp = list(map(int,input().split(' ')))
	if inp[0] == 1:
		N += 1
		a,b = inp[1:]
		sumb += b
		bisect.insort(A,a)
	else:
		n = -(-N//2)-1
		x = A[n]
		s = 0
		t = 0
		if n > 0:
			s = x*(n-1)-sum(A[:n-1])
		if n < N-1:
			t = sum(A[n+1:]) - x*(N-(n+1))
		ans.append((x,s+t+sumb))

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

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 len(a) == 0:
		a.append(n)
		return
	l,r = 0,len(a)
	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])

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("%ld %ld" % (center, a_sum + b_sum))

Submission status: Wrong Answer

Solution code:
import statistics

q=int(input())
a=[]
len_a=0
sum_a=0
sum_b=0
for _ in range(q):
    qi=list(map(int,input().split()))
    if qi[0]==1:
        a.append(qi[1])
        sum_a+=qi[1]
        sum_b+=qi[2]
        len_a+=1
    else:
        m=statistics.median_low(a)
        print(m,sum_b+sum_a-m*len_a)

Submission status: Wrong Answer

Solution code:
import heapq
import math

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

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

Submission status: Wrong Answer

Solution code:
import heapq

def main(): 
    smaller = []
    larger = []

    smallsum = 0
    largesum = 0

    const = 0

    q = int(input())
    for _ in range(q):
        inp = input()
        if inp[0] == '1':
            _,a,b = [int(x) for x in inp.split()]
            const += b

            if not smaller:
                smaller.append(-a)
                smallsum += a

            elif a <= -smaller[0]:
                heapq.heappush(smaller, -a)
                smallsum += a

            else:
                heapq.heappush(larger, a)
                largesum += a

            while len(smaller)>len(larger):
                a = -heapq.heappop(smaller)
                smallsum -= a
                heapq.heappush(larger, a)
                largesum += a
            while len(larger)>len(smaller):
                a = heapq.heappop(larger)
                largesum -= a
                heapq.heappush(smaller,-a)
                smallsum += a

        else:
            x = -smaller[-1] if smaller else 0
            print x, const + len(smaller)*x - smallsum + largesum - len(larger)*x



######## Python 2 and 3 footer by Pajenegod and c1729

# Note because cf runs old PyPy3 version which doesn't have the sped up
# unicode strings, PyPy3 strings will many times be slower than pypy2.
# There is a way to get around this by using binary strings in PyPy3
# but its syntax is different which makes it kind of a mess to use.

# So on cf, use PyPy2 for best string performance.

py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange

import os, sys
from io import IOBase, BytesIO

BUFSIZE = 8192
class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill(): pass
        return super(FastIO,self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill(); self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s:self.buffer.write(s.encode('ascii'))
            self.read = lambda:self.buffer.read().decode('ascii')
            self.readline = lambda:self.buffer.readline().decode('ascii')


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = sys.stdin.readline

# Cout implemented in Python
import sys
class ostream:
    def __lshift__(self,a):
        sys.stdout.write(str(a))
        return self
cout = ostream()
endl = '\n'

# Read all remaining integers in stdin, type is given by optional argument, this is fast
def readnumbers(zero = 0):
    conv = ord if py2 else lambda x:x
    A = []; numb = zero; sign = 1; i = 0; s = sys.stdin.buffer.read()
    try:
        while True:
            if s[i] >= b'0' [0]:
                numb = 10 * numb + conv(s[i]) - 48
            elif s[i] == b'-' [0]: sign = -1
            elif s[i] != b'\r' [0]:
                A.append(sign*numb)
                numb = zero; sign = 1
            i += 1
    except:pass
    if s and s[-1] >= b'0' [0]:
        A.append(sign*numb)
    return A

if __name__== "__main__":
  main()

Submission status: Wrong Answer

Solution code:
import bisect
import heapq
N = int(input())

a_lst = []
heapq.heapify(a_lst)
b = 0
drift = 0
center = 0
for i in range(N):
	vals = list(map(int,input().split()))
	if len(vals) == 3:
		if i == 0:
			drift = 0
		elif len(a_lst)%2 == 0:
			center_1 = a_lst[(len(a_lst)//2)-1]
			center_2 = a_lst[(len(a_lst)//2)]
			if vals[1] < center_1:
				drift += center_1 - vals[1]
			elif vals[1] > center_2:
				drift += vals[1] - center_2
			# if new point in between center. drift is not increase
			
		else:
			drift += abs(vals[1]-center)
		
		heapq.heappush(a_lst, vals[1])
		
		center = a_lst[(len(a_lst)-1)//2]
		b += vals[2]
	else:
		print(center,drift + b)

Submission status: Wrong Answer

Solution code:
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict
import heapq


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


class UnionFind:

    def __init__(self, n):
        self.parent = [i for i in range(n)]

    def root(self, i):
        if self.parent[i] == i:
            return i
        self.parent[i] = self.root(self.parent[i])
        return self.parent[i]

    def unite(self, i, j):
        rooti = self.root(i)
        rootj = self.root(j)
        if rooti == rootj:
            return
        if rooti < rootj:
            self.parent[rootj] = rooti
        else:
            self.parent[rooti] = rootj

    def same(self, i, j):
        return self.root(i) == self.root(j)


###############################################################################


def main():
    qnum = intin()
    qlist = [input() for _ in range(qnum)]

    alist = []
    acount = 0
    prev_med = None
    lsum = 0
    rsum = 0
    bsum = 0

    for q in qlist:

        if q[0] == '1':
            q = q.split(' ')
            a = int(q[1])
            b = int(q[2])

            bsum += b

            med = None
            odd_slice = None
            even_slice = None

            if alist:
                med = alist[acount//2 if acount&1 else acount//2-1]
                if acount & 1:
                    if a <= med:
                        odd_slice = True
                    else:
                        odd_slice = False
                else:
                    if a < med:
                        even_slice = False
                    else:
                        even_slice = True

            heapq.heappush(alist, a)
            acount += 1

            if med is not None:
                prev_med = med
                med = alist[acount//2 if acount&1 else acount//2-1]
                if odd_slice is not None:
                    if odd_slice:
                        lsum -= (abs(prev_med - med) * ((acount - 1) // 2))
                        lsum += abs(med - a)
                        rsum += (abs(prev_med - med) * (acount // 2))
                    else:
                        rsum += abs(med - a)
                if even_slice is not None:
                    if even_slice:
                        lsum += (abs(med - prev_med) * (acount // 2))
                        rsum -= (abs(med - prev_med) * (acount // 2))
                        rsum += abs(a - med)
                    else:
                        lsum += abs(med - a)

        if q[0] == '2':
            print('%d %d' % 
                  (alist[acount//2 if acount&1 else acount//2-1],
                   lsum + rsum + bsum))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
q0=int(input())
from heapq import *

low=[]
high=[]
ans=0
num=0
for _ in range(q0):
    q = [int(i) for i in input().split()]
    if q[0] == 1:
        ans+=q[2]
        num+=1
        a=q[1]
        if num==1:
            heappush(low,-a)
            df = 0
        elif num%2==1:
            centold = -low[0]
            centold2 = high[0]
            if -low[0] >= a:
                heappush(low,-a)
            else:
                c=heappushpop(high,a)
                heappush(low,-c)
            centnew = -low[0]
            if centnew < centold:
                df = 2*(centold-centnew)
            elif centnew <= centold2:
                df = 0
            else:
                df = 2*(centnew - centold2)
        else:
            centold = -low[0]
            if -low[0] > a:
                c=heappushpop(low,-a)
                heappush(high,-c)
            else:
                heappush(high,a)
            centnew = -low[0]
            if centnew < centold:
                df = (centold-centnew)
            else:
                df = (centnew - centold)
        
        ans += df
            
        
        
        

    if q[0] == 2:
        print(-low[0],ans)

Submission status: Wrong Answer

Solution code:
import bisect
import sys
input = sys.stdin.readline
q=int(input())
A=[]
b=0
def f(A,b,n):
  res=0
  if n%2==0:
    return sum(A[n+1:])-sum(A[:n])+b
  else:
    return sum(A[n:])-sum(A[:n])+b
for _ in range(q):
  L=[int(i) for i in input().split()]
  if L[0]==1:
    n=bisect.bisect_left(A,L[1])
    A.insert(n,L[1])
    b+=L[2]
  else:
    n=A[(len(A)-1)//2]
    print(n,f(A,b,n))

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(key=lambda x: abs(x))
        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 bisect
import math

n = int(input())

a = []
b = 0

for i in range(n):
    q = list(map(int,input().split()))
    if len(q)==3:
        bisect.insort(a,q[1])
        b += q[2]
    else:
        x = math.ceil(len(a)/2)-1
        print(a[x],end=' ')
        print(abs(sum(a[:x])-sum(a[x+1:]))-a[x]*((len(a)+1)%2)+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


first = True

for _ in range(Q):
    inp = inpl()
    if inp[0] == 1:
        query,a,b = inp
        SUM += a   # 合計値
        keisu += b # 係数
        N += 1
        if first:
            sakaiue = sakaisita = a
            first = False

        if sakaiue < a:
            heapq.heappush(HIGHq,a)
            HIGHsum += a
            HIGHn += 1
            while abs(HIGHn - LOWn) > 1:
                heapq.heappush(LOWq,-sakaisita)
                LOWsum += sakaisita
                sakaisita = sakaiue
                sakaiue = heapq.heappop(HIGHq)
                HIGHsum -= sakaiue
                HIGHn -= 1
                LOWn  += 1
        elif sakaisita <= a <= sakaiue:
            if HIGHn > LOWn:
                heapq.heappush(LOWq,-sakaisita)
                LOWsum += sakaisita
                sakaisita = a
                LOWn += 1
            else:
                heapq.heappush(HIGHq,sakaisita)
                sakaisita = a
                HIGHsum += sakaisita
                HIGHn += 1
        else:
            heapq.heappush(LOWq,-a)
            LOWsum += a
            LOWn += 1
            while abs(LOWn - HIGHn) > 1:
                heapq.heappush(HIGHq,sakaiue)
                HIGHsum += sakaiue
                sakaiue = sakaisita
                sakaisita = -heapq.heappop(HIGHq)
                HIGHsum -= sakaisita
                LOWn -= 1
                HIGHn  += 1

    else:
        #print('n',LOWn,HIGHn)
        #print(LOWsum,HIGHsum)
        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:
class func:
    def __init__(self):
        self.a = []
        self.b = 0

    def renew(self, a, b):
        self.a.append(a)
        self.a = sorted(self.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 = []
    cnt = 0
    fb = 0
    for _ in range(int(input())):
        Q = list(map(int, input().split()))
        if len(Q) == 1:
            print(F[0], F[1] + fb)
        else:
            a, b = Q[1], Q[2]
            if F:
                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:
import sys
from collections import deque
from collections import defaultdict
import math
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
q = int(input())
tei = 0
x = []
nnn = []
for i in range(q):
        nnn.append(input().rstrip())
for i in range(q):
        nn = nnn[i]
        if int(nn[0]) == 1:
                _,a,b = map(int,nn.split())
                x.append(a)
                tei += b
        else:
                x.sort()
                t = x[len(x)//2]
                ans = 0
                for j in x:
                        ans += abs(t-j)
                print(t,tei+ans)

Submission status: Wrong Answer

Solution code:
Q = int(input())
a, b, Query = [], [], []
for i in range(Q):
    Query.append([int(x) for x in input().split()])

for i in range(Q):
    if Query[i][0] == 1:
        a.append(Query[i][1])
        b.append(Query[i][2])
    else:
        print(min(a), max(a)-min(a)+sum(b))

Submission status: Wrong Answer

Solution code:
import heapq

def main(): 
    smaller = []
    larger = []

    smallsum = 0
    largesum = 0

    const = 0

    q = int(input())
    for _ in range(q):
        inp = input()
        if inp[0] == '1':
            _,a,b = [int(x) for x in inp.split()]
            const += b

            if not smaller:
                smaller.append(-a)
                smallsum += a

            elif a <= -smaller[0]:
                heapq.heappush(smaller, -a)
                smallsum += a

            else:
                heapq.heappush(larger, a)
                largesum += a

            while len(smaller)>len(larger)+1:
                a = -heapq.heappop(smaller)
                smallsum -= a
                heapq.heappush(larger, a)
                largesum += a
            while len(larger)>len(smaller):
                a = heapq.heappop(larger)
                largesum -= a
                heapq.heappush(smaller,-a)
                smallsum += a

        else:
            x = -smaller[-1] if smaller else 0
            print x, const + len(smaller)*x - smallsum + largesum - len(larger)*x



######## Python 2 and 3 footer by Pajenegod and c1729

# Note because cf runs old PyPy3 version which doesn't have the sped up
# unicode strings, PyPy3 strings will many times be slower than pypy2.
# There is a way to get around this by using binary strings in PyPy3
# but its syntax is different which makes it kind of a mess to use.

# So on cf, use PyPy2 for best string performance.

py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange

import os, sys
from io import IOBase, BytesIO

BUFSIZE = 8192
class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill(): pass
        return super(FastIO,self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill(); self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s:self.buffer.write(s.encode('ascii'))
            self.read = lambda:self.buffer.read().decode('ascii')
            self.readline = lambda:self.buffer.readline().decode('ascii')


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = sys.stdin.readline

# Cout implemented in Python
import sys
class ostream:
    def __lshift__(self,a):
        sys.stdout.write(str(a))
        return self
cout = ostream()
endl = '\n'

# Read all remaining integers in stdin, type is given by optional argument, this is fast
def readnumbers(zero = 0):
    conv = ord if py2 else lambda x:x
    A = []; numb = zero; sign = 1; i = 0; s = sys.stdin.buffer.read()
    try:
        while True:
            if s[i] >= b'0' [0]:
                numb = 10 * numb + conv(s[i]) - 48
            elif s[i] == b'-' [0]: sign = -1
            elif s[i] != b'\r' [0]:
                A.append(sign*numb)
                numb = zero; sign = 1
            i += 1
    except:pass
    if s and s[-1] >= b'0' [0]:
        A.append(sign*numb)
    return A

if __name__== "__main__":
  main()

Submission status: Wrong Answer

Solution code:
import bisect
Q = int(input())
input_list = [list(map(int,input().split(' '))) for i in [0]*Q]

A = []
sumb = 0
N = 0
for inp in input_list:
	if inp[0] == 1:
		N += 1
		a,b = inp[1:]
		sumb += b
		bisect.insort(A,a)
	else:
		n = -(-N//2)-1
		x = A[n]
		s = 0
		t = 0
		if n > 0:
			s = x*(n-1)-sum(A[:n-1])
		if n < N-1:
			t = sum(A[n+1:]) - x*(N-(n+1))
		print(x,s+t+sumb)

Submission status: Wrong Answer

Solution code:
import heapq


class Solver:

    def __init__(self):
        self.heap = []
        self.s = 0

    def add(self, a, b):
        if len(self.heap)==0:
            self.s = b
            self.heap = [a]
            return

        i = self.minidx()
        x0 = self.heap[i]

        heapq.heappush(self.heap, a)

        j = self.minidx()
        x1 = self.heap[j]

        if x0 == x1:
            self.s += b + abs(x0-a)
        else:
            dx = x1 - x0
            n1 = len(self.heap[:j])
            n2 = len(self.heap[j+1:])
            self.s += (b + (n1 - n2) * dx) + abs(x1 - a)
        # print(f"s={self.s}")

    def minidx(self):
        n = len(self.heap)
        idx = n//2 - (n%2==0)
        return idx

    def getmin(self):
        return self.heap[self.minidx()], self.s


def main():
    Q = int(input())

    solver = Solver()
    for _ in range(Q):
        q = [int(x) for x in input().split()]
        if q[0] == 2:
            i, s = solver.getmin()
            print(i, s)
        else:
            _, a, b = q
            solver.add(a, b)


if __name__ == '__main__':
    main()

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 x, y in absolute_minima(Q, queries):
        print(x, y)

Submission status: Wrong Answer

Solution code:
q = int(input())
query = [list(map(int, input().split())) for i in range(q)]
mins = []
n = 0
B = 0

for i in query:
  if i[0] == 2:
    med = mins[n // 2]
    ans = B 
    for j in mins:
      ans += abs(j-med)
    print(med,ans)
  else:
    a,b = i[1],i[2]
    mins.append(a)
    n += 1
    mins.sort()
    B += b