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

def main():
    S=input()
    Q=int(input())
    Left=[]
    Right=[]

    reverse_flag=0
    for i in range(Q):
        query=input().split()
        if query[0]=="1":
            if reverse_flag==1:
                reverse_flag=0
            else:
                reverse_flag=1
        else:
            if query[1]=="1":
                if reverse_flag==0:
                    Left.append(query[2])
                else:
                    Right.append(query[2])
            else:
                if reverse_flag==0:
                    Right.append(query[2])
                else:
                    Left.append(query[2])

    res=""
    if reverse_flag==0:
        for i in range(len(Left)-1,-1,-1):
            res+=Left[i]
        res+=S
        for r in Right:
            res+=r
    else:
        for i in range(len(Right)-1,-1,-1):
            res+=Right[i]
            
        for i in range(len(S)-1,-1,-1):
            res+=S[i]

        for l in Left:
            res+=l
    print(res)

if __name__=="__main__":
    main()

### FIXED CODE ###

def main():
    S=input()
    Q=int(input())
    Left=[]
    Right=[]

    reverse_flag=0
    for i in range(Q):
        query=input().split()
        if query[0]=="1":
            if reverse_flag==1:
                reverse_flag=0
            else:
                reverse_flag=1
        else:
            if query[1]=="1":
                if reverse_flag==0:
                    Left.append(query[2])
                else:
                    Right.append(query[2])
            else:
                if reverse_flag==0:
                    Right.append(query[2])
                else:
                    Left.append(query[2])

    res=""
    if reverse_flag==0:
        Left.reverse()
        res+="".join(Left)
        res+=S
        res+="".join(Right)

    else:
        Right.reverse()
        res+="".join(Right)
        S=list(S)
        S.reverse()
        res+="".join(S)
        res+="".join(Left)
    print(res)

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

import itertools
from collections import defaultdict
H,W,N=map(int, raw_input().split())

d=[-1,0,1]
D=list(itertools.product(d,d))

C=set()	#Center
A=[]
for i in range(N):
	a,b=map(int, raw_input().split())
	A.append((a,b))
	for dx,dy in D:
		cx=a+dx
		cy=b+dy
		if cx>=2 and cx<=H-1 and cy>=2 and cy<=W-1:
			C.add( (cx,cy) )



l=defaultdict(lambda: 0)

for x,y in C:
	cnt=0
	for i,j in D:
		#print x+i,y+j,A[x+i][y+j]
		if (x+i, y+j) in A:
			cnt+=1
	l[cnt]+=1



for i in range(10):
	if i==0:
		print (H-2)*(W-2)-sum(l.values())
	else:
		print l[i]




### FIXED CODE ###

import itertools
from collections import defaultdict
from collections import Counter
H,W,N=map(int, raw_input().split())

d=[-1,0,1]
D=list(itertools.product(d,d))

A=defaultdict(lambda: 0)
for i in range(N):
	a,b=map(int, raw_input().split())
	for dx,dy in D:
		cx=a+dx
		cy=b+dy
		if cx>=2 and cx<=H-1 and cy>=2 and cy<=W-1:
			A[(cx,cy)]+=1

C=Counter(A.values())


for i in range(10):
	if i==0:
		print (H-2)*(W-2)-sum(C.values())
	else:
		print C[i]
### BUGGY CODE ###

N, K = map(int, input().split())
p = list(map(int, input().split()))

res = 0

p = list(map(lambda x:(x+1)/2, p))
for i in range(N-K+1):
    kk = 0
    for j in range(K):
        kk += p[i+j]
    res = max(res, kk)

print(res)

### FIXED CODE ###

N, K = map(int, input().split())
p = list(map(int, input().split()))

kk = sum(p[:K])
res = kk

for i in range(N-K):
    kk += p[K+i] - p[i]
    res = max(res, kk)

res = res/2 + K/2
print(res)
### BUGGY CODE ###

A, B = map(int, input().split())

# def int2bin(x):
#     quotient = x
#     string_bin = ''
#     while(quotient != 1):
#         rest = quotient % 2
#         quotient = int((quotient - rest) / 2)
#         string_bin = str(rest) + string_bin
#     string_bin = '1' + string_bin
#     return int(string_bin)
#
# def bin2int(x):
#     power = int(len(str(x)) - 1)
#     integer = 0
#     i = 0
#     while(power >= 0):
#         integer += 2**power * int(str(x)[i])
#         i += 1
#         power -= 1
#     return integer


