CodeEff/ECCO huggingface dataset:
# Original solution
import sys
def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    N,K = list(map(int, input().split()))
    S = sys.stdin.readline()
  else:
    # For Test
    # N = 5
    # K = 1
    # S = "00010"
    N = 14
    K = 2
    S = "11101010110011"
    # N = 1
    # K = 1
    # S = "1"
    
  SC = []
  i = 0
  if S[0] == "0":SC.append(0)
  while i < N :
    if S[i] == "0":
      j = S.find("1",i)
    else:
      j = S.find("0",i)
    if j == -1: j = N 
    cnt = j - i
    i = j
    SC.append(cnt)
    
  if 'get_ipython' in globals(): print(SC)
    
  i = 0
  lenSC = len(SC) - 1
  ans = 0
  for i in range(0,lenSC+1,2):
  #while i <= lenSC:
    cnt = 0
    k = i + K * 2
    if k > lenSC:
      k = lenSC
    k += 1
    cnt = sum(SC[i:k])
    if ans < cnt:
      ans = cnt
  # i += 2

  print(ans)

main()

# Optimized solution
import sys
def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    N,K = list(map(int, input().split()))
    S = sys.stdin.readline()
  else:
    # For Test
    # N = 5
    # K = 1
    # S = "00010"
    # N = 14
    # K = 2
    # S = "11101010110011"
    # N = 1
    # K = 1
    # S = "1"
    N = 5
    K = 1
    S = "11111"
    
  SC = []
  i = 0
  if S[0] == "0":SC.append(0)
  while i < N :
    if S[i] == "0":
      j = S.find("1",i)
    else:
      j = S.find("0",i)
    if j == -1: j = N 
    cnt = j - i
    i = j
    SC.append(cnt)
    
  if 'get_ipython' in globals(): print(SC)
    
  SH = []
  cnt = 0
  for i in range(len(SC)):
    cnt += SC[i]
    SH.append(cnt)
  
  if 'get_ipython' in globals(): print(SH)
  
  lenSC = len(SC) - 1
  ans = 0
  for i in range(0,lenSC+1,2):
    k = i + K * 2
    if k > lenSC:
      k = lenSC
    if i != 0:
      cnt = SH[k] - SH[i-1]
    elif k == i:
      cnt = SH[k]
    else:
      cnt = SH[k] - SH[i]
    if ans < cnt: ans = cnt

  print(ans)

main()
# Original solution
n, k = list(map(int, input().split()))
k += 1
s = "01" + input().rstrip()
n += 2
ans = 0
i = 0
left = 2
right = 1
while i < n:
    if k > 0:
        pos = s.find('01', i)
        if pos == -1:
            i = n
            right = n - 1
        else:
            pos = s.find('10', pos + 1)
            if pos == -1:
                i = n
                right = n - 1
            else:
                right = pos
                i = pos + 1
        k = k - 1
        ans = max(ans, right - left + 1)
    else:
        pos = s.find('01', left)
        left = pos + 1
        k = k + 1

print(ans)


# Optimized solution
n, k = list(map(int, input().split()))
s = input().rstrip()
ans = 1
i = 0
left = 0
right = 1
while i < n:
    if k > 0:
        pos = s.find('01', i)
        if pos == -1:
            i = n
            right = n - 1
        else:
            pos = s.find('10', pos + 1)
            if pos == -1:
                i = n
                right = n - 1
            else:
                right = pos
                i = pos + 1
        k = k - 1
        ans = max(ans, right - left + 1)
    else:
        pos = s.find('01', left)
        left = pos + 1
        k = k + 1

print(ans)
# Original solution

from itertools import accumulate


