Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

N = int(input())
from collections import Counter
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ca = Counter(A)
cb = Counter(B)
h = []
for i in range(1,N+1):
  if ca[i]+cb[i]>N:
    print('No')
    exit()
  if ca[i]+cb[i]>0:
    heappush(h,(-ca[i]-cb[i],-cb[i],i))
lis = [[] for _ in range(N+1)]
while len(h):
  cnt, cntb, n = heappop(h)
  cnt2, cntb2, n2 = heappop(h)
  if cntb-cnt>0:
    cnt += 1
    lists = []
    while cntb2==0:
      lists.append((cnt2,cntb2,n2))
      cnt2, cntb2, n2 = heappop(h)
    for i in range(len(lists)):
      heappush(h,lists[i])
    cntb2 += 1
    cnt2 += 1
    lis[n].append(n2)
    if cnt<0:
      heappush(h,(cnt,cntb,n))
    if cnt2<0:
      heappush(h,(cnt2,cntb2,n2))
  else:
    cntb += 1
    cnt += 1
    lists = []
    while cntb2-cnt2==0:
      lists.append((cnt2,cntb2,n2))
      cnt2, cntb2, n2 = heappop(h)
    for i in range(len(lists)):
      heappush(h,lists[i])
    cnt2 += 1
    lis[n2].append(n)
    if cnt<0:
      heappush(h,(cnt,cntb,n))
    if cnt2<0:
      heappush(h,(cnt2,cntb2,n2))
ans = []
for i in range(1,N+1):
  for b in lis[i]:
    ans.append(b)
print('Yes')
print(*ans)

### FIXED CODE ###

N = int(input())
from collections import Counter
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ca = Counter(A)
cb = Counter(B)
mod = 10**6
cnts = [set() for _ in range(N+1)]
for i in range(1,N+1):
  if ca[i]+cb[i]>N:
    print('No')
    exit()
  if ca[i]+cb[i]>0:
    cnts[ca[i]+cb[i]].add(i)

def get_any(counts,r):
  for k in counts.keys():
    if counts[k]>0 and k!=r:
      return k

def update_cnt(cnt_,r):
  cnt_[r] -= 1
  if cnt_[r]==0:
    del cnt_[r]

lis = [[] for _ in range(N+1)]
for i in range(N,0,-1):
  if len(cnts[i])==2:
    p,q = cnts[i]
    for j in range(ca[p]):
      lis[p].append(q)
    for j in range(ca[q]):
      lis[q].append(p)
    break
  elif len(cnts[i])==1:
    p, = cnts[i]
    for j in range(ca[p]):
      q = get_any(cb,p)
      update_cnt(cb,q)
      lis[p].append(q)
    for j in range(cb[p]):
      q = get_any(ca,p)
      update_cnt(ca,q)
      lis[q].append(p)
    break
  else:
    p = get_any(ca,-1)
    q = get_any(cb,p)
    lis[p].append(q)
    cnts[ca[p]+cb[p]].remove(p)
    cnts[ca[q]+cb[q]].remove(q)
    update_cnt(ca,p)
    update_cnt(cb,q)
    cnts[ca[p]+cb[p]].add(p)
    cnts[ca[q]+cb[q]].add(q)
ans = []
for i in range(1,N+1):
  for b in lis[i]:
    ans.append(b)
print('Yes')
print(*ans)
### BUGGY CODE ###

if __name__ == '__main__':
    MOD = 1000000007
    s = input()
    n = len(s)

    dp = [[0 for _ in range(13)]]
    dp[0][0] = 1

    for i, c in enumerate(s):
        if c == "?":
            cn = -1
        else:
            cn = int(c)

        dp.append([0 for _ in range(13)])
        for j in range(10):
            if cn != -1 and cn != j: continue
            for ki in range(13):
                dp[i + 1][(ki * 10 + j) % 13] += dp[i][ki]
        for j in range(13):
            dp[i + 1][j] %= MOD
    result = dp[n][5]

    print(result)

### FIXED CODE ###