# divided_bin_str1 = str(int2bin(A))
# for divided in range(A+1, B+1):
#     added = '0'
#     divided_bin_str2 = str(int2bin(divided))
#     if len(divided_bin_str1) < len(divided_bin_str2):
#         divided_bin_str1 = '0' + divided_bin_str1
#     else:
#         pass
#     # print(divided_bin_str1, divided_bin_str2)
#     for i in range(len(divided_bin_str1)):
#         ans = int(divided_bin_str1[i]) + int(divided_bin_str2[i])
#         if ans == 1:
#             added += '1'
#         else:
#             if added == '0':
#                 pass
#             else:
#                 added += '0'
#     divided_bin_str1 = added
#
# added = int(added)
# ans = bin2int(added)
#
# print(ans)

summary = A
for XORed in range(A+1, B+1):
    summary = summary ^ XORed

print(summary)


### FIXED CODE ###

A, B = map(int, input().split())

# summary = A
# for XORed in range(A+1, B+1):
#     summary = summary ^ XORed

def XORfromZERO(x):
    rest = x % 2
    quotient = (x + rest) / 2
    if rest == 0:
        if quotient % 2 == 0:
            return 0 ^ x
        else:
            return 1 ^ x
    else:
        if quotient % 2 == 0:
            return 0
        else:
            return 1

print(XORfromZERO(A-1) ^ XORfromZERO(B))
### BUGGY CODE ###

from bisect import*
N,*A=map(int,open(0))
L=[A[0]]
for x in A[1:]:
	i=bisect_left(L,x)
	if i==0:L=[x]+L
	else:L[i-1]=x
print(len(L))

### FIXED CODE ###

from collections import*
from bisect import*
N,*A=map(int,open(0))
q=deque([A[0]])
for x in A[1:]:
	i=bisect_left(q,x)
	if i==0:q.appendleft(x)
	else:q[i-1]=x
print(len(q))
### BUGGY CODE ###

INF = float('inf')
N, C = map(int, input().split())
D = list() #D[i][j]:=iからjに変える時の違和感
graph = list()
for i in range(C):
  D.append(list(map(int, input().split())))
for i in range(N):
  graph.append(list(map(int, input().split())))
ans = INF
for c0 in range(C):
  for c1 in range(C):
    for c2 in range(C):
      if(c0 == c1 or c1 == c2 or c2 == c0):
        continue
      tmp = 0
      for x in range(N):
        for y in range(N):
          p = (x+y+2)%3
          c = graph[x][y]-1
          if(p == 0):
            tmp += D[c][c0]
          elif(p == 1):
            tmp += D[c][c1]
          else:
            tmp += D[c][c2]
      ans = min(tmp, ans)
print(ans)

### FIXED CODE ###

INF = float('inf')
N, C = map(int, input().split())
D = list() #D[i][j]:=iからjに変える時の違和感
graph = list()
for i in range(C):
  D.append(list(map(int, input().split())))
for i in range(N):
  graph.append(list(map(int, input().split())))
E = [[0] * C for _ in range(3)] #E[i][j]:=mod3でiの場所を全て色jにしたときの違和感
for c in range(C):
  for x in range(N):
    for y in range(N):
      p = (x+y+2)%3
      cxy = graph[x][y]-1
      E[p][c] += D[cxy][c]
F = [[[INF]*2 for _ in range(3)] for _ in range(3)] 
#F[i][j][k]:=mod3でiの場所の違和感の最小値第j+1位。k=0色番号, k=1最小値]
for i in range(3):
  for j in range(C):
    if(E[i][j] < F[i][0][1]):
      F[i][2] = F[i][1]
      F[i][1] = F[i][0]
      F[i][0] = [j, E[i][j]]
    elif(E[i][j] < F[i][1][1]):
      F[i][2] = F[i][1]
      F[i][1] = [j, E[i][j]]
    elif(E[i][j] < F[i][2][1]):
      F[i][2] = [j, E[i][j]]
      