def resolve():
    N, K = map(int, input().split())
    S = input()

    # even:1
    # odd:0
    # 1-0-1-0-1 の配列にする. 両端は1にする
    L = []
    pre = "1"
    cnt = 0
    for i in range(N):
        if pre == S[i]:
            cnt += 1
        else:
            L.append(cnt)
            cnt = 1
        pre = S[i]
    L.append(cnt)
    # 最後が0で終わっていたら、仮の1を付け足す。(値が0なので影響ない)
    if pre == "0":
        L.append(0)

    # 1-0-1-0-1の配列を作成し、K＝2だとする。
    # 0を2個含めた個数は, 1＝3、0＝2の長さが作成できる
    length = 2 * K + 1

    # 0をすべて変換できる
    if len(L) <= length:
        return print(N)

    acc = [0] + list(accumulate(L))
    ans = 0
    for i in range(0, len(L) - length + 1, 2):
        ans = max(ans, acc[i + length] - acc[i])

    print(ans)


if __name__ == "__main__":
    resolve()


# Optimized solution

from itertools import accumulate


def resolve():
    N, K = map(int, input().split())
    S = input()

    # even:1
    # odd:0
    # 1-0-1-0-1 の配列にする. 両端は1にする
    L = []
    pre = "1"
    cnt = 0
    for i in range(N):
        if pre == S[i]:
            cnt += 1
        else:
            L.append(cnt)
            cnt = 1
        pre = S[i]
    L.append(cnt)
    # 最後が0で終わっていたら、仮の1を付け足す。(値が0なので影響ない)
    if pre == "0":
        L.append(0)

    # 1-0-1-0-1の配列を作成し、K＝2だとする。
    # 0を2個含めた個数は, 1＝3、0＝2の長さが作成できる
    length = 2 * K + 1

    # 0をすべて変換できる
    if len(L) <= length:
        return print(N)

    acc = [0] + list(accumulate(L))
    ans = 0
    # 1-0-1-0-1の配列なので間に0を含んだ数え上げ
    # なので偶数とびに1を起点に数え上げ 
    for i in range(0, len(L) - length + 1, 2):
        ans = max(ans, acc[i + length] - acc[i])

    print(ans)


if __name__ == "__main__":
    resolve()
# Original solution

def resolve():
    N, K = map(int, input().split())
    S = input()

    # even:1
    # odd:0
    # 1-0-1-0-1 の配列にする. 両端は1にする
    L = []
    pre = "1"
    cnt = 0
    for i in range(N):
        if pre == S[i]:
            cnt += 1
        else:
            L.append(cnt)
            cnt = 1
        pre = S[i]
    L.append(cnt)
    # 最後が0で終わっていたら、仮の1を付け足す。(値が0なので影響ない)
    if pre == "0":
        L.append(0)

    # 1-0-1-0-1の配列を作成し、K＝2だとする。
    # 0を2個含めた個数は, 1＝3、0＝2の長さが作成できる
    length = 2 * K + 1

    # 0をすべて変換できる
    if len(L) <= length:
        return print(N)

    # 1-0-1-0-1の配列なので間に0を含んだ数え上げ
    # なので偶数とびに1を起点に数え上げ
    left = 0
    right = 0
    tmp = 0
    # しゃくとり
    ans = 0
    for i in range(0, len(L), 2):
        nextL = i
        nextR = min(i + length, len(L))

        while nextL > left:
            tmp -= L[left]
            left += 1
        while nextR > right:
            tmp += L[right]
            right += 1

        ans = max(ans, tmp)
        
    print(ans)


if __name__ == "__main__":
    resolve()


# Optimized solution

from itertools import accumulate
def resolve():
    N, K = map(int, input().split())
    S = input()

    # even:1
    # odd:0
    # 1-0-1-0-1 の配列にする. 両端は1にする
    L = []
    pre = "1"
    cnt = 0
    for i in range(N):
        if pre == S[i]:
            cnt += 1
        else:
            L.append(cnt)
            cnt = 1
        pre = S[i]
    L.append(cnt)
    # 最後が0で終わっていたら、仮の1を付け足す。(値が0なので影響ない)
    if pre == "0":
        L.append(0)

    # 1-0-1-0-1の配列を作成し、K＝2だとする。
    # 0を2個含めた個数は, 1＝3、0＝2の長さが作成できる
    length = 2 * K + 1

    # 0をすべて変換できる
    if len(L) <= length:
        return print(N)

    # 1-0-1-0-1の配列なので間に0を含んだ数え上げ
    # なので偶数とびに1を起点に数え上げ
    # 累積
    acc = [0] + list(accumulate(L))
    ans = 0
    for i in range(0, len(L), 2):
        left = i
        right = min(i + length, len(L))
        tmp = acc[right] - acc[left]

        ans = max(ans, tmp)

    print(ans)