if __name__ == '__main__':
    MOD = 1000000007
    s = input()
    n = len(s)

    dp = [[0 for _ in range(13)]]
    dp[0][0] = 1

    for i, c in enumerate(s):
        if c == "?":
            cn = -1
        else:
            cn = int(c)

        dp.append([0 for _ in range(13)])
        for j in range(10):
            if cn != -1 and cn != j: continue
            for ki in range(13):
                dp[i + 1][(ki * 10 + j) % 13] += dp[i][ki]
        for j in range(13):
            dp[i + 1][j] %= MOD
    result = dp[n][5]

    print(result)
### BUGGY CODE ###

# sumitb2019_b_bacha.py
N = int(input())
for i in range(10000000):
    if int(i*1.08) == N:
        print(i)
        exit()
print(":(")




### FIXED CODE ###

# sumitb2019_b.py
import math 
N = int(input())
for i in range(50000):
    if math.floor(i*1.08) == N:
        print(i)
        exit()
print(":(")
### BUGGY CODE ###

a, b, c, k = map(int, input().split())

ans = 0

for i in range(k):
    if a >= 1:
        ans += 1
        a -= 1
    elif b >= 1:
        b -= 1
        pass
    else:
        ans -= 1
print(ans)


### FIXED CODE ###

a, b, c, k = map(int, input().split())

if k <= a:
    print(k)
elif k - a > b:
    print(-1 * ((k - a) - b) + a)
else:
    print(a)
### BUGGY CODE ###

n = int(input())
p = list(range(1, n+1))
mod = (10 ** 9) + 7

x = 1

for i in p:
    x *= i

print(x%mod)

### FIXED CODE ###

n = int(input())

def power(n):
  ans = 1
  for i in range(1, n+1):
    ans = ans * i % (10**9+7) 
  return ans

print(power(n))
### BUGGY CODE ###

from collections import deque 
n, m = map(int, input().split())
es = [[] for i in range(n)]
co = [[] for i in range(n)] # 有効辺の向きを逆にした
for i in range(n - 1 + m):
    a, b = map(int, input().split())    
    es[a - 1].append(b - 1)
    co[b - 1].append(a - 1)

v = 0
while co[v]:
    v = co[v][0]

parent = [-1] * n
parent[v] = 0

q = deque([v])

while q:
    v = q.popleft()
    for e in es[v]:
        parent[e] = v + 1
        q.append(e)

for i in parent:
    print(i)

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
n, m = map(int, input().split())
es = [[] for i in range(n)]
co = [[] for i in range(n)] # 有効辺の向きを逆にした
for i in range(n - 1 + m):
    a, b = map(int, input().split())    
    es[a - 1].append(b - 1)
    co[b - 1].append(a - 1)

dp = [-1] * n

def memo(v):
    if dp[v] != -1: #更新済
        return dp[v]
    a = 0
    for i in co[v]:
        a = max(a, memo(i) + 1)
    dp[v] = a
    return a

for i in range(n):
    memo(i)

parent = [0] * n
for v in range(n):
    for e in es[v]:
        if dp[v] + 1 == dp[e]:
            parent[e] = v + 1

for i in parent:
    print(i)
### BUGGY CODE ###

#!/usr/bin/env python3

import functools

def cmp1(p0, p1):
    (_, t0, a0), (_, t1, a1) = p0, p1
    return (t1 - a0) - (t0 - a1)

def cmp2(p0, p1):
    (_, t0, a0), (_, t1, a1) = p0, p1
    return (a1 - t0) - (a0 - t1)

n = int(input())
AB = [tuple([i] + [int(x) for x in input().split()]) for i in range(n)]
# hey atcoder Python 3.4 is too old

A = sorted(AB, key=functools.cmp_to_key(cmp1))
B = sorted(AB, key=functools.cmp_to_key(cmp2))
used = {-1}
a, b = -1, -1
ans = 0