ans = INF
for i in range(3):
  for j in range(3):
    for k in range(3):
      c0 = F[0][i][0]
      c1 = F[1][j][0]
      c2 = F[2][k][0]
      if(c0 != c1 and c1 != c2 and c2 != c0):
        ans = min(ans, F[0][i][1]+F[1][j][1]+F[2][k][1])
print(ans)
### BUGGY CODE ###

n,m=map(int,input().split())
p=list(map(int,input().split()))
rank=[0 for i in range(n)]
r=[i for i in range(n)]
sp=[{p[i]-1} for i in range(n)]
def union(x,y):
  rx=root(x)
  ry=root(y)
  if rx==ry:
    sp[rx]=sp[rx]|sp[ry]
  else:
    r[ry]=rx
    sp[rx]=sp[rx]|sp[ry]
    if r[rx]==r[ry]:
      rank[rx]+=1
def root(x):
  if x==r[x]:
    return x
  else:
    r[x]=root(r[x])
    return r[x]
def get(x):
  return sp[root(x)]
for i in range(m):
  a,b=map(int,input().split())
  union(a-1,b-1)
ans=0
for i in range(n):
  if (i in get(i)) or i+1==p[i]:
    ans+=1
print(ans)

### FIXED CODE ###

n,m=map(int,input().split())
p=list(map(int,input().split()))
r=[i for i in range(n)]
def union(x,y):
  rx=root(x)
  ry=root(y)
  if rx==ry:
    return
  else:
    r[rx]=ry
def root(x):
  if x==r[x]:
    return x
  else:
    r[x]=root(r[x])
    return r[x]
for i in range(m):
  a,b=map(int,input().split())
  union(a-1,b-1)
ans=0
for i in range(n):
  if root(i)==root(p[i]-1) or i+1==p[i]:
    ans+=1
print(ans)
### BUGGY CODE ###

import sys
read = sys.stdin.buffer.read

n,*X=map(int,read().split())
mod = 10**9+7
last=X[-1]
X=[last-i for i in X[:-1]]
l=1
left=[1]
for i in range(1, n-1):
  l=l*i%mod
  left.append(l)
r=1
right=[1]
for i in range(n-1, 1, -1):
  r*=i%mod
  right.append(r)
right.reverse()
flst=[i*j%mod for i,j in zip(left,right)]
s = sum(i*j%mod for i,j in zip(X,flst))
print(s%mod)

### FIXED CODE ###

# https://atcoder.jp/contests/dwacon6th-prelims/submissions/9426910


def solve():
    MOD = 10**9 + 7

    N = int(input())
    xs = list(map(int, input().split()))

    ds = []
    for i in range(N-1):
        d = xs[i+1] - xs[i]
        ds.append(d)

    nums = [1, 1]
    num = 1
    for i in range(2, N-1):
        num *= i
        num %= MOD
        nums.append(num)

    ms = [N-1]
    m = N-1
    for i in reversed(range(2, N-1)):
        m *= i
        m %= MOD
        ms.append(m)
    ms.reverse()
    ms.append(1)

    ks = []
    k = 0
    for num, m in zip(nums, ms):
        k += num*m % MOD
        k %= MOD
        ks.append(k)

    ans = 0
    for d, k in zip(ds, ks):
        ans += d*k % MOD
        ans %= MOD

    print(ans)

solve()
### BUGGY CODE ###

k = int(input())
d = int(input())

li = list(map(int,(list(str(k)))))
leng = len(li)
mod = 10**9+7

dp1 = [0 for _ in range(d)]
dp2 = [0 for _ in range(d)]

mm1 = li[0]
for i in range(mm1):
    dp2[i%d] += 1

for i in range(1,leng):
    for j in range(0,10):
        for l in range(d):
            #既にk以下であることが確定
            dp1[(l+j)%d] += dp2[l]
            dp1[(l+j)%d] %= mod

        #上からi桁目でk以下が確定
        if j<li[i]:
            dp1[(mm1+j)%d] += 1
            dp1[(mm1+j)%d] %= mod
    #print(dp1,dp2)
    mm1 = (mm1+li[i])%d
    dp2 = [dp1[i] for i in range(d)]
    dp1 = [0 for _ in range(d)]
