Problem:
 Score : 300 points    Problem Statement When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2}) -th largest value among a_1, a_2, ..., a_l .  You are given N numbers X_1, X_2, ..., X_N , where N is an even number.
For each i = 1, 2, ..., N , let the median of X_1, X_2, ..., X_N excluding X_i , that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i .  Find B_i for each i = 1, 2, ..., N .      Constraints  2 \leq N \leq 200000  N is even.  1 \leq X_i \leq 10^9  All values in input are integers.         Input Input is given from Standard Input in the following format:  N  X_1  X_2 ... X_N       Output Print N lines.
The i -th line should contain B_i .        Sample Input 1 4
2 4 4 3      Sample Output 1 4
3
3
4   Since the median of X_2, X_3, X_4 is 4 , B_1 = 4 .  Since the median of X_1, X_3, X_4 is 3 , B_2 = 3 .  Since the median of X_1, X_2, X_4 is 3 , B_3 = 3 .  Since the median of X_1, X_2, X_3 is 4 , B_4 = 4 .        Sample Input 2 2
1 2      Sample Output 2 2
1       Sample Input 3 6
5 5 4 4 3 3      Sample Output 3 4
4
4
4
4
4

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
XY = [[i+1,X[i],0] for i in range(N)]
XY.sort(key=lambda x:x[1],reverse=True)
m2 = XY[N//2][1]
m1 = XY[N//2-1][1]
for i in range(N):
  if (i+1) <= N//2:
    XY[i][2] = m2
  else:
    XY[i][2] = m1
XY.sort(key=lambda x:x[0])
for i in range(N):
  print(XY[i][2])

Solution (Python):
n=int(input())
index=int(n/2)-1
x=list(map(int,input().split()))
y=[]
for i in range(n):
  y.append(x[i])
y.sort()
med=y[index]
for i in range(n):
    if x[i]>med:
        print(med)
    else:
        print(y[index+1])

Solution (Python):

def main():
    n = int(input())
    x = list(map(int, input().split()))
    
    l, h = sorted(x)[n // 2 - 1 : n // 2 + 1]
    ans = [h if e <= l else l for e in x] 
    print("\n".join(map(str, ans)))
if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())

X = [int(el) for el in input().split(' ')]

Y = sorted(X)
p = Y[n // 2 - 1]
q = Y[n // 2 ]

for i in range(0, n):
	if X[i] <= p:
		print(q)
	else:
		print(p)

Solution (Python):
n = int(input())
X = list(map(int,input().split()))
X_sorted = sorted(X)
L = X_sorted[n // 2 - 1]
R = X_sorted[n // 2]
for x in X:
  print(L if x >= R else R)

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
sx=sorted(x)
a=sx[n//2]
b=sx[n//2-1]
for i in range(n):
  if x[i]>=a:
    print(b)
  else:
    print(a)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
xs = list(sorted(x))
m1 = xs[n//2 - 1]
m2 = xs[n//2]
for xi in x:
  if xi <= m1:
    print(m2)
  else:
    print(m1)

Solution (Python):
n = int(input())
X = list(map(int, input().split()))
D = []
for i, x in enumerate(X):
    D.append([x, i])
D.sort()
l = len(X)

left = D[l//2-1][0]
right = D[l//2][0]

ans = [0] * n
for i in range(n):
    idx = D[i][1]
    if i <= l//2-1:
        ans[idx] = right
    else:
        ans[idx] = left

for a in ans:
    print(a)

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
X2 = sorted(X)
mid1 = X2[N//2-1]
mid2 = X2[N//2]
for i in X:
    if i <= mid1:
        print(mid2)
    else:
        print(mid1)

Solution (Python):

from bisect import bisect_left
import sys
readline = sys.stdin.readline
N = int(readline())
X = [int(x) for x in readline().split()]




sX = sorted(X)
m = (N - 1) // 2
for i in range(N):
    p = bisect_left(sX, X[i])
    if p <= m:
        print(sX[m + 1])
    else:
        print(sX[m])

Solution (Python):
import sys
input = sys.stdin.readline
import numpy as np
N = int(input())
X = np.array([int(x) for x in input().split()])
Y = np.sort(X)
right = N // 2
left = right - 1
right, left = Y[right], Y[left]
for i in range(N):
    if X[i] <= left:
        print(right)
    else:
        print(left)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
y = sorted(x)
for i in range(n):
    print(y[n // 2] if x[i] <= y[n // 2 - 1] else y[n // 2 - 1])

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
y = x[:]
y.sort()
for i in range(n):
    print(y[n // 2] if x[i] <= y[n // 2 - 1] else y[n // 2 - 1])

Solution (Python):
n=int(input())
x =list(map(int,input().split()))
xx=sorted(x)

l=len(x)
c1=xx[l//2-1]
c2=xx[l//2]

for i in range(n):
    if x[i] > c1:
        print(c1)
    else:
        print(c2)

Solution (Python):

import sys
input = sys.stdin.readline

n = int(input())
x = list(map(int,input().split()))
x_vi = [(v,i) for i,v in enumerate(x)]
x_vi.sort()
medl = x_vi[n//2-1][0]
medr = x_vi[n//2][0]
ret_median = [0 for _ in range(n)]
for sort_idx,vi in enumerate(x_vi):
    if sort_idx < n//2:
        ret_median[vi[1]]=medr
    else:
        ret_median[vi[1]]=medl
for i in ret_median:
    print(i)

Solution (Python):
N = int(input())
li = list(map(int,input().split()))
lia = li[:]
lia.sort()
index1 = int(N/2)
index2 = int((N-2)/2)
ave1 = lia[index2]
ave2 = lia[index1]
for i in range(N) :
    if li[i] <= ave1 :
        print(ave2)
    else :
        print(ave1)

Solution (Python):
N = int(input())
li = list(map(int,input().split()))
lia = li[:]
lia.sort()
index1 = int(N/2)
index2 = int((N-2)/2)
ave1 = lia[index2]
ave2 = lia[index1]
for i in range(N) :
    if li[i] <= ave1 :
        print(ave2)
    else :
        print(ave1)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
sortedx = sorted(x)
mid = n // 2 - 1

for i in x:
    if i <= sortedx[mid]:
        print(sortedx[mid + 1])
    else:
        print(sortedx[mid])

Solution (Python):

n=int(input())
B=list(map(int,input().split()))
C=B.copy()
B=sorted(B)
median1=B[n//2]
median2=B[n//2-1]
if median1==median2:
    for _ in range(n):
        print(median1)
elif median1>median2:
    for i in range(n):
        if C[i]>=median1:
            print(median2)
        else:
            print(median1)

Solution (Python):
import numpy as np

N=int(input())
X=list(map(int, input().split()))
Xs=np.array([[X[i], i] for i in range(N)])
Xs=Xs[np.argsort(Xs[:, 0]), :]
p=Xs[N//2, 0]
pi=Xs[N//2, 1]
q=Xs[N//2-1, 0]
for i in range(N):
  if X[i]<p:
    print(p)
  elif X[i]>p:
    print(q)
  else:
    if i<pi:
      print(p)
    else:
      print(q)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))

X2 = sorted(X)

m_l = X2[N//2-1]
m_r = X2[N//2]

for x in X:
    if x <= m_l:
        print(m_r)
    else:
        print(m_l)

Solution (Python):
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

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

N=one_int()
X=many_int()

sort_X=sorted(X)

med_min1 = sort_X[(len(sort_X)//2)-1]
med_plus1 = sort_X[(len(sort_X)//2)]


for i in X:
    if i >= med_plus1:
        print(med_min1)
    else:
        print(med_plus1)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
ans = sorted(x)

mid = len(x)//2-1
for i in range(n):
  if(ans[mid] < x[i]):
    print(ans[mid])
  else:
    print(ans[mid+1])

Solution (Python):
n=int(input())
x=[int(x) for x in input().split()]
y=sorted(x)

for i in range(n):
  print(y[(n+1)//2] if y[(n+1)//2]>x[i] else y[(n-1)//2])

Solution (Python):

N = int(input())
X = list(map(int, input().split()))
sorted_X = sorted(X)
one = sorted_X[N//2]
two = sorted_X[N//2-1]
for i in range(N):
    if X[i] < one:
        print(one)
    else:
        print(two)

Solution (Python):
n=int(input())
x=[int(i) for i in input().split()]
y=sorted(x)
l=y[n//2-1]
m=y[n//2]
for i in range(n):
    if x[i]<=l:
        print(m)
    else:
        print(l)

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

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
sx = sorted(X,reverse=True)
med1 = sx[int(N/2)-1]
med2 = sx[int(N/2)]
ans = []
for x in X:
    if x >= med1:
        ans.append((med2))
    else:
        ans.append((med1))
print(*ans)

Solution (Python):
import copy

import numpy as np


def main():
    N = int(input())
    X = np.array(list(map(int, input().split())))
    m = np.median(X)

    XX = copy.deepcopy(X)
    mm = np.argmin(X)
    XX = np.delete(XX, mm)
    m0 = int(np.median(XX))

    XX = copy.deepcopy(X)
    mm = np.argmax(X)
    XX = np.delete(XX, mm)
    m1 = int(np.median(XX))

    for x in X:
        if x <= m:
            print(m0)
        else:
            print(m1)


main()

Solution (Python):
N = int(input())
X = [int(i) for i in input().split()]
X_sort = sorted(X)
for i in range(N):
    if X[i] < X_sort[N // 2]:
        print(X_sort[N // 2])
    else:
        print(X_sort[N // 2 - 1])

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
x2 = sorted(x)
median_index = len(x2) // 2
median = x2[median_index]
cnt = x2.count(median_index)
for i in range(n):
    if x[i] >= median:
        print(x2[median_index - 1])
    else:
        print(x2[median_index])

Solution (Python):
import sys
import copy
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()


med = N//2

B = copy.deepcopy(A)
B.sort()
l_m = B[med-1]
h_m = B[med]

for a in A:
	if a > l_m:
		print(l_m)
	else:
		print(h_m)

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

Solution (Python):
N = int(input())
a = [0] + list(map(int, input().split()))
X = sorted(a)

for i in range(1,N+1):
    if a[i] <= X[N//2]:
        print(X[(N // 2 + 1)])
    else:
        print(X[N // 2])

Solution (Python):
import statistics
N = int(input())
X = list(map(int,input().split()))
y = statistics.median(X)
yl = statistics.median_low(X)
yh = statistics.median_high(X)
for x in X:
  if x>y:
    print(yl)
  if x<=y:
    print(yh)

Solution (Python):
N=int(input())
X = [int(x) for x in input().split()]
Y=sorted(X)
a=Y[N//2-1]
b=Y[N//2]
for i in range(N):
  if X[i]<=a:
    print(b)
  else:
    print(a)

Solution (Python):
n=int(input())
X=list(map(int, input().split()))
X1=sorted(X)
mid_1=X1[int(n/2)-1]
mid_2=X1[int(n/2)]
for x in X:
    if x <= mid_1:
        print(mid_2)
    else:
        print(mid_1)

Solution (Python):
n = int(input())
X = list(map(int, input().split()))
X_sort = sorted(X)

mid_1 = X_sort[int(n/2) -1]
mid_2 = X_sort[int(n/2)]

for x in X:
    if x <= mid_1:
        print(mid_2)
    else:
        print(mid_1)

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
X_work = sorted(X)
before = X_work[N // 2]
after = X_work[N // 2 - 1]
for x in X:
    if x <= after:
        print(before)
    else:
        print(after)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))

sx = sorted(X)
mid1 = sx[N//2-1]
mid2 = sx[N//2]

if mid1 == mid2:
    print(*[mid1]*N, sep='\n')
else:
    for i in range(N):
        if X[i] <= mid1:
            print(mid2)
        else:
            print(mid1)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
X = list(map(int, input().split()))
X_sorted = sorted(X)
L = X_sorted[N//2-1]
R = X_sorted[N//2]


for x in X:
    print(L if x >= R else R)

Solution (Python):
'''
　 ∧_,,∧    究極奥義「WAがACになーれ！！」
　（`・ω・)つ━☆・*。
　⊂　　 ノ 　　　・゜+.
　 し’´Ｊ　　*・ 
'''
import sys
input = sys.stdin.readline
n=int(input())
x=list(map(int,input().split()))
y=sorted(x)
l=y[n//2 -1]
r=y[n//2]
for i in range(n):
    if x[i]<=l:
        print(r)
    else:
        print(l)

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
Y = sorted(X)
midL = Y[N//2-1]
midH = Y[N//2]
for i in range(N):
    if X[i]<midH:
        print(midH)
    else: print(midL)

Solution (Python):
import copy
n=int(input())
a=list(map(int,input().split()))
b=copy.deepcopy(a)
b.sort()
for i in range(n):
    if a[i]<=b[n//2-1]:
        print(b[n//2])
    else:
        print(b[n//2-1])

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
X_sort = sorted(X)

ans1 = X_sort[N // 2 - 1]
ans2 = X_sort[N // 2]

for i in range(N):
  if X[i] <= ans1:
    print(ans2)
  else:
    print(ans1)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
p,q=b[n//2-1],b[n//2]
for i in a:print(p if i>=q else q)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
p,q=b[n//2-1:n//2+1]
for i in a:print(p if i>=q else q)

Solution (Python):
N=int(input())
Xs=list(map(int, input().split()))
nXs=sorted(Xs)

medL=nXs[len(nXs)//2-1]
medR=nXs[len(nXs)//2]

if medL == medR:
    for i in range(N):
        print(medL)
else:
    for i in Xs:
        if i<=medL:
            print(medR)
        else:
            print(medL)

Solution (Python):
def examC():
    N = I()
    x = LI(); num = [i for i in range(N)]
    X = list(zip(x,num)); X.sort()
    ans = [0]*N
    mid0 = X[(N)//2-1][0]; mid1 = X[(N)//2][0]
    for i in range(N):
        if X[i][0]<mid1:
            ans[X[i][1]] = mid1
        else:
            ans[X[i][1]] = mid0
    for v in ans:
        print(v)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

Solution (Python):
def examC():
    N = I()
    x = LI(); num = [i for i in range(N)]
    X = list(zip(x,num)); X.sort()
    ans = [0]*N
    mid0 = X[(N)//2-1][0]; mid1 = X[(N)//2][0]
    for i in range(N):
        if X[i][0]<mid1:
            ans[X[i][1]] = mid1
        else:
            ans[X[i][1]] = mid0
    for v in ans:
        print(v)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

Solution (Python):

import sys, math, itertools, heapq, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

n=int(input())
Y=list(map(int,input().split()))
X=sorted(Y)
X0=X[n//2-1]
X1=X[n//2]
for i in  range(n):
    if Y[i]<=X0:
        print(X1)
    else:
        print(X0)

Solution (Python):
import bisect
N = int(input())
lst = list(map(int, input().split()))
lst1 = sorted(lst)
x1 = lst1[N//2-1]
x2 = lst1[N//2]

for i in range(N):
    if bisect.bisect_right(lst1, lst[i]) <= N//2:
        print(x2)
    else:
        print(x1)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
X = LIST()
sorted_X = sorted(X)
kouho1 = sorted_X[N//2-1]
kouho2 = sorted_X[N//2]
for i in range(N):
	if X[i] <= kouho1:
		print(kouho2)
	else:
		print(kouho1)

Solution (Python):
n = int(input())
li = list(map(int,input().split()))
L = sorted(li)

a = L[n//2-1]
b = L[n//2]

for i in range(n):
    if li[i]<=a:
        print(b)
    elif li[i] >=b:
        print(a)

Solution (Python):
n = int(input())
li = list(map(int,input().split()))
L = sorted(li)

a = L[n//2-1]
b = L[n//2]

for i in range(n):
    if li[i]<=a:
        print(b)
    elif li[i] >=b:
        print(a)

Solution (Python):
n = int(input())
xl = list(map(int,input().split()))

sorted_xl = sorted(xl)
front = sorted_xl[n//2 - 1]
back = sorted_xl[n//2]

for x in xl:
    if x <= front:
        print(back)
    else:
        print(front)

Solution (Python):
n = int(input())
X = list(map(int, input().split()))

Y = sorted(X)
b1, b2 = Y[n//2 - 1], Y[n//2]
for x in X:
    print(b2 if x <= b1 else b1)

Solution (Python):
from statistics import median
N = int(input())
X = [int(i) for i in input().split()]
sort_X = sorted(X)
sort_X = sort_X[N//2-1:N//2+1]
for x in X:
    if sort_X[0] >= x:
        print(sort_X[1])
    else:
        print(sort_X[0])

Solution (Python):
n = int(input())
*l, = map(int, input().split())

p, q = sorted(l)[n//2-1 : n//2+1]
for _l in l:
    print(p if _l >= q else q)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
p, q = sorted(A)[N//2-1: N//2+1]
for a in A: print(p if a>=q else q)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

X = []
for i, a in enumerate(A):
    X.append([a, i])

X.sort()


m = N//2
itoj = {}
for j in range(N):
    x, i = X[j]
    itoj[i] = j
for i in range(N):
    j = itoj[i]
    if j < m:
        print(X[m][0])
    else:
        print(X[m-1][0])

Solution (Python):
n=int(input())
X=list(map(int,input().split()))
L=[]
for i in range(n):
    l=[i,X[i]]
    L.append(l)
LS=sorted(L,key=lambda x:x[1])
LSM=[0]*n
for i in range(n):
    if i<n//2:
        LSM[LS[i][0]]=LS[n//2][1]
    else:
        LSM[LS[i][0]]=LS[n//2-1][1]
for i in range(n):
    print(LSM[i])

Solution (Python):
N = int(input())
X = list(map(int, input().split()))

sorted_X = sorted(X)

left_med = sorted_X[N//2 -1]
right_mid = sorted_X[N//2]

for i in range(N):
    if X[i] <= left_med:
        print(right_mid)
    else:
        print(left_med)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=[0]*n
    for i,x in enumerate(map(int,input().split())):
        A[i]=[x,i]
    A.sort()

    l=A[n//2-1][0]
    h=A[n//2][0]
    for i in range(n//2):
        A[i][0]=h
    for i in range(n//2):
        A[n//2+i][0]=l

    A.sort(lambda x:x[1])
    for i in range(n):
        print(A[i][0])
resolve()

Solution (Python):
from sys import stdin
input = stdin.readline

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

x_sorted=sorted(x)
c = (x_sorted[n//2-1]+x_sorted[n//2])/2

for i in range(n):
    if x[i]>=c:
        print(x_sorted[n//2-1])
    else:
        print(x_sorted[n//2])

Solution (Python):
import bisect
N=int(input())
X=list(map(int,input().split()))

if N==2:
    print(X[-1])
    print(X[0])
else:
    sortedX=sorted(X)
    num=N//2-1
    for x in X:
        if x<=sortedX[num]:print(sortedX[num+1])
        else:print(sortedX[num])

Solution (Python):
from bisect import bisect_left
N = int(input())
X = list(map(int,input().split()))
Y = X.copy()
Y.sort()
for i in range(N):
    k = bisect_left(Y,X[i])
    if k < N//2:
        print(Y[N//2])
    else:
        print(Y[N//2-1])

Solution (Python):
from sys import stdin
import numpy as np
import statistics


n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
lin = sorted(li)
ni = lin[n//2]
iti = lin[n//2-1]

for i in range(n):
    if li[i] <= iti:
        print(ni)
    else:
        print(iti)

Solution (Python):
n = int(input())
list_x = list(map(int, input().split()))
sub_list = sorted(list_x)

a = sub_list[n // 2]
b = sub_list[n // 2 - 1]

for one_x in list_x:
  if one_x <= b:
    print(a)
  else:
    print(b)

Solution (Python):
N=int(input())
x=list(map(int,input().split()))
y=sorted(x)
a=y[N//2-1]
b=y[N//2]
for i in range(N):
  if x[i]<=a:
    print(b)
  else:
    print(a)

Solution (Python):
n=int(input())
moga=list(map(int,input().split()))
hoge=sorted(moga)
for i in range(n):
  if(moga[i]<hoge[n//2]):
    print(hoge[n//2])
  else:
    print(hoge[n//2-1])

Solution (Python):
N = int(input())
X = [int(x) for x in input().split()]
X_ = sorted(X, reverse=True)
mid1 = X_[N // 2 - 1]
mid2 = X_[N // 2]
for x in X:
  if x >= mid1:
    print(mid2)
  else:
    print(mid1)

Solution (Python):
n = int(input())
L = list(map(int, input().split()))
sL = sorted(L)
for i in range(n):
  if L[i] <= sL[n // 2 - 1]:
    print(sL[n//2])
  else:
    print(sL[n//2 - 1])

Solution (Python):
N = int(input())
n = (N//2) - 1
X = list(map(int,input().split()))
import copy
Y = copy.deepcopy(X)
Y.sort()
a = Y[n]
b = Y[n+1]
for i in range(N):
    ans = a
    if X[i] <= a:
        ans = b
    print(ans)

Solution (Python):
N = int(input())
X = list(map(lambda x: int(x), input().split(' ')))

afters = [0 for _ in range(N)]
after_x_dict = {}
for after, (before, x) in enumerate(sorted(list(enumerate(X)), key=lambda x:x[1])):
    afters[before] = after
    after_x_dict[after] = x

threshold = N//2 - 1
for i in range(N):
    if  afters[i] <= threshold:
        print(after_x_dict[threshold+1])
    else:
        print(after_x_dict[threshold])

Solution (Python):


import sys










def main():
    n, *x = (int(i) for i in sys.stdin.read().split())
    s_x = list(sorted(x))
    half = n // 2
    m_s, m_l = s_x[half - 1], s_x[half]
    for i in x:
        print(m_l if i < m_l else m_s)

if __name__ == "__main__":
    
    main()

Solution (Python):


import sys



import bisect






def main():
    n, *x = (int(i) for i in sys.stdin.read().split())
    s_x = list(sorted(x))
    half = n // 2
    m_s, m_l = s_x[half -1], s_x[half]
    for i in x:
        b = bisect.bisect_left(s_x, i)
        print(m_l if b < half else m_s)

if __name__ == "__main__":
    
    main()

Solution (Python):


import sys



import bisect






def main():
    n, *x = (int(i) for i in sys.stdin.read().split())
    s_x = list(sorted(x))
    m_s, m_l = s_x[n // 2 -1], s_x[n // 2]
    for i in x:
        b = bisect.bisect_left(s_x, i)
        print(m_l if b < n // 2 else m_s)

if __name__ == "__main__":
    
    main()

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
nx=x[:]
nx.sort()
med1=nx[n//2-1]
med2=nx[n//2]
for sx in x:
    if sx > med1:
        print(med1)
    else:
        print(med2)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))

x_sorted = sorted(x)
l = x_sorted[n//2]
s = x_sorted[n//2-1]

for i in x:
    print(l if i <= s else s)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))

sorted_x = sorted(x)
l = sorted_x[n//2]
s = sorted_x[n//2-1]

for i in x:
    if i <= s:
        print(l)
    else:
        print(s)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))

x_sorted = sorted(x)
larger_candidate = x_sorted[n//2]
smaller_candidate = x_sorted[n//2-1]

for i in range(len(x)):
    if x[i] <= smaller_candidate:
        print(larger_candidate)
    else:
        print(smaller_candidate)

Solution (Python):
N = int(input())
A = [int(a) for a in input().split()]
B = sorted(A)

for i in range(N):
    if A[i] <= B[N//2-1]:
        print(B[N//2])
    else:
        print(B[N//2-1])

Solution (Python):
n = int(input())
list = list(map(int, input().split()))
list1 = sorted(list)
median_candidate1, median_candidate2 = list1[n//2-1], list1[n//2]
for i in list:
    if i <= median_candidate1:
        print(median_candidate2)
    else:
        print(median_candidate1)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
b = sorted(a)
cl = b[(n-1)//2]
cr = b[n//2]
for i in range(n):
    if a[i] <= cl:
        print(cr)
    elif cr <= a[i]:
        print(cl)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))

Dict={}

for i,Num in enumerate(A):
    Dict[i]=Num

List = sorted(Dict.items(), key=lambda x:x[1])
S=List[(N//2)-1][1]
B=List[(N//2)][1]
for i in range(N):
    if(Dict[i]<=S):
        print(B)
    else:
        print(S)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
Y = sorted(X)
a = Y[N // 2 - 1]
b = Y[N // 2]

for i in X:
    if i <= a:
        print(b)
    elif i >= b:
        print(a)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
X2 = sorted(X)
left = X2[(N//2)-1]
right = X2[N//2]
for i in range(N):
    print(left if X[i] > left else right)

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
y = sorted(x)
a = y[n//2]
b = y[n//2-1]
for i in x:
  if i >= a:
    print(b)
  else:
    print(a)

Solution (Python):
N=int(input())
X=list(map(int,input().split()))

X_sort=sorted(X)

if X_sort[N//2-1]==X_sort[N//2]:
    for n in range(N):
        print(X_sort[N//2])
else:
    if X_sort.count(X_sort[N//2-1])==1:
        for n in range(N):
            if X[n]>X_sort[N//2-1]:
                print(X_sort[N//2-1])
            else:
                print(X_sort[N//2])
    else:
        for n in range(N):
            if X[n]>X_sort[N//2-1]:
                print(X_sort[N//2-1])
            else:
                print(X_sort[N//2])

Solution (Python):
N = int(input())
X = sorted([[x,i] for i, x in enumerate(map(int,input().split()))])
med1,med2 = X[(N-1)//2][0], X[(N-1)//2+1][0]
ans = []
for idx1, x in enumerate(X):
  if idx1 <= (N-1)//2: ans.append([x[1],med2])
  else: ans.append([x[1],med1])
  
[print(med) for i, med in sorted(ans)]

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
y=sorted(x)
m1=y[n//2-1]
m2=y[n//2]
for i in x:
    if i>=m2:
        print(m1)
    else:
        print(m2)

Solution (Python):
n=int(input())
xl=list(map(int,input().split()))
sxl=sorted(xl[:])
if n==2:
    print(xl[1])
    print(xl[0])
    exit()
m1=sxl[n//2-1]
m2=sxl[n//2]
if m1==m2:
    for _ in range(n):
        print(m1)
    exit()
for x in xl:
    if x<=m1:
        print(m2)
    else:
        print(m1)

Solution (Python):
n=int(input())
l=[int(i) for i in input().split()]
l1=[[l[i],i] for i in range(n)]
l1.sort() 
mi=n//2 
cand1=l1[mi][0]
ind1=l1[mi][1]
cand2=l1[mi-1][0]
ind2=l1[mi][1]
if ind1>ind2:
    ind1,ind2=ind2,ind1
    cand1,cand2=cand2,cand1
ans=[0]*n 


for i in range(n): 
    if l[i]<=cand2:
        print(cand1)
    else:
       
        print(cand2)

Solution (Python):
import math
import copy



def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return((a*b)//gcd(a,b))

def main():
    
    
    
    
    n=int(input())
    a = list(map(int,input().split()))
    b=copy.copy(a)
    a.sort()
    for i in range(n):
        x=b[i]
        if x<=a[(n//2)-1]:
            print(a[(n//2)])
        else:
            print(a[(n//2)-1])

main()

Solution (Python):
N = int(input())
Xlist = list(map(int, input().split()))

Xlist_sorted = sorted(Xlist)
idx = (N-1) // 2
candidates = [Xlist_sorted[idx], Xlist_sorted[idx+1]]

for i in range(N):
    if Xlist[i] >= candidates[1]:
        print(candidates[0])
    else:
        print(candidates[1])

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
y = sorted(x)
a = y[n//2]
b = y[n//2-1]
for i in x:
  if i >= a:
    print(b)
  else:
    print(a)

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
y=sorted(x)
a=y[n//2-1]
b=y[n//2]
for u in x:
    if u<=a:
        print(b)
    else:
        print(a)

Solution (Python):
def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools

    n = int(input())
    xs = list(map(int, input().split()))
    xs_sorted = sorted(xs)
    medians_small = xs_sorted[n // 2 - 1]
    medians_large = xs_sorted[n // 2]
    for x in xs:
        if x <= medians_small:
            print(medians_large)
        else:
            print(medians_small)


if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
Y=[0]*N
for i in range(N):
  Y[i]=X[i]
X.sort()
L=X[N//2-1]
U=X[N//2]
for i in range(N):
  if(Y[i]<=L):
    print(U)
  else:
    print(L)

Solution (Python):
import copy

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

Y=sorted(X.copy())

a=Y[N//2-1]
b=Y[N//2]

for i in range(N):
    if X[i]<=a:
        print(b)
    else:
        print(a)

Solution (Python):
import copy
N = int(input())
X = list(map(int, input().split()))
L =copy.copy(X)
X.sort()
for i in L:
   if i <=X[N//2-1]:
      print(X[N//2])
   elif i >=X[N//2]:
      print(X[N//2-1])

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
Y = sorted(X)

x_s = Y[N // 2 - 1]
x_l = Y[N // 2]
for i in range(1, N + 1):
	if X[i - 1] <= x_s:
		print(x_l)
	else:
		print(x_s)

Solution (Python):
def slove():
    import sys
    import copy
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    x = list(map(int, input().rstrip('\n').split()))
    xl = copy.deepcopy(x)
    xl.sort()
    a = xl[n // 2-1]
    b = xl[n // 2]
    for i in range(n):
        if x[i] <= a:
            print(b)
        elif b <= x[i]:
            print(a)


if __name__ == '__main__':
    slove()

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
y = sorted(x)
a = y[n//2-1]
b = y[n//2]
for i in range(n):
  print(a if x[i] > a else b)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))

SORTED = sorted(X)
med1 = SORTED[N//2 - 1]
med2 = SORTED[N//2]


for xi in X:
    if xi <= med1:
        print(med2)
    else:
        print(med1)

Solution (Python):
def main():

    N = int(input())
    X = list(map(int, input().split()))
    Y = sorted(X)
    for i in range(N):
        if X[i] < Y[N//2]:
            print(Y[N//2])
        else:
            print(Y[N//2-1])

if __name__ == '__main__':
    
    main()

Solution (Python):
n = int(input())
k = [[int(i)] for i in input().split()]
for i in range(n):
    k[i].append(i)
k.sort()
a = k[n//2-1][0]
b = k[n//2][0]
ans = [0]*200010
for i in range(n//2):
    ans[k[i][1]] = b
for i in range(n//2,n):
    ans[k[i][1]] = a
for i in range(n):
    print(ans[i])

Solution (Python):
import statistics
n = int(input())
x = list(map(int,input().split()))

median_left = statistics.median_low(x)
median_right = statistics.median_high(x)

for i in range(n):
  if x[i] >= median_right:
    print(median_left)
  else:
    print(median_right)

Solution (Python):
import statistics
n = int(input())
x = list(map(int,input().split()))

median_left = statistics.median_low(x)
median_right = statistics.median_high(x)

for i in range(n):
  if x[i] == median_right:
    print(median_left)
  elif x[i] == median_left:
    print(median_right)
  else:
    if x[i] < median_left:
      print(median_right)
    else:
      print(median_left)

Solution (Python):
N = int(input())
x = list(map(int, input().split()))

y=sorted(x)
a = y[N//2]
b = y[N//2-1]

for i in range(N):
    if x[i] < a:
        print(a)
    else:
        print(b)

Solution (Python):
import copy

n = int(input())
x = list(map(int, input().split()))
y = copy.deepcopy(x)
y.sort()
a = y[n//2 -1]
b = y[n//2]
for i in range(n):
    if x[i]<=a:
        print(b)
    elif a<x[i]:
        print(a)

Solution (Python):
from operator import itemgetter
N = int(input())
X = list(map(int, input().split()))
data = []
for i in range(N):
    data.append([X[i],i])

data.sort()
k = (N//2) - 1
f = data[k][0]
s = data[k+1][0]

data = sorted(data, key = lambda x:x[1])
for i in range(N):
    if data[i][0] <= f:
        print(s)
    else:
        print(f)

Solution (Python):
n = int(input())
ary = list(map(int,input().split()))
sorted_ary = sorted(ary)
for i in range(n):
    a = n//2-1
    if sorted_ary[a] >= ary[i]:
        print(sorted_ary[a+1])
    else:
        print(sorted_ary[a])