Problem:


Score : 600 points

Problem Statement

There is a function f(x), which is initially a constant function f(x) = 0.

We will ask you to process Q queries in order. There are two kinds of queries, update queries and evaluation queries, as follows:

An update query 1 a b: Given two integers a and b, let g(x) = f(x) + |x - a| + b and replace f(x) with g(x).

An evaluation query 2: Print x that minimizes f(x), and the minimum value of f(x). If there are multiple such values of x, choose the minimum such value.

We can show that the values to be output in an evaluation query are always integers, so we ask you to print those values as integers without decimal points.

Constraints

All values in input are integers.

1 \leq Q \leq 2 \times 10^5

-10^9 \leq a, b \leq 10^9

The first query is an update query.

Input

Input is given from Standard Input in the following format:

Q
Query_1
:
Query_Q

See Sample Input 1 for an example.

Output

For each evaluation query, print a line containing the response, in the order in which the queries are given.

The response to each evaluation query should be the minimum value of x that minimizes f(x), and the minimum value of f(x), in this order, with space in between.

Sample Input 1

4
1 4 2
2
1 1 -8
2

Sample Output 1

4 2
1 -3

In the first evaluation query, f(x) = |x - 4| + 2, which attains the minimum value of 2 at x = 4.

In the second evaluation query, f(x) = |x - 1| + |x - 4| - 6, which attains the minimum value of -3 when 1 \leq x \leq 4. Among the multiple values of x that minimize f(x), we ask you to print the minimum, that is, 1.

Sample Input 2

4
1 -1000000000 1000000000
1 -1000000000 1000000000
1 -1000000000 1000000000
2

Sample Output 2

-1000000000 3000000000



Sample input:
4
1 4 2
2
1 1 -8
2


Sample output:
4 2
1 -3

Submission status: Wrong Answer

Solution code:
import bisect

Q = int(input())

Query, A, B = [], [], 0
for _ in range(Q):
    q = tuple(map(int, input().split()))
    Query.append(q)
    if len(q) == 3:
        A.append(q[1])
        B += q[2]

A.sort()