dp2[sum(li)%d]+=1
print((dp2[0]-1)%mod)   








### FIXED CODE ###

k = int(input())
d = int(input())

li = list(map(int,(list(str(k)))))
leng = len(li)
mod = 10**9+7

dp1 = [0 for _ in range(d)]
dp2 = [0 for _ in range(d)]

mm1 = li[0]
for i in range(mm1):
    dp2[i%d] += 1

for i in range(1,leng):
    for j in range(0,10):
        for l in range(d):
            #既にk以下であることが確定
            dp1[(l+j)%d] += dp2[l]
            dp1[(l+j)%d] %= mod

        #上からi桁目でk以下が確定
        if j<li[i]:
            dp1[(mm1+j)%d] += 1
            dp1[(mm1+j)%d] %= mod
    #print(dp1,dp2)
    mm1 = (mm1+li[i])%d
    dp2 = [dp1[i] for i in range(d)]
    dp1 = [0 for _ in range(d)]
dp2[sum(li)%d]+=1
print((dp2[0]-1)%mod)
### BUGGY CODE ###

n = int(input())
p = list(map(int,input().split()))

ret = 0
for i in range(n):
    f = True
    for j in range(i):
        f = f and (p[i] <= p[j])
    if f:
        ret +=1

print(ret)

### FIXED CODE ###

n = int(input())
p = list(map(int, input().split()))

mn = p[0]
ret = 0
for i in range(n):
    if mn >= p[i]:
        ret += 1
    mn = min(mn, p[i])
print(ret)
### BUGGY CODE ###

N, P = list(map(int, input().split()))

now_max = 1

for i in range(round(P ** (1 / N)) + 1, 0, -1):
    if P % (i ** N) == 0:
        now_max = i
        break

print(now_max)

### FIXED CODE ###

n, p = map(int, input().split())
if n == 1:
    print(p)
else:
    for i in range(1, round(p**(1/n))+1):
        if p % i**n ==0:
            res = i
    print(res)
### BUGGY CODE ###

import sys

from math import floor


def check(t):
    maxx, minx, maxy, miny = float(-1e9), float(1e9), float(-1e9), float(1e9)
    for x, y in dots['R']:
        maxx = max(maxx, x + t)
        minx = min(minx, x + t)
        maxy = max(maxy, y)
        miny = min(miny, y)
    for x, y in dots['L']:
        maxx = max(maxx, x - t)
        minx = min(minx, x - t)
        maxy = max(maxy, y)
        miny = min(miny, y)
    for x, y in dots['U']:
        maxx = max(maxx, x)
        minx = min(minx, x)
        maxy = max(maxy, y + t)
        miny = min(miny, y + t)
    for x, y in dots['D']:
        maxx = max(maxx, x)
        minx = min(minx, x)
        maxy = max(maxy, y - t)
        miny = min(miny, y - t)
    return (maxx - minx) * (maxy - miny)


n = int(input())
dots = {'R': set(), 'L': set(), 'U': set(), 'D': set()}
for line in sys.stdin:
    x, y, d = line.rstrip().split()
    x, y = int(x), int(y)
    dots[d].add((x, y))

l = 0.0
r = float(1 << 27)

while l <= r - 1:
    m1 = floor(l + r) / 2
    m2 = m1 + 0.5
    c1 = check(m1)
    c2 = check(m2)
    # print(l, r, m1, m2, c1, c2)
    if c1 > c2:
        l = m1
    else:
        r = m2

ans = float(1e18)
l = floor(l * 2) / 2
while l <= r + 1:
    ans = min(ans, check(l))
    l += 0.5
print(ans)


### FIXED CODE ###

import sys

from math import floor


def check(t):
    maxx, minx, maxy, miny = ud_maxx, ud_minx, lr_maxy, lr_miny
    for x, y in dots['R']:
        maxx = max(maxx, x + t)
        minx = min(minx, x + t)
    for x, y in dots['L']:
        maxx = max(maxx, x - t)
        minx = min(minx, x - t)
    for x, y in dots['U']:
        maxy = max(maxy, y + t)
        miny = min(miny, y + t)
    for x, y in dots['D']:
        maxy = max(maxy, y - t)
        miny = min(miny, y - t)
    return (maxx - minx) * (maxy - miny)