for _ in range(n // 2):
    while a in used:
        a, s, _ = A.pop(0)
    used.add(a)
    ans += s

    while b in used:
        b, _, s = B.pop(0)
    used.add(b)
    ans -= s

if n % 2 == 1:
    while a in used:
        a, s, _ = A.pop(0)
    used.add(a)
    ans += s

print(ans)


### FIXED CODE ###

#!/usr/bin/env python3

n = int(input())
A = [tuple(int(x) for x in input().split()) for i in range(n)]
A.sort(key=lambda ab: -(ab[0] + ab[1]))
print(sum(a for a, _ in A[::2]) - sum(b for _, b in A[1::2]))
### BUGGY CODE ###

n, m = map(int, input().split())


ans = [1] * n
for i in range(m):
    l, r = map(int, input().split())
    ans[:l-1] = [0] * (l - 1)
    ans[r:] = [0] * (n - r)
print(sum(ans))

### FIXED CODE ###

n, m = map(int, input().split())

Left = -1
Right = n + 1
for i in range(m):
    l, r = map(int, input().split())
    Left = max(Left, l)
    Right = min(Right, r)
if Left <= Right:
    ans = Right - Left + 1
else:
    ans = 0
print(ans)
### BUGGY CODE ###

N = int(input())
S = []
count = 0
for i in range(N):
    S.append(sorted(input()))
for j in range(N-1):
    for k in range(j+1,N):
        f = True
        for l in range(10):
            if S[j][l] != S[k][l]:
                f = False
                break
        if f:
            count += 1
print(count)

### FIXED CODE ###

N = int(input())
S = []
count = 0
for i in range(N):
    S.append(sorted(input()))
S = sorted(S)
a = 'sing'
for j in range(N):
    if a != S[j]:
        f = 0
        a = S[j]
    else:
        f += 1
        count += f
print(count)
### BUGGY CODE ###

#!/usr/bin/env python3
# n,m = map(int,sys.stdin.readline().split())
# a = list(map(int,sys.stdin.readline().split()))
# a = [sys.stdin.readline() for _ in range(n)]
# s = sys.stdin.readline().rstrip()
# n = int(sys.stdin.readline())
import sys,bisect
sys.setrecursionlimit(15000)

s = sys.stdin.readline().rstrip()
cum = [0]*(len(s)+1)#cumulative sum
import collections
d = collections.defaultdict(list)
for i in range(len(s)):
    cum[i+1]=cum[i]+int(s[i])
for i in range(len(s)+1):
    d[cum[i]%3].append(i)
ret = 0
#print(cum,d)
for l in d.values():
    #print(l)
    n = len(l)
    can = [[l[i],l[j]] for i in range(n) for j in range(i,n) if l[j] > l[i]+3]
    #print(can)
    #print([[i,j,int(s[i:j])] for i,j in can if int(s[i:j])>2019 and int(s[i:j])%2019==0])
    #print([1 for i,j in can if int(s[i:j])>2019 and int(s[i:j])%2019==0])
    ret += sum(1 for i,j in can if int(s[i:j])>2019 and int(s[i:j])%2019==0)
print(ret)


### FIXED CODE ###

# n = int(sys.stdin.readline())
import sys,bisect,math
sys.setrecursionlimit(15000)

s = sys.stdin.readline().rstrip()
cum = [0]*(len(s)+1)#cumulative sum
import collections
d = collections.defaultdict(int)
d[0] = 1
ret = 0
dig = 1
for i in range(len(s))[::-1]:
    cum[i]=(int(s[i])*dig+cum[i+1])%2019
    dig = (dig*10)%2019
    #cum[i+1]=int(s[i:])%2019
    if cum[i] in d:
        ret += d[cum[i]]
    d[cum[i]] += 1
#print(d,cum,ret)
print(ret)
### BUGGY CODE ###

k=int(input())
a=list(map(int,input().split()))

for i in range(1,k):
  print(a.count(i))
print(0)

### FIXED CODE ###

k=int(input())
a=list(map(int,input().split()))
ans=[0 for x in range (2*(10**5))]
for i in range(k-1):
  ans[(a[i]-1)]+=1
for i in range(k):
  print(ans[i])
### BUGGY CODE ###

from collections import Counter
n = int(input())
s = input()
mod = 10**9+7
c = Counter(s)
cv = list(c.values())
cl = len(cv)
ans = 0
for i in range(1,1<<cl):
  da =1
  for j in range(cl):
    if (i>>j)%2:
      da *= cv[j]
  ans += da%mod
print(ans%mod)

### FIXED CODE ###

def main():
  from collections import Counter
  n = int(input())
  s = input()
  mod = 10**9+7
  c = Counter(s)
  cv = list(c.values())
  cl = len(cv)
  ans = 1
  for i in range(cl):
    ans *= (cv[i]+1)
  print((ans-1)%mod)
main()
### BUGGY CODE ###

N = int(input())
M = 10 ** 9 + 7

res = 1
for i in range(1, N + 1):
    res *= i

print(res % M)

### FIXED CODE ###

import math
n = int(input())
print(math.factorial(n) % (10**9 + 7))
### BUGGY CODE ###

N, Q = list(map(int, input().split()))
S = input()
T = [list(map(int, input().split())) for _ in range(Q)]

for i in range(Q):
  l, r = T[i][0], T[i][1]
  s = S[l-1:r]
  count = 0
  if r-l == 0:
    count = 0
  else:
    for j in range(r-l):
      if s[j] == 'A' and s[j+1] == 'C':
        count += 1
  print(count)

### FIXED CODE ###

N, Q = list(map(int, input().split()))
S = input()
T = [list(map(int, input().split())) for _ in range(Q)]

total_list = []
total = 0
try:
  for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C':
      total += 1
    total_list.append(total)

  for i in range(Q):
    l, r = T[i][0], T[i][1]
    if l != 1:
      print(total_list[r-2]-total_list[l-2])
    else:
      print(total_list[r-2])
except IndexError:
  print(0)
### BUGGY CODE ###

from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
MOD = 10 ** 9 + 7  
n = int(input())
A = list(map(int, input().split()))

l = 1
for i in A:
  l = lcm(l, i)
  
B = [(l // i) % MOD for i in A]

ans = 0
for i in B:
  ans = (ans + i) % MOD

print(ans)

### FIXED CODE ###

from fractions import gcd

def lcm(x, y):
  return (x * y) // gcd(x, y)

MOD = 10 ** 9 + 7  
n = int(input())
A = list(map(int, input().split()))

l = 1
for i in A:
  l = lcm(l, i)
l %= MOD

ans = 0
for i in A:
  ans += l * pow(i, MOD - 2, MOD)
  ans %= MOD
print(ans)
### BUGGY CODE ###

a,b,x=map(int,input().split())
sum=0
for i in range(a,b+1):
    if i%x==0:
        sum+=1
print(sum)

### FIXED CODE ###

a,b,x=map(int,input().split())
print(b//x-a//x+1 if a%x==0 else b//x-a//x)
### BUGGY CODE ###

import functools
N = int(input())

A = list(map(int,input().split()))
#print(A)
ans = []
for i in range(len(A)):
    B = A[:i]+A[i+1:]
    res = functools.reduce(lambda x, y: x ^ y, B)
    ans.append(res)
print(*ans)

### FIXED CODE ###

import functools
N = int(input())

A = list(map(int,input().split()))
#print(A)
s = A[0]
for num in A[1:]:
    s ^= num

res = [0] * N
for i,num in enumerate(A):
    res[i] = s^num
print(*res)
### BUGGY CODE ###

N, K = map(int,input().split())
h = [int(input()) for i in range(N)]
h.sort()
for i in list(set(h)):
  if(h.count(i) >= K):
    print('0')
    exit()
trees = h[:K]
h_max = max(trees)
h_min = min(trees)
print(h_max - h_min)

### FIXED CODE ###

N, K = map(int,input().split())
h = sorted([int(input()) for i in range(N)])
trees = [h[i+K-1] - h[i] for i in range(N-K+1)]
print(min(trees))
### BUGGY CODE ###

import sys
input = sys.stdin.readline
k, q = map(int, input().split())
d = list(map(int, input().split()))

query = []
for _ in range(q):
    query.append(list(map(int, input().split())))

def answer_query(n, x, m):
    l = []
    for i in range(k):
        l.append(d[i]%m)
    zero = l.count(0)
    total = sum(l)*((n-1)//k)
    total += x%m
    zero_total = zero*((n-1)//k)

    s = n
    n -= 1
    n -= n//k * k
    t = 0
    for i in range(n):
        t += l[i]
    total += t

    for i in range(n):
        if l[i] == 0:
            zero_total += 1

    return s-1-total//m-zero_total

for n, x, m in query:
    print(answer_query(n, x, m))


### FIXED CODE ###

import sys
input = sys.stdin.readline
k, q = map(int, input().split())
d = list(map(int, input().split()))
query = [None]*q
for i in range(q):
    query[i] = list(map(int, input().split()))

def answer_query(n, x, m):
    l = [m if i%m == 0 else i%m for i in d]
    count = n // k
    rem = n % k
    s = sum(l)
    total = s%m * count + x%m
    for i in range(rem):
        total += l[i]

    total //= m
    total += s//m * count

    print(n-total)


for n, x, m in query:
    answer_query(n-1, x, m)
### BUGGY CODE ###

import itertools
N,M,R=map(int, raw_input().split())
r=map(int, raw_input().split())

dp=[ [ float("inf") for i in range(N+1)] for i in range(N+1) ]

for i in range(M):
	A,B,C=map(int, raw_input().split())
	dp[A][B]=C
	dp[B][A]=C

for i in range(N+1): dp[i][i]=0


for k in range(N+1):
	for x in range(N+1):
		for y in range(N+1):
			dp[x][y]=min( dp[x][y], dp[x][k]+dp[k][y] )


l=list(itertools.permutations(r))


ans=float("inf")

for i in l:
	dist=0
	for j in range(R):
		if j==0:
			prev=i[j]
			continue
		cur=i[j]
		dist+=dp[prev][cur]
		prev=cur
	ans=min(ans,dist)

print ans





### FIXED CODE ###

import heapq
import itertools
N,M,R=map(int, raw_input().split())
r=map(int, raw_input().split())

cost=[ [ float("inf") for i in range(N+1)] for i in range(N+1) ]
nl=[ [] for i in range(N+1) ]

for i in range(M):
	A,B,C=map(int, raw_input().split())
	cost[A][B]=C
	cost[B][A]=C
	nl[A].append(B)
	nl[B].append(A)


for i in range(N+1): cost[i][i]=0


def Dij(start):

	#Initialize
	d=[float("inf") for i in range(N+1)]
	d[start]=0
	q=[]
	heapq.heappush(q,(0,start))
	
	while len(q)!=0:
		tmp=heapq.heappop(q)
		u=tmp[1]

		for v in nl[u]:
			alt=d[u]+cost[u][v]
			if d[v]>alt:
				d[v]=alt
				heapq.heappush(q,(alt,v))
	return d


l=list(itertools.permutations(r))

C={}
for i in r:
	C[i]=Dij(i)


ans=float("inf")


for i in l:
	dist=0
	for j in range(R):
		if j==0:
			prev=i[j]
			continue
		cur=i[j]
		dist+=C[prev][cur]
		prev=cur
	ans=min(ans,dist)

print ans
### BUGGY CODE ###

from collections import deque
import numpy as np

num_r,num_c = map(int,input().split())
field = [list(input()) for i in range(num_r)]
q_r = deque([])
q_c = deque([])
seen = np.zeros((num_r,num_c))
step_r = [1,0,-1,0]
step_c = [0,1,0,-1]

for i in range(num_r):
  for j in range(num_c):
    if field[i][j] == "#":
      q_r.append(i)
      q_c.append(j)
      g_r = 0
      g_c = 0

while q_r:
  r = q_r.popleft()
  c = q_c.popleft()

  for i in range(4):
    next_r = r + step_r[i]
    next_c = c + step_c[i]
    
    if (0 <= next_r < num_r) and (0 <= next_c < num_c) and (field[next_r][next_c] != "#"):
      field[next_r][next_c] = "#"
      q_r.append(next_r)
      q_c.append(next_c)
      seen[next_r][next_c] = seen[r][c] + 1
  #    print(seen[next_r][next_c],next_r,next_c)
      g_r = next_r
      g_c = next_c

print(int(seen[g_r][g_c]))

### FIXED CODE ###

def main():
    h,w = map(int,input().split())
    a = []
    for i in range(h):
        a.append(input())

    used = [True]*(h*w)

    p = []
    for i in range(h):
        for j in range(w):
            if a[i][j] == '#':
                p.append(i*w+j)
                used[i*w+j] = False


    
    res = 0
    while p:
        tank = []
        for e in p:
            if e>w-1 and used[e-w]:
                tank.append(e-w)
                used[e-w] = False
            if e%w > 0 and used[e-1]:
                tank.append(e-1)
                used[e-1] = False
            if e<(h-1)*w and used[e+w]:
                tank.append(e+w)
                used[e+w] = False
            if e%w<w-1 and used[e+1]:
                tank.append(e+1)
                used[e+1] =  False
        p = tank
        res += 1
    print(res-1)

if __name__ == '__main__':
    main()
### BUGGY CODE ###

from collections import deque
''' 
INF = float('inf')
MOD = 10 ** 9 + 7
'''
## ここは１つにまとめれる
# dy = (0, -1, 0, 1)
# dx = (1, 0, -1, 0)
d=[(1,0),(0,1),(-1,0),(0,-1)]

    
H,W=map(int,input().split())
M = []
Max_list = []
for i  in range(H):
    t = input()
    M.append(t)
dist = [[-1]*W for _ in range(H)]
q = deque()
for i in range(H):
    for j in range(W):
        dist = [[-1]*W for _ in range(H)]
        if M[i][j] == '.':
            Ma = 0
            q.append((i, j))
            dist[i][j] = 0
            while q:
                cx,cy = q.popleft()
                for nx,ny in d:
                    x ,y= cx+nx,cy+ny
                    ''' ここの処理がをnotにしてわかりやすく
                    if x<0 or y<0 or x>=H or y>=W or dist[x][y]>0:
                        continue
                    '''
                    '''
                    if 0<= x < H and 0<= y < W and dist[x][y]<=0:
                    '''
                    if 0<= x < H and 0<= y < W and M[x][y] == ".":
                        dist[x][y]=dist[cx][cy]+1
                        Ma = max(Ma,dist[x][y])
                        q.append((x,y))
            Max_list.append(Ma)

print(max(Max_list))

### FIXED CODE ###

from collections import deque
 
INF = float('inf')
MOD = 10 ** 9 + 7
dy = (0, -1, 0, 1)
dx = (1, 0, -1, 0)


H,W=map(int,input().split())
M = []
Max_list = []
for i  in range(H):
    t = input()
    M.append(t)
dx = [0,0,-1,1]
dy = [1,-1,0,0]
dist = [[-1]*W for _ in range(H)]
q = deque()
for i in range(H):
    for j in range(W):
        dist = [[-1]*W for _ in range(H)]
        if M[i][j] == '.':
            Ma = 0
            q.append((i, j))
            dist[i][j] = 0
            while q:
                cx,cy = q.popleft()
                for nx,ny in zip(dx,dy):
                    x ,y= cx+nx,cy+ny
                    if x<0 or y<0 or x>=H or y>=W or dist[x][y]>0:
                        continue
                    if M[x][y] == "." and dist[x][y] == -1:
                        dist[x][y]=dist[cx][cy]+1
                        Ma = max(Ma,dist[x][y])
                        q.append((x,y))
            # print(Ma)
            Max_list.append(Ma)
# print(Max_list)

print(max(Max_list))
### BUGGY CODE ###

n, a =map(int, input().split())
x=list(map(int, input().split()))
x=[i-a for i in x]
memo=[[-1]*100000 for i in range(60)]
def dp(k, value):
    if k==n:
        if value==0:
            return 1
        else:
            return 0
    if memo[k][value]>0:
        return memo[k][value]
    memo[k][value]=dp(k+1, value+x[k])+dp(k+1, value)
    return memo[k][value]
print(dp(0, 0)-1)

### FIXED CODE ###

n, a = map(int, input().split())
x=list(map(lambda x: int(x)-a, input().split()))
k=[[0]*3000 for i in range(60)]
for i in range(3000):
    k[0][i]=0
k[0][x[0]+1500]+=1
k[0][1500]+=1
for i in range(1, n):
    for j in range(3000):
        if 3000>j-x[i]>=0:
            k[i][j]=k[i-1][j-x[i]]+k[i-1][j]
        else:
            k[i][j]=k[i-1][j]
print(k[n-1][1500]-1)
### BUGGY CODE ###

import heapq
#printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
#inm   = lambda:      map(int, input().split())
DBG = True  and False
#def ddprint(x):
#  if DBG:
#    print(x)

q = inn()
x = inl()
root = x[1]
b = x[2]
tl = []
tr = []
nl = nr = suml = sumr = 0
#ddprint("q " + str(q))
for i in range(1,q):
    #ddprint("i " + str(i))
    x = inl()
    if len(x)==1:
        z = sumr - suml - (root if nr>nl else 0) + b
        print("{} {}".format(root,z))
    else:
        a = x[1]
        b += x[2]
        if nl == nr:
            aa = -heapq.heappushpop(tl,-a)
            suml += a - aa
            if aa<root:
                aa,root = root,aa
            heapq.heappush(tr,aa)
            sumr += aa
            nr += 1
        else:
            aa = heapq.heappushpop(tr,a)
            sumr += a - aa
            if aa>root:
                aa,root = root,aa
            heapq.heappush(tl,-aa)
            suml += aa
            nl += 1
        #ddprint("b {} root {} nl {} nr {} suml {} sumr {}".format(b,root,nl,nr,suml,sumr))
        #ddprint(tl)
        #ddprint(tr)


### FIXED CODE ###

import heapq
#printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
#inm   = lambda:      map(int, input().split())
DBG = True  and False
#def ddprint(x):
#  if DBG:
#    print(x)

q = inn()
x = inl()
root = x[1]
b = x[2]
tl = []
tr = []
nl = nr = suml = sumr = 0
#ddprint("q " + str(q))
for i in range(1,q):
    #ddprint("i " + str(i))
    x = inl()
    if len(x)==1:
        z = sumr - suml - (root if nr>nl else 0) + b
        print("{} {}".format(root,z))
    else:
        a = x[1]
        b += x[2]
        if nl == nr:
            aa = -heapq.heappushpop(tl,-a)
            suml += a - aa
            if aa<root:
                aa,root = root,aa
            heapq.heappush(tr,aa)
            sumr += aa
            nr += 1
        else:
            aa = heapq.heappushpop(tr,a)
            sumr += a - aa
            if aa>root:
                aa,root = root,aa
            heapq.heappush(tl,-aa)
            suml += aa
            nl += 1
        #ddprint("b {} root {} nl {} nr {} suml {} sumr {}".format(b,root,nl,nr,suml,sumr))
        #ddprint(tl)
        #ddprint(tr)
### BUGGY CODE ###

import math


def sieve_of_erastosthenes(num):
    input_list = [False if i % 2 == 0 or i % 3 == 0 or i % 5 == 0 else True for i in range(num)]
    input_list[0] = input_list[1] = False
    input_list[2] = input_list[3] = input_list[5] = True
    sqrt = math.sqrt(num)

    for serial in range(3, num, 2):
        
        if serial >= sqrt:
            return input_list

        for s in range(serial ** 2, num, serial): 
            input_list[s] = False


if __name__ == '__main__':
    while True:
        try:
            n = int(input())
        except:
            break

        if 5 >= n:
            print(1)

        else:
            input_list = sieve_of_erastosthenes(n)

            print(sum(input_list))

### FIXED CODE ###

a = [True for i in range(1000000)]
i = 3
while i * i < 1000000:
    for j in range(3 * i, 1000000, 2 * i): a[j] = False
    i += 2
 
while True:
    try:
        n = int(input())
    except:
        break
 
    count = int(n >= 2) + sum(a[i] for i in range(3, n + 1, 2))
    print(count)
### BUGGY CODE ###

s = input()
if(len(s) < 5):
    print(0)
else:
    t = [0]*2019
    t[0] = 1
    p = 0
    for i in range(1,len(s)+1):
        t[int(s[-i:])%2019] += 1
    for i in range(2019):
        p += (t[i]*(t[i]-1))//2
    print(p)

### FIXED CODE ###

s = input()
if(len(s) < 5):
    print(0)
else:
    t = [0]*2019
    t[0] = 1
    p = 0
    temp = 0
    temp2 = 1
    for i in range(1,len(s)+1):
        temp2 *= 10
        temp2 %= 2019
        t[(temp + temp2*int(s[-i]))%2019] += 1
        temp += temp2*int(s[-i])
    for i in range(2019):
        p += (t[i]*(t[i]-1))//2
    print(p)