if __name__ == "__main__":
    resolve()
# Original solution
#--初期の並びを圧縮表示,逆立ち、正立を目印--#
import sys,math,collections,itertools
input = sys.stdin.readline

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

stand = []
s_or_r = []

s_bf = '.'
cnt = 0
for i in range(N):
    if s_bf != S[i] and i != 0:
        stand.append(cnt)
        s_or_r.append(s_bf)
        cnt = 1
        s_bf=S[i]
    else:
        cnt += 1
        s_bf =S[i]
stand.append(cnt)
s_or_r.append(s_bf)


#--正立kまで許容して足す。maxが答え
if s_or_r.count('0')<=K:
    print((len(S)))
    exit()

ans = 0
for start in range(len(stand)):
    rev = 0
    tmp = 0
    i=0
    flag = 0
    while rev+(s_or_r[start+i] == '0')<=K:
        tmp += stand[start+i]
        if s_or_r[start+i] == '0':
            rev += 1
        if start + i == len(stand)-1:
            flag =1
            break
        i += 1
    ans = max(ans,tmp)
    if flag == 1:
        break
print(ans)


# Optimized solution
#--初期の並びを圧縮表示,逆立ち、正立を目印--#
import sys,math,collections,itertools
input = sys.stdin.readline

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

stand = []
s_or_r = []

s_bf = '.'
cnt = 0
for i in range(N):
    if s_bf != S[i] and i != 0:
        stand.append(cnt)
        s_or_r.append(s_bf)
        cnt = 1
        s_bf=S[i]
    else:
        cnt += 1
        s_bf =S[i]
stand.append(cnt)
s_or_r.append(s_bf)


#--正立kまで許容して足す。maxが答え
if s_or_r.count('0')<=K:
    print((len(S)))
    exit()
#--成形==#
if s_or_r[0]=='0':
    s_or_r=['1']+s_or_r
    stand = [0]+stand
if s_or_r[-1]=='0':
    s_or_r.append('1')
    stand.append(0)
#初期条件#
tmp = sum(stand[0:2*K+1])
ans = tmp
for i in range(2,len(stand)-2*K,2):
    tmp += -(stand[i-1]+stand[i-2])+stand[i+2*K-1]+stand[i+2*K]
    ans = max(ans,tmp)
print(ans)
# Original solution
t,s=open(0)
n,k=list(map(int,t.split()))
l=2*k+1
x=[0]*2+[i+1for i in range(n-1)if s[i]!=s[i+1]]+[n]*l
print((max(x[i+l]-x[i]for i in range(s>'1',len(x)-l,2))))

# Optimized solution
t,s=open(0)
n,k=list(map(int,t.split()))
l=2*k+1
x=[0]*2+[i for i in range(1,n)if s[i]!=s[i-1]]+[n]*l
print((max(x[i+l]-x[i]for i in range(s>'1',len(x)-l,2))))
# Original solution
n, k = list(map(int, input().split()))
s = list(map(int, list(input().strip())))

streaks = []
c = s[0]
i = 1
count = 1
while True:
    if i == n:
        streaks.append(count)
        count = 1
        break
    if s[i] == c:
        i += 1
        count += 1
    else:
        c = s[i]
        i += 1
        streaks.append(count)
        count = 1

start = s[0]
res = []
for i in range(len(streaks)):
    x = 0
    stop = min(len(streaks), i + 2 * k + start)
    for j in range(i, stop):
        x += streaks[j]
    res.append(x)
    start = 1 - start