n = int(input())
dots = {'R': set(), 'L': set(), 'U': set(), 'D': set()}
lr_maxy, lr_miny, ud_maxx, ud_minx = -1e9, 1e9, -1e9, 1e9
for line in sys.stdin:
    x, y, d = line.rstrip().split()
    x, y = int(x), int(y)
    dots[d].add((x, y))
    if d in 'LR':
        lr_maxy = max(lr_maxy, y)
        lr_miny = min(lr_miny, y)
    else:
        ud_maxx = max(ud_maxx, x)
        ud_minx = min(ud_minx, x)

l = 0.0
r = float(1 << 30)

while l < r - 1:
    m1 = l + floor((r - l) / 3 * 2) / 2
    m2 = l + floor((r - l) / 3 * 4) / 2
    c1 = check(m1)
    c2 = check(m2)
    # print(l, r, m1, m2, c1, c2)
    if c1 >= c2:
        l = m1
    else:
        r = m2

ans = float(1e17)
l = max(0.0, floor(l * 2 - 16) / 2)
while l <= r + 8:
    ans = min(ans, check(l))
    l += 0.5
print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3
import heapq

h, w = map(int, input().split())
cx, cy = map(lambda x: int(x) - 1, input().split())
dx, dy = map(lambda x: int(x) - 1, input().split())
s = [input() for _ in range(h)]
c = [[10**6] * w for _ in range(h)]


def bfs():
    d = ((1, 0), (-1, 0), (0, 1), (0, -1))
    d2 = (
        (-2, -2),
        (-2, -1),
        (-2, 0),
        (-2, 1),
        (-2, 2),
        (-1, -2),
        (-1, -1),
        (-1, 1),
        (-1, 2),
        (0, -2),
        (0, 2),
        (1, -2),
        (1, -1),
        (1, 1),
        (1, 2),
        (2, -2),
        (2, -1),
        (2, 0),
        (2, 1),
        (2, 2),
    )
    hp = []

    heapq.heappush(hp, (0, (cx, cy)))
    c[cx][cy] = 0

    while hp:
        cp, (
            x,
            y,
        ) = heapq.heappop(hp)
        if (x, y) == (dx, dy):
            c[x][y] = cp
            break
        for i in range(4):
            nx = x + d[i][0]
            ny = y + d[i][1]
            if 0 <= nx < h and 0 <= ny < w and s[nx][ny] != "#" and c[nx][
                    ny] > cp:
                heapq.heappush(hp, (cp, (nx, ny)))
                c[nx][ny] = cp
        cp += 1
        for i in range(20):
            nx = x + d2[i][0]
            ny = y + d2[i][1]
            if 0 <= nx < h and 0 <= ny < w and s[nx][ny] != "#" and c[nx][
                    ny] > cp:
                c[nx][ny] = cp
                heapq.heappush(hp, (cp, (nx, ny)))

    return c[dx][dy] if c[dx][dy] < 10**6 else -1


print(bfs())


### FIXED CODE ###

#!/usr/bin/env python3
import heapq

h, w = map(int, input().split())
cx, cy = map(lambda x: int(x) - 1, input().split())
dx, dy = map(lambda x: int(x) - 1, input().split())
s = [input() for _ in range(h)]
c = [[10**6] * w for _ in range(h)]


def bfs():
    d = ((1, 0), (-1, 0), (0, 1), (0, -1))
    d2 = (
        (-2, -2),
        (-2, -1),
        (-2, 0),
        (-2, 1),
        (-2, 2),
        (-1, -2),
        (-1, -1),
        (-1, 1),
        (-1, 2),
        (0, -2),
        (0, 2),
        (1, -2),
        (1, -1),
        (1, 1),
        (1, 2),
        (2, -2),
        (2, -1),
        (2, 0),
        (2, 1),
        (2, 2),
    )
    hp = []

    heapq.heappush(hp, (0, (cx, cy)))
    c[cx][cy] = 0

    while hp:
        cp, (
            x,
            y,
        ) = heapq.heappop(hp)
        if (x, y) == (dx, dy):
            c[x][y] = cp
            break
        for i in range(4):
            nx = x + d[i][0]
            ny = y + d[i][1]
            if 0 <= nx < h and 0 <= ny < w and s[nx][ny] != "#" and c[nx][
                    ny] > cp:
                heapq.heappush(hp, (cp, (nx, ny)))
                c[nx][ny] = cp
        cp += 1
        for i in range(20):
            nx = x + d2[i][0]
            ny = y + d2[i][1]
            if 0 <= nx < h and 0 <= ny < w and s[nx][ny] != "#" and c[nx][
                    ny] > cp:
                c[nx][ny] = cp
                heapq.heappush(hp, (cp, (nx, ny)))

    return c[dx][dy] if c[dx][dy] < 10**6 else -1