lA = len(A)
if lA % 2 == 0:
    mi = lA // 2 - 1
    l, m, r = sum(A[:lA // 2]), 0, sum(A[lA // 2:])
    even = True
else:
    mi = lA // 2
    l, m, r = sum(A[:lA // 2]), A[lA // 2], sum(A[lA // 2 + 1:])
    even = False

ans = []
for i in range(Q):
    q = Query[Q - i - 1]
    if len(q) == 3:
        ix = bisect.bisect_left(A, q[1])
        if even:
            if ix > mi:
                l, m, r = l, A[mi], r - A[ix]
                mi = mi
            elif ix == mi:
                l, m, r = l - A[ix], A[mi + 1], r - A[mi + 1]
                mi = mi + 1
            else:
                l, m, r = l - A[ix], A[mi + 1], r - A[mi + 1]
                mi = mi + 1
            even = False
        else:
            if ix > mi:
                l, m, r = l, 0, r - A[ix] + m
                mi = mi - 1
            elif ix == mi:
                l, m, r = l, 0, r
                mi = mi - 1
            else:
                l, m, r = l - A[ix] + m, 0, r
                mi = mi
            even = True
        B -= q[2]
    else:
        ans.append((A[mi], r - l + B))

la = len(ans)
for i in range(la):
    print(ans[la - i - 1][0], ans[la - i - 1][1])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
from heapq import heappush

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

Q=INT()

li=[]
B=fx=cost=cnt=0
for _ in range(Q):
    instr=input()
    if instr[0]=='1':
        _,a,b=map(int, instr.split())
        B+=b
        heappush(li, a)
        if cnt==0:
            A=a
        else:
            # 偶数回目
            if cnt%2==1:
                A2=li[len(li)//2-1]
            # 奇数回目
            else:
                A2=li[len(li)//2]
            cost+=abs(A-A2)
            A=A2
        fx=cost+B
        cnt+=1
    else:
        print(A, fx)

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
ans1 = 0
for i in range(Q - 1):
	x = getlist()
	if x[0] == 1:
		a, b = x[1], x[2]
		if n % 2 == 0:
			u, v = A[int(n // 2) - 1], A[int(n // 2)]
			if a <= u:
				ans1 += u - a
			elif a >= v:
				ans1 += a - v
			else:
				pass
		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 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 heapq import heappush

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[len(A) - idx - 1:]) - sum(A[:idx + 1]) + bias)
            print(*ans)
        else:
            _, a, b = q
            bias += b
            heappush(A, a)
    return

main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

Q=INT()

fx=0
li=[]
B=0
cost=0
cnt=0
for _ in range(Q):
    instr=input()
    if instr[0]=='1':
        _,a,b=map(int, instr.split())
        B+=b
        li.append(a)
        li.sort()
        if cnt==0:
            A=a
        else:
            # 偶数回目
            if cnt%2==1:
                A2=li[len(li)//2-1]
            # 奇数回目
            else:
                A2=li[len(li)//2]
            cost+=abs(A-A2)
            A=A2
        fx=cost+B
        cnt+=1
    else:
        print(A, fx)

Submission status: Wrong Answer

Solution code:
import heapq

Q = int(input())
A=[]
sumA = 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())
        sumA += a
        heapq.heappush(A, a)
        B += b
    else:
        average = A[(j-1)//2]
        print(int(average), int(sumA - average*j + B))

Submission status: Wrong Answer

Solution code:
from heapq import heappush
import numpy as np
 
num_q = int(input())
x = 0
f = 0
a = []
c = False
b = 0
 
for _ in range(num_q):
  q = input()
  if q[0] == '2':
    print(x, f)
  else:
    _, n, m = map(int, q.split(" "))
    heappush(a, n)
    x_tmp = a[b//2]
    if c:
      f += m + np.abs(x - n)
    else:
      f += m + np.abs(x_tmp - n)
    c = ~c
    x = x_tmp
    b += 1

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from heapq import heappush, heappop
def solve(): 
    Q = int(input())
    q, a, b = map(int, input().split())
    B = b
    c = a
    L, R = [], []
    count = 1
    x = c
    v_ = 0
    res_l = []

    for _ in range(Q-1):
        #print(x, v_ ,c,L,R)
        *q_, = map(int, input().split())
        if q_[0] == 1:
            q, a, b = q_
            B += b
            if count&1:
                if a < c:
                    heappush(L, -a)
                    heappush(R, c)
                    x_ = -L[0]
                    v_ = x-x_
                    x = x_
                else:
                    heappush(L, -c)
                    heappush(R, a)                
            else:
                if a <= -L[0]:
                    heappush(L, -a)
                    x_ = -heappop(L)
                elif a >= R[0]:
                    heappush(R, a)
                    x_ = heappop(R)
                else:
                    x_ = c = a
                x = x_

            v_ += abs(x-a)
            count ^= 1
            #print(x, v_ ,c,L,R)
        else:
            v = v_ + B
            res_l.append('{} {}'.format(x, v))
    res = '\n'.join(res_l)
    return str(res)

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

Submission status: Wrong Answer

Solution code:
Q = int(input())
B = 0  # bの総和
X = []  # 最小となるxの候補
q = [list(input().split()) for _ in range(Q)]

for i in range(Q):
	if q[i][0] == "2":
		n = len(set(X))
		if n == 0:
			print(0, 0)
		else:
			if n % 2 == 0:
				X = sorted(X)
				x = list(set(X))[n // 2 - 1]
				I = [i for i, k in enumerate(X) if k == x]
				print(x, B + sum(X[max(I) + 1:]) - sum(X[: min(I)]))
			else:
				X = sorted(X)
				x = list(set(X))[n // 2]
				I = [i for i, k in enumerate(X) if k == x]
				print(x, B + sum(X[max(I) + 1:]) - sum(X[: min(I)]))
	else:
		X.append(int(q[i][1]))
		B += int(q[i][2])

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:
			u, v = A[int(n // 2) - 1], A[int(n // 2)]
			if a <= u:
				ans1 += u - a
			elif a >= v:
				ans1 += a - v
		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:
# -*- 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 = 1
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
        print(A,A[(len(A)-1)//2],B)
    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:
import heapq

Q = int(input())

aHeap = []
sumA = 0
sumB = 0
N = 0

for i in range(Q):
    Query = list(map(int,input().split()))
    if Query[0] == 1:
        sumB += Query[2]
        a = Query[1]
        heapq.heappush(aHeap, a)
        sumA += a
        N += 1
    else:
        mean = (N + 1) // 2 - 1
        ans1 = aHeap[mean]
        if N % 2 == 1:
            ans2 = sumB + sumA - sum(aHeap[:mean]) * 2 - aHeap[mean]
        else:
            ans2 = sumB + sumA - sum(aHeap[:(mean + 1)]) * 2
        print("{} {}".format(ans1, ans2))

Submission status: Wrong Answer

Solution code:
import heapq

Q = int(input())
A=[]
sumA = 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())
        sumA += a
        heapq.heappush(A, a)
        B += b
    else:
        average = A[j//2-1]
        print(int(average), int(sumA - average*j + B))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from heapq import heappush, heappop
def solve(): 
    Q = int(input())
    q, a, b = map(int, input().split())
    B = b
    c = a
    L, R = [], []
    count = 1
    x = c
    v_ = 0
    res_l = []

    for _ in range(Q-1):
        #print(x, v_ ,c,L,R)
        *q_, = map(int, input().split())
        if q_[0] == 1:
            q, a, b = q_
            B += b
            if count&1:
                if a < c:
                    heappush(L, -a)
                    heappush(R, c)
                    x_ = -L[0]
                    v_ = x-x_
                    x = x_
                else:
                    heappush(L, -c)
                    heappush(R, a)                
            else:
                if a <= -L[0]:
                    heappush(L, -a)
                    x_ = heappop(L)
                elif a >= R[0]:
                    heappush(R, a)
                    x_ = heappop(R)
                else:
                    x_ = c = a
                x = x_

            v_ += abs(x-a)
            count ^= 1
            #print(x, v_ ,c,L,R)
        else:
            v = v_ + B
            res_l.append('{} {}'.format(x, v))
    res = '\n'.join(res_l)
    return str(res)

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

Submission status: Wrong Answer

Solution code:
import sys
from bisect import insort


class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(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

    def debug_print(self):
        print(*('{:5d}'.format(i) for i in range(1, self.size + 1)))
        print(*('{:5d}'.format(self.sum(i)) for i in range(1, self.size + 1)))


Q = int(input())
queries = []
nums = set()
for line in sys.stdin:
    q = list(map(int, line.split()))
    queries.append(q)
    if len(q) > 1:
        _, a, b = q
        nums.add(a)
nums = sorted(nums)
min_a = nums[0]
n = len(nums)
diffs = [a - min_a for a in nums]
num_d = {num: i for i, num in enumerate(sorted(nums))}

bit = Bit(n)
update_count = 0
update_list = []
sum_da = 0
sum_b = 0

for q in queries:
    if len(q) == 1:
        k = (update_count - 1) // 2
        x = update_list[k]
        i = num_d[x]
        d = diffs[i]
        dn_cnt = (update_count + 1) // 2
        up_cnt = update_count - dn_cnt
        bsi = bit.sum(i + 1)
        up_sum = sum_da - bsi - d * up_cnt
        dn_sum = d * dn_cnt - bsi
        # print('k:{} x:{} i:{} d:{} up:{} dn:{}'.format(k, x, i, d, up_sum, dn_sum))
        res = up_sum + dn_sum + sum_b
        print(x, res)
    else:
        _, a, b = q
        sum_b += b
        update_count += 1
        insort(update_list, a)
        i = num_d[a]
        d = diffs[i]
        bit.add(i + 1, d)
        sum_da += d

Submission status: Wrong Answer

Solution code:
Q = int(input())
Queries = [list(map(int, input().split())) for _ in range(Q)]

import heapq as hp
L = [10**9+1] # 最小ヒープなので負を入れる
R = [10**9+1] # そのまま
hp.heapify(L)
hp.heapify(R)
odd = False
sum_b = 0
sum_l = 0
sum_r = 0

flag = 1

for q in Queries:
  if len(q)==1 and q[0]==2:
    if flag ==0:
      print(*(-L[0], sum_b + abs(sum_l-sum_r)))
    else:
      print(*(-L[0], sum_b))
      flag = 0

  else:
    _, a, b = q
    sum_b += b

    l = -hp.heappop(L)
    r = hp.heappop(R)
    sum_l -= l
    sum_r -= r
    X = sorted([l, r, a])
    if odd==False:
      hp.heappush(L,-X[0])
      hp.heappush(L,-X[1])
      hp.heappush(R,X[2])
      sum_l += X[0]+X[1]
      sum_r += X[2]
      odd=True
    elif odd==True:
      hp.heappush(L,-X[0])
      hp.heappush(R,X[1])
      hp.heappush(R,X[2])
      sum_l += X[0]
      sum_r += X[1] + X[2]
      odd=False

Submission status: Wrong Answer

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

odd = True
for _ in range(Q-1):
  q = input()
  if q[0] == '1':
    _, a, b = map(int, q.split())
    if odd:
      m += abs(vs[midx]-a) + b
    else:
      t1 = abs(vs[midx]-a)
      t2 = abs(vs[midx+1]-a)
      m += (t1 if t1 < t2 else t2) + b
      midx += 1
    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:
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:
			u, v = A[int(n // 2) - 1], A[int(n // 2)]
			if a <= u:
				ans1 += u - a
			elif a >= v:
				ans1 += a - v
			else:
				ans1 += v - u
		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 heapq
Q = int(input())
heap = []
b = 0
for _ in range(Q):
  s = input()
  if len(s) > 1:
    a= int(s.split()[1])
    b += int(s.split()[2])
    heapq.heappush(heap,a)
  else:
    if len(heap) % 2 is 0:
      print(heap[len(heap)//2-1],-1*sum(heap[:len(heap)//2])+sum(heap[len(heap)//2-1:])+b)
    else:
      print(heap[len(heap)//2],-1*sum(heap[:len(heap)//2])+sum(heap[len(heap)//2+1:])+b)

Submission status: Wrong Answer

Solution code:
q = int(input())

keisuu_lower = []
keisuu_upper = []
keisuu_lower_max = 0
keisuu_upper_min = float("inf")
keisuu_lower_count = 0
keisuu_upper_count = 0
keisuu_lower_sum = 0
keisuu_upper_sum = 0
teisuu = 0

for i in range(q):
    query = input()
    if query == "2":
        print(keisuu_lower_max,
              - keisuu_lower_sum + keisuu_lower_count * keisuu_lower_max
              + keisuu_upper_sum - keisuu_upper_count * keisuu_lower_max + teisuu)

    else:
        _, a, b = [int(i) for i in query.split()]
        keisuu_lower.append(a)
        keisuu_lower_count += 1
        keisuu_lower_max = max(keisuu_lower_max, a)
        keisuu_lower_sum += a

        if keisuu_lower_count > keisuu_upper_count + 1:
            keisuu_lower.sort()
            c = keisuu_lower.pop()
            keisuu_lower_count -= 1
            keisuu_lower_max = keisuu_lower[-1]
            keisuu_lower_sum -= c

            keisuu_upper.append(c)
            keisuu_upper.sort(reverse=True)
            keisuu_upper_count += 1
            keisuu_upper_min = keisuu_upper[-1]
            keisuu_upper_sum += c

        elif keisuu_lower_count < keisuu_upper_count:
            keisuu_upper.sort()
            c = keisuu_upper.pop()
            keisuu_upper_count -= 1
            keisuu_upper_min = keisuu_upper[-1]
            keisuu_upper_sum -= c

            keisuu_lower.append(c)
            keisuu_lower.sort(reverse=True)
            keisuu_lower_count += 1
            keisuu_lower_max = keisuu_lower[-1]
            keisuu_lower_sum += c

        if keisuu_lower_max > keisuu_upper_min:
            d = keisuu_upper.pop()
            e = keisuu_lower.pop()
            keisuu_lower.append(d)
            keisuu_upper.append(e)
            keisuu_lower_sum += d - e
            keisuu_upper_sum += e - d
            keisuu_lower_max = d
            keisuu_upper_min = e

        #print(keisuu_lower)
        #print(keisuu_lower_sum)
        #print(keisuu_lower_max)
        teisuu += b

Submission status: Wrong Answer

Solution code:
Q = int(input())
bSum=0
a = []
aSum = 0
for i in range(Q):
    tmp = list(map(int,input().split()))
    if len(tmp) == 1:
        x = aSum//i
        ans = bSum
        for k in a:
            ans += abs(k-x)
        print("{0} {1}".format(x, ans))
    else:
        aSum += tmp[1]
        a.append(tmp[1])
        bSum += tmp[2]

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from heapq import heappush, heappop
def solve(): 
    Q = int(input())
    q, a, b = map(int, input().split())
    B = b
    c = a
    L, R = [], []
    count = 1
    x = c
    v_ = 0
    res_l = []

    for _ in range(Q-1):
        *q_, = map(int, input().split())
        if q_[0] == 1:
            q, a, b = q_
            B += b
            if count&1:
                if a < c:
                    heappush(L, -a)
                    heappush(R, c)
                    x_ = -L[0]
                    v_ = x-x_
                    x = x_
                else:
                    heappush(L, -c)
                    heappush(R, a)                
            else:
                if a <= -L[0]:
                    heappush(L, -a)
                    x_ = heappop(L)
                elif a >= R[0]:
                    heappush(R, a)
                    x_ = heappop(R)
                else:
                    x_ = c = a

            v_ += abs(x-a)
            count ^= 1
        else:
            v = v_ + B
            res_l.append('{} {}'.format(x, v))
    res = '\n'.join(res_l)
    return str(res)

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

Submission status: Wrong Answer

Solution code:
Q = int(input())

import numpy as np

a_array = np.empty(1,)
b_array = np.empty(1,)

for _ in range(Q):
    query_list = list(map(int,input().split()))
    
    if query_list[0] == 1:
        a_array = np.append(a_array, query_list[1])
        b_array = np.append(b_array, query_list[2])
    
    if query_list[0] == 2:
        x = np.mean(a_array)
        b = np.sum(b_array)
        
        print(int(x))
        print(int(np.sum(np.abs(x - a_array)) + b))

Submission status: Wrong Answer

Solution code:
from sys import stdin

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

    a = 0
    b = 0
    term = 0

    minA = 10**10

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

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

Submission status: Wrong Answer

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

q = []
anum = 0
bsum = 0

for i in range(Q):
    query = list(map(int, input().split()))
    if query[0] == 1:
        a = query[1]
        heapq.heappush(q, a)
        anum += 1
        bsum += query[2]
    elif query[0] == 2:
        x = q[(anum-1)//2]
        if anum % 2 == 1:
            fx = bsum
        else:
            fx =  q[(anum-1)//2 + 1] - x  + bsum
        # print(anum, bsum, q)
        print(x, fx)

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
second = 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
            continue
        elif second:
            if sakaiue > a:
                sakaisita = a
            else:
                sakaiue = a
            second = False
            continue

        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
            print('nya-n',LOWn,HIGHn)
            while abs(LOWn - HIGHn) > 1:
                heapq.heappush(HIGHq,sakaiue)
                HIGHsum += sakaiue
                sakaiue = sakaisita
                sakaisita = -heapq.heappop(LOWq)
                HIGHsum -= sakaisita
                LOWn -= 1
                HIGHn  += 1

    else:
        #print('n',sakaisita,sakaiue)
        #print(LOWsum,HIGHsum)
        if LOWn >= HIGHn:
            x = sakaisita
        else:
            x = sakaiue

        if not second:
            tmp = (HIGHsum+sakaiue - LOWsum-sakaisita) + (LOWn-HIGHn)*x + keisu
        else:
            tmp = keisu

        ans.append([x,tmp])



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

Submission status: Wrong Answer

Solution code:
import bisect

q = int(input())
a = []
b = 0
for i in range(q):
    s = list(input().split())
    if s[0] == '1':
        ai = int(s[1])
        bi = int(s[2])
        bisect.insort_left(a, ai)
        b += bi
    else:
        if len(a) % 2:
            idx = len(a) // 2
            print(str(a[idx]), str(b))
        else:
            idx = len(a) // 2 - 1
            print(str(a[idx]), str(b + (a[idx + 1] - a[idx])))

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:
			l = p
		else:
			r = 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 = -10**9
		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:
			if y < a_med:
				sum_a_mae += y - 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:
Q = int(input())
l, mid, r = None, None, None
s = 0
min_x = 0
for i in range(Q):
    q = list(map(int, input().split()))
    if len(q) == 1:
        print(min_x, s)
    else:
        a, b = q[1], q[2]
        s += b
        if mid == None:
            if l == None or r == None:
                mid = a
                min_x = a
            else:
                if a >= r:
                    s += a - r
                    mid = r
                    min_x = r
                elif a > l:
                    mid = a
                    min_x = a
                else:
                    s += l - a
                    mid = l
                    min_x = l
        else:
            if l == None or r == None:
                l, r = min(mid, a), max(mid, a)
                s += abs(l - r)
                min_x = l
            else:
                s += abs(a - mid)
                if a > r:
                    l, r = mid, r
                elif a >= l:
                    l, r = min(mid, a), max(mid, a)
                else:
                    l, r = a, l
                min_x = l
                mid = None

Submission status: Wrong Answer

Solution code:
N=int(input())
num=0
a=[]
b=0
for i in range(N):
    A=list(map(int,input().split()))
    if A[0]==1:
        num=+1
        a.append(A[1])
        b+=A[2]
    else:
        a.sort()
        sum=b
        for j in a:
            sum+=abs(a[num//2-1]-j)
        print(a[num//2],sum)

Submission status: Wrong Answer

Solution code:
Q = int(input())
B = 0  # bの総和
X = []  # 最小となるxの候補
q = [list(input().split()) for _ in range(Q)]

for i in range(Q):
	if q[i][0] == "2":
		n = len(set(X))
		if n == 0:
			print(0, 0)
		else:
			if n % 2 == 0:
				X = sorted(X)
				x = list(set(X))[n // 2 - 1]
				I = [i for i, k in enumerate(X) if k == x]
				print(x, B + sum(X[max(I) + 1:]) - sum(X[: min(I) + 1]))
			else:
				X = sorted(X)
				x = list(set(X))[n // 2]
				I = [i for i, k in enumerate(X) if k == x]
				print(x, B + sum(X[max(I) + 1:]) - sum(X[: min(I)]))
	else:
		X.append(int(q[i][1]))
		B += int(q[i][2])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
Q = int(input())
Y = []
D = []
S = [0] * Q
s = 0
for i in range(Q):
    a = list(map(int, input().split()))
    Y.append(a)
    if a[0] == 1:
        D.append(a[1])
        s += a[2]
    S[i] = s

D = sorted(list(set(D)))
INV = {}
for i in range(len(D)):
    INV[D[i]] = i
print("Y=", Y)
print("D=", D)
print("INV=", INV)
print("S=", S)


N = 17
X = [0] * (2**(N+1)-1)
C = [0] * (2**(N+1)-1)

def add(j, x):
    i = 2**N + j - 1
    while i >= 0:
        X[i] += x
        C[i] += 1
        i = (i-1) // 2

def rangeof(i):
    s = (len(bin(i+1))-3)
    l = ((i+1) - (1<<s)) * (1<<N-s)
    r = l + (1<<N-s)
    return (l, r)

def rangesum(a, b, i=0):
    l, r = rangeof(i)
    if l >= b or r <= a:
        return 0
    if a <= l and r <= b:
        return X[i]
    return rangesum(a, b, 2*i+1) + rangesum(a, b, 2*i+2)
def rangecnt(a, b, i=0):
    l, r = rangeof(i)
    if l >= b or r <= a:
        return 0
    if a <= l and r <= b:
        return C[i]
    return rangecnt(a, b, 2*i+1) + rangecnt(a, b, 2*i+2)

c = 0
su = 0
CC = [0] * (2**N)
for i in range(Q):
    y = Y[i]
    if y[0] == 1:
        add(INV[y[1]], y[1])
        CC[INV[y[1]]] += 1
        c += 1
        su += y[1]
    else:
        l, r = 0, 2**N
        while True:
            m = (l+r)//2
            rc = rangecnt(0, m)
            if rc >= (c+1)//2:
                r = m
            elif rc + CC[m] <= (c-1)//2:
                l = m
            else:
                break
        rs = rangesum(m, 2**N)
        print(rs-m*rc+(c-rc)*m-(su-rs))

Submission status: Wrong Answer

Solution code:
from bisect import insort_left, bisect_left, bisect_right

Q = int(input())
a_list = []
scalar = 0
length = 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]
        length += 1
    else:
        # unique_a_list =list(set(a_list.copy())) 
        if length%2==0:
            ans0_pos =int(length/2 - 1)
            ans0 = a_list[ans0_pos]
            ans1 = -1* sum(a_list[:ans0_pos+1]) + sum(a_list[ans0_pos+1:])


        else:
            ans0_pos = int(length/2-0.5)
            
            ans0 = a_list[ans0_pos]
            ans1 = -1* sum(a_list[:ans0_pos]) + sum(a_list[ans0_pos+1:]) + scalar
        print(str(ans0)+" "+str(ans1))