print((max(res)))

# Optimized solution
n, k = list(map(int, input().split()))
s = list(input().strip())

streaks = []
c = s[0]
i = 1
count = 1
while True:
    if i == n:
        streaks.append(count)
        break
    if s[i] == c:
        i += 1
        count += 1
    else:
        streaks.append(count)
        c = s[i]
        i += 1
        count = 1

accs = [0]
for num in streaks:
    accs.append(accs[-1] + num)
if accs[-1] != n:
    accs.append(n)

flag = s[0] == '0'
res = []
for i in range(len(accs)):
    if flag:
        index = i + 2 * k
    else:
        index = i + 2 * k + 1
    index = min(index, len(accs) - 1)
    res.append(accs[index] - accs[i])
    flag = not flag

print((max(res)))
# Original solution
from sys import stdin
from collections import deque

N, K = [int(x) for x in stdin.readline().rstrip().split()]
S = deque([int(x) for x in stdin.readline().rstrip()])

# 0の始点と終点のインデックスリスト
# 始点→終点→始点→終点→...の順
# 従って、必ず偶数個になる（インデックスが偶数の場合は始点で、奇数の場合は終点）
index_list = []
if S[0] == 0:
    index_list.append(0)
    
res = []

for i in range(1, len(S)):
    if S[i] != S[i-1]:
        if S[i] == 0:
            index_list.append(i)
        else:
            index_list.append(i-1)

if S[-1] == 0:
    index_list.append(len(S)-1)