print(bfs())
### BUGGY CODE ###

# -*- coding: utf-8 -*-
#import matplotlib.pyplot as plt
#import numpy as np

from bisect import bisect
from operator import itemgetter
def inpl(): return list(map(int, input().split()))


class BIT:
    def __init__(self, N):
        self.size = 2 ** (int.bit_length(N)+1)
        self.tree = [0]*(self.size + 1)

    def sum(self, i):
        res = 0
        while i:
            res += self.tree[i]
            i -= (i & -(i))
        return res

    def add(self, i, x):
        if i == 0:
            return
        while i <= self.size:
            self.tree[i] += x
            i += (i & -(i))


class RABIT():
    # range add BIT
    def __init__(self, N):
        self.bit0 = BIT(N)
        self.bit1 = BIT(N)

    def sum(self, i):
        return i*self.bit1.sum(i) + self.bit0.sum(i)

    def add_range(self, l, r, x):
        self.bit0.add(l, -x*(l-1))
        self.bit1.add(l, x)
        self.bit0.add(r+1, x*r)
        self.bit1.add(r+1, -x)

    def get_range(self, l, r):
        return self.sum(r) - self.sum(l-1)


N, M = inpl()
R, L, S = [], [], []
Q = []
for _ in range(N):
    l, r = inpl()
    Q.append((l, r, (r-l+1)))

Q = sorted(Q, key=itemgetter(2), reverse=True)
rabit = RABIT(M+1)

Lmin = M
Rmax = 0
for i in range(1, M+1):
    while Q and Q[-1][2] < i:
        l, r, _ = Q.pop()
        rabit.add_range(l, r, 1)
        Lmin = min(Lmin, l)
        Rmax = max(Rmax, r)
    ans = len(Q)
    for j in range(-(-Lmin//i) * i, Rmax+1, i):
        ans += rabit.get_range(j, j)
    print(ans)

### FIXED CODE ###

from bisect import bisect
from operator import itemgetter

import sys
input = sys.stdin.readline

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


class BIT:
    def __init__(self, N):
        self.size = 2 ** (int.bit_length(N)+1)
        self.tree = [0]*(self.size + 1)

    def sum(self, i):
        res = 0
        while i:
            res += self.tree[i]
            i -= (i & -(i))
        return res

    def add(self, i, x):
        if i == 0:
            return
        while i <= self.size:
            self.tree[i] += x
            i += (i & -(i))


class RABIT():
    # range add BIT
    def __init__(self, N):
        self.bit0 = BIT(N)
        self.bit1 = BIT(N)

    def sum(self, i):
        return i*self.bit1.sum(i) + self.bit0.sum(i)

    def add_range(self, l, r, x):
        self.bit0.add(l, -x*(l-1))
        self.bit1.add(l, x)
        self.bit0.add(r+1, x*r)
        self.bit1.add(r+1, -x)

    def get_range(self, l, r):
        return self.sum(r) - self.sum(l-1)


N, M = inpl()
R, L, S = [], [], []
Q = []
for _ in range(N):
    l, r = inpl()
    Q.append((l, r, (r-l+1)))

Q = sorted(Q, key=itemgetter(2), reverse=True)
rabit = RABIT(M+1)

Lmin = M
Rmax = 0
for i in range(1, M+1):
    while Q and Q[-1][2] < i:
        l, r, _ = Q.pop()
        rabit.add_range(l, r, 1)
        Lmin = min(Lmin, l)
        Rmax = max(Rmax, r)
    ans = len(Q)
    for j in range(-(-Lmin//i) * i, Rmax+1, i):
        ans += rabit.get_range(j, j)
    print(ans)
### BUGGY CODE ###

q = int(input())
l = []
b = 0
count = 0
for i in range(q):
    a = list(map(int,input().split()))
    if a[0] == 1:
        l.append(a[1])
        count += 1
        b += a[2]
    else:
        l.sort()
        x = l[(count-1)//2]
        
        ans = 0
        for i in l:
            ans += abs(x-i)
        print(x,ans+b)
    

### FIXED CODE ###

import heapq

q = int(input())
l = []
r = []
ans = 0

for i in range(q):
    a = list(map(int,input().split()))
    if a[0] == 1:
        ans += a[2]
        if l == []:
            heapq.heappush(r,a[1])
            heapq.heappush(l,-a[1])
        else: 
            ll = -heapq.heappop(l)
            rr = heapq.heappop(r)
            if ll <= a[1] <= rr:
                heapq.heappush(r,rr)
                heapq.heappush(l,-ll) 
                heapq.heappush(r,a[1])
                heapq.heappush(l,-a[1]) 

            elif ll > a[1]:
                ans += ll-a[1]
                heapq.heappush(r,rr)
                heapq.heappush(r,ll) 
                heapq.heappush(l,-a[1])
                heapq.heappush(l,-a[1]) 
            else:
                ans += a[1] -rr
                heapq.heappush(l,-rr)
                heapq.heappush(l,-ll) 
                heapq.heappush(r,a[1])
                heapq.heappush(r,a[1]) 
        
    else:
        a = heapq.heappop(l)
        print(-a,ans)
        heapq.heappush(l,a)
### BUGGY CODE ###

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

a = list(map(int, input().split()))
heapq.heapify(a)

for i in range(m):
  b,c = map(int, input().split())
  for j in range(b):
    if a[0] < c:
      heapq.heappop(a)
      heapq.heappush(a, c)
    else:
      break

print(sum(a))

### FIXED CODE ###

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

a = list(map(int, input().split()))
heapq.heapify(a)

min_num = a[0]

tmp_array = []

for i in range(m):
  b,c = map(int, input().split())
  tmp_array.append([b,c])

sort_array = sorted(tmp_array, key=lambda x: -x[1])

for i in range(m):
  b = sort_array[i][0]
  c = sort_array[i][1]
  if min_num >= c:
    continue
  else:
    for j in range(b):
      if a[0] < c:
        heapq.heappop(a)
        heapq.heappush(a, c)
      else:
        break
    min_num = a[0]

#for i in range(m):
#  b,c = map(int, input().split())
#  if min_num >= c:
#    continue
#  else:
#    for j in range(b):
#      if a[0] < c:
#        heapq.heappop(a)
#        heapq.heappush(a, c)
#      else:
#        break
#    min_num = a[0]

print(sum(a))
### BUGGY CODE ###

import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

S = readline().rstrip()
S = S[::-1]
dp = [0]*13
dp[0] = 1

for i,s in enumerate(S):
    dpnew = [0]*13
    if s != '?':
        k = int(s)
        for j in range(13):
            dpnew[(k*(10**i)+j)%13] = (dpnew[(k*(10**i)+j)%13]+dp[j])%mod
    else:
        for k in range(10):
            for j in range(13):
                dpnew[(k*(10**i)+j)%13] = (dpnew[(k*(10**i)+j)%13]+dp[j])%mod
    dp = dpnew

print(dp[5])


### FIXED CODE ###

import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

S = readline().rstrip()
S = S[::-1]
dp = [0]*13
dp[0] = 1

for i,s in enumerate(S):
    dpnew = [0]*13
    pow10 = pow(10,i,13)
    if s != '?':
        k = int(s)
        for j in range(13):
            dpnew[(k*pow10+j)%13] = (dpnew[(k*pow10+j)%13]+dp[j])%mod
    else:
        for k in range(10):
            for j in range(13):
                dpnew[(k*pow10+j)%13] = (dpnew[(k*pow10+j)%13]+dp[j])%mod
    dp = dpnew

print(dp[5])
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
for i in range(n):
    b=sorted(a[:i]+a[i+1:])
    print(b[n//2-1])

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
c=b[n//2]
d=b[n//2-1]
for i in range(n):
    print(c if a[i]<=d else d)