if K < len(index_list) // 2:
    for i in range(len(index_list)//2 - K + 1):
        start = 0
        end = 0
        if i == 0:
            start = 0
        else:
            # 1から始まるところ
            # index_list[2*i-1]は0の終点のインデックス
            start = index_list[2*i-1] + 1
        
        if i == len(index_list)//2 - K:
            end = len(S) - 1
        else:
            # 1で終わるところ
            # index_list[2*(i+K)]は0の始点
            end = index_list[2*(i+K)] - 1

        res.append(end-start+1)


# 全部反転できる
if K >= len(index_list)//2:
    res.append(len(S))

print((max(res)))


# Optimized solution
from sys import stdin

N, K = [int(x) for x in stdin.readline().rstrip().split()]
# -1は終端
S = [int(x) for x in stdin.readline().rstrip()] + [-1]

# 連続して立っている人のカウント
straight_stand_cnt = 0

if S[0] == 0:
    straight_stand_cnt = 1

l = 0
r = 0
ans = -999

while r < N:
    # for DEBUG
    #print(l, r)
    if straight_stand_cnt <= K:
        if S[r] == 1 and S[r+1] == 0:
            straight_stand_cnt += 1

        ans = max(ans, r-l+1)
        r += 1
    else:
        if S[l] == 0 and S[l+1] == 1:
            straight_stand_cnt -= 1
        l += 1      


print(ans)
# Original solution
#!/usr/bin/env python3
from collections import defaultdict
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

s = input().rstrip()
ans = []
for ch in s:
    if ch == "0":
        ans.append("0")
    elif ch == "1":
        ans.append("1")
    else:
        if len(ans) > 0:
            ans.pop()
print(("".join([item for item in ans])))

# Optimized solution
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

s = input().rstrip()
ans = [] 
for ch in s:
    if ch in "01":
        ans.append(ch)
    if ch == "B" and ans:
        ans.pop()
print(("".join([item for item in ans])))
# Original solution
s = str(input())

ans = []
for i in s:
  if i == '0':
    ans.append('0')
  elif i == '1':
    ans.append('1')
  elif i == 'B':
    if ans == []:
      continue
    else:
      ans.pop()
print(*ans, sep='')


# Optimized solution
s=input()
data=[]
for i in range(len(s)):
  if s[i]=='0':
    data.append('0')
  elif s[i]=='1':
    data.append('1')
  else:
    if len(data)==0:
      continue
    else:
      data.pop()
print(*data,sep='')
# Original solution
s = input()
l = list(s)
r = []
for i in l:
  if i == "0":
    r.append("0")
  elif i =="1":
    r.append("1")
  else:
    if r == []:
      continue
    else:
      del r[-1]
print(*r, sep="")


# Optimized solution
s = input()
r = []
for i in s:
  if i == "B":
    if r:
      del r[-1]
  else:
    r.append(i)
print(*r, sep="")
# Original solution
def gcd(x,y):
    while y>0:
        x,y = y,x%y
    return x
N,M = list(map(int,input().split()))
S = input().strip()
T = input().strip()
a = gcd(N,M)
L = (N//a)*(M//a)*a
ks = L//N
kt = L//M
flag = 0
if S[0]!=T[0]:
    flag = 1
else:
    b = gcd(ks,kt)
    kl = (ks//b)*(kt//b)*b
    for i in range(min(N,M)):
        if (kl//ks)*i<N and (kl//kt)*i<M and S[(kl//ks)*i]!=T[(kl//kt)*i]:
            flag = 1
            break
if flag==1:
    print((-1))
else:
    print(L)

# Optimized solution
def gcd(x,y):
    while y>0:
        x,y = y,x%y
    return x
N,M = list(map(int,input().split()))
S = input().strip()
T = input().strip()
a = gcd(N,M)
K = (N//a)*M
t = (N//a)*(M//a)
flag = 0
k = 0
while (k*t)//(K//N)<N and (k*t)//(K//M)<M:
    if S[(k*t)//(K//N)]!=T[(k*t)//(K//M)]:
        flag = 1
        break
    k += 1
if flag==0:
    print(K)
else:
    print((-1))
# Original solution
s = str(eval(input()))
k = int(eval(input()))

t = 0
  
for i in range(len(s)):
  temp = s[i]
  if temp == '1':
    t += 1
  else:
    break

if t == 0:
  print((s[0]))
else:
  if k <= t:
    print('1')
  else:
    print(temp)
    
 

# Optimized solution
s = str(eval(input()))
k = int(eval(input()))

cnt = 0
for i in range(len(s)):
    if s[i] == '1':
        cnt += 1
    else:
        c = s[i]
        break

if cnt:
    if cnt >= k:
        print('1')
    else:
        print(c)
else:
    print(c)
# Original solution
print((input()[:int(eval(input()))].replace('1','')[:1]or'1'))

# Optimized solution
print((input()[:int(eval(input()))].replace('1','')[:1]or 1))
# Original solution
#!/usr/bin/env python3
import sys
import itertools
import collections
import functools
import math
from queue import Queue
# import numpy as np
INF = float("inf")


def solve(S: int, K: int):
    n = -1
    nc = 1
    for i, c in enumerate(str(S)):
        if c != "1":
            n = i+1
            nc = c
            break
    # print(n, nc, K)
    if n == -1:
        print((1))
        return

    if K < n:
        print((1))
    else:
        print(nc)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(S, K)


if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(S: str, K: int):

    for i in range(K):
        if S[i] != "1":
            c = S[i]
            break
    else:
        print((1))
        return
    print(c)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = str(next(tokens))  # type: str
    K = int(next(tokens))  # type: int
    solve(S, K)


if __name__ == '__main__':
    main()
# Original solution
# ARC095C - Many Medians (ABC094C)
def main():
    n = int(eval(input()))
    x = list(map(int, input().rstrip().split()))
    l, h = sorted(x)[n // 2 - 1 : n // 2 + 1]
    for i in x:
        if i <= l:
            print(h)
        else:
            print(l)


if __name__ == "__main__":
    main()

# Optimized solution
# ARC095C - Many Medians (ABC094C)
def main():
    n = int(eval(input()))
    x = tuple(map(int, input().rstrip().split()))
    l, h = sorted(x)[n // 2 - 1 : n // 2 + 1]
    for i in x:
        if i <= l:
            print(h)
        else:
            print(l)


if __name__ == "__main__":
    main()
# Original solution


def binsearch(x,value):
    left=0; right=len(x)-1
    if x[right] == value:
        return right
    elif x[left] == value:
        return left
    while True:
        m = (right+left)//2
        if x[m] == value:
            return m
        elif x[m] > value:
            right = m
        else:
            left = m


def main():
    n = int(eval(input()))
    x = [int(i) for i in input().split()]
    newx = sorted(x)
    for i in x:
        index = binsearch(newx,i)
        del newx[index]
        print((newx[(n-1)//2]))
        newx.insert(index,i)


if __name__ == '__main__':
    main()


# Optimized solution
def main():
    n = int(eval(input()))
    x = [int(i) for i in input().split()]
    newx = sorted(x)
    ans = dict()
    for i,xx in enumerate(newx):
        if i+1 <= n//2:
            ans[xx] = newx[n//2]
        else:
            ans[xx] = newx[n//2-1]
    for xx in x:
        print((ans[xx]))

if __name__ == '__main__':
    main()
# Original solution
import statistics
N=int(eval(input()))
X=list(map(int, input().split()))
for i in range(0,N):
    print((statistics.median(X[:i]+X[i+1:])))

# Optimized solution
N=int(eval(input()))
X=list(map(int, input().split()))
sortX=sorted(X)
small=sortX[int(N/2)-1]
big=sortX[int(N/2)]
if small==big:
    for i in range(0,N):
        print(small)
    exit()

for i in range(0,N):
    if X[i]>small:
        print(small)
    else:
        print(big)
# Original solution

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

N = int(eval(input()))
X = list(map(int, input().split()))

for i in range(N):
    x = X[0:i]+X[i+1:]
    x.sort(reverse=True)

#    print(x)
    print(( x[((len(x)+1) // 2)-1] ))


# Optimized solution

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

N = int(eval(input()))
X = list(map(int, input().split()))

x = X[:]
x.sort()
m1 = x[N//2 - 1]
m2 = x[N//2]

for a in X:
    if a <= m1:
        print(m2)
    else:
        print(m1)
# Original solution
from statistics import mean, median,variance,stdev

n = int(eval(input()))
x = list(map(int, input().split()))

for i in range(n):
    print((median(x[:i]+x[i+1:])))


# Optimized solution

n = int(eval(input()))
x = list(map(int, input().split()))
x_sort = x.copy()
x_sort.sort()
row = x_sort[n//2 - 1]
high = x_sort[n//2]

for i in range(n):
    if x[i] <= row:
        print(high)
    else:
        print(row)
# Original solution
def median(lista):
  lista = sorted(lista)
  return lista[int((len(lista)+ 1)/ 2)- 1]

N = int(eval(input()))
lista = list(map(int, input().split()))

for i in range(N):
  if(i == 0):
    newlista = lista[1:]
  elif(i == N- 1):
    newlista = lista[:N- 1]
  else:
  	newlista = lista[:i]+ lista[i+ 1:]
   
  print((median(newlista)))

# Optimized solution
N = int(eval(input()))
lista = list(map(int, input().split()))
newlista = sorted(lista)

lowermedian = newlista[int(len(lista)/ 2- 1)]
highermedian = newlista[int(len(lista)/2)]

for i in range(N):
  if(lista[i] <= lowermedian):
    print(highermedian)
  else:
    print(lowermedian)
# Original solution
n=int(eval(input()));*a,=list(map(int,input().split()))
for i in range(n):print((sorted(a[:i]+a[-~i:])[~-n//2]))

# Optimized solution
n=int(eval(input()));*a,=list(map(int,input().split()));b=sorted(a);l,m=b[n//2-1],b[n//2]
for x in a:print(([l,m][x<m]))
# Original solution
n = int(eval(input()))
x = list(map(int, input().split()))
xs = sorted(x)
a = xs[n // 2 - 1]
b = xs[n // 2]
for i in range(n):
    if xs.index(x[i]) < n // 2:
        print(b)
    else:
        print(a)

# Optimized solution
n = int(eval(input()))
x = list(map(int, input().split()))
xs = sorted(x)
a = xs[n // 2 - 1]
b = xs[n // 2]
for i in x:
    if i <= a:
        print(b)
    else:
        print(a)
# Original solution
N = int(eval(input()))

X = input().split()


for i in range(N):
    x2 = [int(x) for x in X]
    del x2[i]
    x2.sort()
    
    print(("%d"%x2[int((N/2)-1)]))

# Optimized solution
N = int(eval(input()))

X = input().split()
x1 = [int(x) for x in X]
x2 = [int(x) for x in X]

x2.sort()
ml = x2[int((N/2)-1)]
mr = x2[int(N/2)]

for i in range(N):
    if x1[i] <=  ml:
        print(("%d"%mr))
    else:
        print(("%d"%ml))
# Original solution
# -*- coding: utf-8 -*-
"""
Contents   : AtCoder Regular Contest 095 c問題
Author     : Kitaura Hiromi
LastUpdate : 20180414
Since      : 20180414
"""
import random
import copy
def quickselect(items, item_index):

    def select(lst, l, r, index):

        # base case
        if r == l:
            return lst[l]

        # choose random pivot
        pivot_index = random.randint(l, r)

        # move pivot to beginning of list
        lst[l], lst[pivot_index] = lst[pivot_index], lst[l]

        # partition
        i = l
        for j in range(l+1, r+1):
            if lst[j] < lst[l]:
                i += 1
                lst[i], lst[j] = lst[j], lst[i]

        # move pivot to correct location
        lst[i], lst[l] = lst[l], lst[i]

        # recursively partition one side only
        if index == i:
            return lst[i]
        elif index < i:
            return select(lst, l, i-1, index)
        else:
            return select(lst, i+1, r, index)

    if items is None or len(items) < 1:
        return None

    if item_index < 0 or item_index > len(items) - 1:
        raise IndexError()

    return select(items, 0, len(items) - 1, item_index)

N = int(eval(input()))
X = list(map(int, input().split(" ")))
med1 = quickselect(copy.deepcopy(X), N//2-1)
med2 = quickselect(copy.deepcopy(X), N//2)
for i in range(N):
    if X[i] <= med1:
        print(med2)
    else:
        print(med1)

# Optimized solution
# -*- coding: utf-8 -*-
"""
Contents   : AtCoder Regular Contest 095 c問題
Author     : Kitaura Hiromi
LastUpdate : 20180414
Since      : 20180414
"""
import random
import copy

N = int(eval(input()))
X = list(map(int, input().split(" ")))
sorted_X = sorted(X)
med1 = sorted_X[N//2-1]
med2 = sorted_X[N//2]
for i in range(N):
    if X[i] <= med1:
        print(med2)
    else:
        print(med1)
# Original solution
# coding: utf-8
import sys
import copy


# 標準入力
n = int(sys.stdin.readline().strip())
xArray = list(map(int, sys.stdin.readline().strip().split(" ")))

result = []

# 演算処理
for i in range(n):
    tmp = copy.copy(xArray)
    del tmp[i]
    tmp = sorted(tmp)
    result.append(tmp[int((n/2) - 1)]) # (l + 1)/2 の要素を参照


# 標準出力
print(('\n'.join(map(str, result))))



# Optimized solution
# coding: utf-8
import sys
import copy


# 標準入力
n = int(sys.stdin.readline().strip())
xArray = list(map(int, sys.stdin.readline().strip().split(" ")))

result = []

sortedArray = sorted(xArray)


# 中央値を算出する
for i in range(n):
    middle = sortedArray[int((n / 2) - 1)]
    if (middle >= xArray[i]):
        result.append(sortedArray[int(n / 2)])
    else:
        result.append(middle)


# 標準出力
print(('\n'.join(map(str, result))))