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())
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])

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

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

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

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

x_org = list(map(int, input().split()))

x = sorted(x_org)

mid = x[n // 2 - 1]
midr = x[n // 2]

for i in range(n) :
    if x_org[i] <= mid :
        print(midr)
    else :
        print(mid)

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

sortedX=sorted(X)
m1=sortedX[n//2-1]
m2=sortedX[n//2]
for i in range(n):
  if X[i]<=m1:
    print(m2)
  else:
    print(m1)

Solution (Python):
import sys
import os
import copy
N = int(input())
X = list(map(int,input().split()))
XX = copy.deepcopy(X)
X.sort()
mid = X[N//2-1]
midr = X[N//2]
ans = 0
for x in XX:
    if x <= mid:
        ans = midr
    elif midr <= x:
        ans = mid
    print(ans)
    ans = 0

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 range(n):
  if x[i]<=m1:
    print(m2)
  else:
    print(m1)

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

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

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
l=len(x)
s=sorted(x)
m=s[l//2-1]
M=s[l//2]
for i in range(l):
  print(m if x[i]>m else M)

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

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

Solution (Python):


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

XX=sorted(X)

for item in X:
    if item<=XX[len(XX)//2-1]:
        print(XX[len(XX)//2])
    else:
        print(XX[len(XX)//2-1])

Solution (Python):
import copy

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

sort_X = copy.copy(X)
sort_X.sort()
small_median_X = sort_X[N//2 - 1]
big_median_X = sort_X[N//2]

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

Solution (Python):
N = int(input())
array = list(map(int, input().split()))
array_sorted = sorted(array)
ans = [array_sorted[(N//2)-1],array_sorted[N//2]]
for item in array:
    if item <= ans[0]:
        print(ans[1])
    else:
        print(ans[0])

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

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

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

Solution (Python):
import copy
n = int(input())
a = list(map(int,input().split()))

sa = copy.copy(a)
sa.sort()
L = sa[n//2 -1]
R = sa[n//2]
for i in a:
    if i <=L:
        print(sa[n//2])
    elif i>=R:
        print(sa[n//2 - 1])

Solution (Python):

import copy
N = int(input()) 
X_list = [int(e) for e in input().split()]

sort_X_list = copy.copy(X_list)
sort_X_list.sort(reverse=False)
Bi_smaller = sort_X_list[int(len(X_list)/2-1)]
Bi_bigger = sort_X_list[int(len(X_list)/2)]

for i in range(N):
    if X_list[i]>=Bi_bigger:
        print(Bi_smaller)
    else:
        print(Bi_bigger)

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

x2 = x.copy()
x2.sort()
tmp = x2[n // 2]
tmp2 = x2[n // 2 - 1]

for i in x:
    if i <= tmp2:
        print(tmp)

    else:
        print(tmp2)

Solution (Python):
def main():
    N = int(input())
    X = [(int(i),idx) for idx,i in enumerate(input().split())]
    Y = [(i,idx) for idx,i in enumerate(sorted(X))]
    ans1 = Y[(N//2)][0][0]
    ans2 = Y[N//2-1][0][0]
    Y.sort(key=lambda p: p[0][1])
    for y in Y:
        if y[1] <= N//2 - 1:
            print(ans1)
        else:
            print(ans2)

if __name__ == '__main__':
    main()

Solution (Python):

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

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

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

Solution (Python):


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

sorted_nums = sorted(org_nums) 
sorted_index = sorted(range(len(org_nums)), key=lambda k: org_nums[k]) 
extract_index = sorted(range(len(sorted_index)), key=lambda k: sorted_index[k]) 

for i in extract_index:
    if i+1 <= n // 2:
        print(sorted_nums[n//2])
    else:
        print(sorted_nums[n//2-1])

Solution (Python):
from heapq import heappush, heappop

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

m = int(n/2)-1
x_tmp = sorted(x)

for i in range(n):
    if x[i] <= x_tmp[m]:
        print(x_tmp[m+1])
    else:
        print(x_tmp[m])

Solution (Python):
import sys

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

def main():
    n=int(input())
    xx=list(map(int, input().split()))
    cxx=sorted(xx)
    m0=cxx[n//2-1]
    m1=cxx[n//2]
    for x in xx:
        if x<=m0:print(m1)
        else:print(m0)

main()

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

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

Solution (Python):
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
b = sorted(a)
l,r = b[n//2-1],b[n//2]
for i in a:
    if i <= l:
        print(r)
    else:
        print(l)

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
XX=[]
for i in range(N):
    XX.append([X[i],i])
XX=sorted(XX,key=lambda x:x[0])

for i in range(N):
    if i<=N//2-1:
        XX[i].append(XX[N//2][0])
    else:
        XX[i].append(XX[N//2-1][0])

XX=sorted(XX,key=lambda x:x[1])

for i in range(N):
    print(XX[i][2])

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

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

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

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

X_s = sorted(X)

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

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

X_s = sorted(X)

median = [X_s[N//2-1], X_s[N//2]]


for i in range(N):
    if X[i] <= X_s[N//2-1]:
        print(X_s[N//2])
    else:
        print(X_s[N//2-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 range(N):
    if X[i]<a:
        print(a)
    else:
        print(b)

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

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

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

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
t=sorted(x)
m=n//2
a=t[m-1];b=t[m]

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

Solution (Python):
n=int(input())
ls=[int(s) for s in input().split()]
ls2=sorted(ls)
m=ls2[n//2-1]
M=ls2[n//2]
for i in range(n):
  if ls[i]<=m:
    print(M)
  else:
    print(m)

Solution (Python):
import collections
n = int(input())
x = list(map(int, input().split()))
tmp = sorted(x)
xl = tmp[n // 2 - 1]
xr = tmp[n // 2]
if xl == xr:
    for i in range(n):
        print(xl)
    exit()
for i in x:
    if i > xl:
        print(xl)
    elif i < xr:
        print(xr)

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
X_s=sorted(X)
ans1=X_s[N//2]
ans2=X_s[N//2-1]
for i in X:
    print(ans1*(i<=ans2) or ans2)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
b = list(a)
b.sort()
c = int(n/2)
ML=b[c-1]
MR=b[c]
for i in range(0,n):
    if a[i] >= MR:
        print(ML)
    else:
        print(MR)

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

Solution (Python):
import sys
from functools import reduce
import copy
import math
from pprint import pprint


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    nums = string_to_int(inputs[0])
    sorted_nums = sorted(nums)
    N = len(nums)
    medians = []
    median_candidate = [sorted_nums[N//2 - 1], sorted_nums[N//2]]
    for a in nums:
        if a <= median_candidate[0]:
            medians.append(median_candidate[1])
        else:
            medians.append(median_candidate[0])
    return medians


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    for r in ret:
        print(r)

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
for i in range(N):
  A[i] = [A[i],i]
A.sort()
B = A
for i in range(N):
  A[i] = [A[i],i]
A = sorted(A,key = lambda x : x[0][1])
c = N//2-1
for i in range(N):
  if A[i][1]<=c:
    print(B[N//2][0][0])
  else:
    print(B[c][0][0])

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
ans = dict()
x_copy = sorted(x[:])
right = x_copy[(n//2)-1]
left = x_copy[-(n//2)]

for i in range(n):
    if i < n//2:
        ans[x_copy[i]] = left
    else:
        ans[x_copy[i]] = right

for i in x:
    print(ans[i])

Solution (Python):
n,*x=map(int, open(0).read().split());xc=sorted(x);
for i in x:print(xc[n//2-(i>(xc[n//2-1]+xc[n//2])/2)])

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

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

Solution (Python):
N = int(input())
x = input().split()
X = [(int(x[i]), i) for i in range(N)]
X.sort()
ans = [0]*N
for i in range(N // 2):
    ans[X[i][1]] = X[N // 2][0]
for i in range(N // 2, N):
    ans[X[i][1]] = X[N // 2 - 1][0]
for i in range(N):
    print(ans[i])

Solution (Python):
n = int(input())
xs = list(map(int,input().split()))
xs_copy = xs.copy()
xs.sort()
a = xs[n//2-1]
b = xs[n//2]
for x in xs_copy:
  if x  <= a:
    print(b)
  elif x >= b:
    print(a)

Solution (Python):
N=int(input())
X=[int(i) for i in input().split()]
Y=sorted(X)
MidL=Y[N//2-1]
MidR=Y[N//2]
for x in X:
	if x>=MidR:print(MidL)
	else:print(MidR)

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

Solution (Python):
import sys
from collections import defaultdict, deque
from heapq import *
sys.setrecursionlimit(200000)
input = sys.stdin.readline


N = int(input())
L = [int(v) for v in input().split()]





lc = L.copy()
L.sort()

t = int(N // 2) * -1
center = L[t]
c2 = L[t - 1]
for i in range(N):
    c = lc[i]

    if c < center:
        print(center)
    else:
        print(c2)

Solution (Python):
from bisect import bisect_left
N = int(input())
x = [int(i) for i in input().split()]
sorted_x = sorted(x)

mid = N // 2
for i in range(N) :
    if bisect_left(sorted_x, x[i]) < mid :
        print(sorted_x[N//2])
    else :
        print(sorted_x[N//2-1])

Solution (Python):
N = int(input())
X = [int(x) for x in input().split()]

for i in range(N):
    X[i] = [X[i], i]
    
X.sort(reverse=True)
B = [0 for i in range(N)]
for i in range(N):
    if (i+1) <= N*0.5:
        B[X[i][1]] = X[N//2][0]
    else:
        B[X[i][1]] = X[N//2-1][0]
        
for i in range(N):
    print(B[i])

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

x_1 = x_sorted[n // 2 - 1]
x_2 = x_sorted[n // 2]

for x_ in x:
    if x_ <= x_1:
        print(x_2)
    else:
        print(x_1)

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

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

print("\n".join(str(med2) if X[i] < med2 else str(med1) for i in range(N)))

Solution (Python):
import statistics

N = int(input())
x = list(map(int, input().split()))
sx = sorted(x)
tmp = statistics.median(sx)

for i in range(N):
    if x[i] <= tmp:
        print(sx[((N - 1) // 2) + 1])
    else:
        print(sx[(N - 1) // 2])

Solution (Python):
from heapq import *

N=int(input())
X=list(map(int,input().split()))
h=[]
for i in X:
    heappush(h,i)
for i in range(N//2-1):
    heappop(h)
a = heappop(h)
b = heappop(h)
for i in X:
    print(a if i >= b else b)

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

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

Y = sorted(X)

for i in range(N):
    if X[i] <= Y[N // 2 - 1]:
        print(Y[N // 2])
    elif X[i] >= Y[N // 2]:
        print(Y[N // 2 - 1])

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

Xsorted=sorted(X)

ans1=Xsorted[(N-1)//2]
ans2=Xsorted[(N-1)//2+1]

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

Solution (Python):
import collections

N=int(input())

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

B_dict=collections.Counter(X)
B=sorted(B_dict.items())

cnt=0
for i in range(len(B)):
    cnt+=B[i][1]
    if cnt==N//2:
        ans1=B[i][0]
        ans2=B[i+1][0]
        break
    elif cnt>=N//2+1:
        ans1=B[i][0]
        ans2=B[i][0]
        break


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

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

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

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

Solution (Python):
import copy
n = int(input())
x=list(map(int,input().split()))
l=copy.copy(x)
l.sort()
n1 = l[n//2-1]
n2 = l[n//2]
for i in range(n):
  if x[i]>n1:
    print(n1)
  else:
    print(n2)

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

X2 = sorted(XList)
a1 = X2[N//2-1]
a2 = X2[N//2]


for b in XList:
    if b <= a1:
        print(a2)
    elif b >=a2:
        print(a1)
    else:
        print('ERROR')

Solution (Python):
import copy

N=int(input())
X=list(map(int,input().split()))
Y=copy.deepcopy(X)
X.sort()
x1,x2=X[N//2-1],X[N//2]

for i in Y:
  print(x1 if i>=x2 else x2)

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

xs = sorted(x)
med_left = xs[n//2-1]
med_right = xs[n//2]

for i in range(n):
    if x[i] <= med_left:
        print(med_right)
    else:
        print(med_left)

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

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

Solution (Python):
N = int(input())
X = [int(x) for x in input().split()]

XX = list(tuple(X))
XX.sort()
X_medium_1 = XX[(N//2)-1]
X_medium_2 = XX[N//2]

for n in range(N):
  if X[n] <= X_medium_1:
    print(X_medium_2)
  else: 
    print(X_medium_1)

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

sorted_A = sorted(A)

left_med = sorted_A[(N-1)//2]
right_med = sorted_A[(N+1)//2]

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

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

Solution (Python):

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

y = sorted(x)
l = y[n//2 - 1]
r = y[n//2]
 
for x in x:
  print(l if x >= r else r)

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

Solution (Python):

def main():
    N, *X = map(int, open(0).read().split())
    l, h = sorted(X)[N // 2 - 1 : N // 2 + 1]
    ans = [h if i <= l else l for i in X]
    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()

Solution (Python):

def main():
    N, *X = map(int, open(0).read().split())
    l, h = sorted(X)[N // 2 - 1 : N // 2 + 1]
    ans = [h if i <= l else l for i in X]
    print(*ans, sep="\n")


if __name__ == "__main__":
    main()

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

def main():
    N = int(input())
    X = list(map(int, input().split()))
    Y = X.copy()
    Y.sort()
    m1 = Y[N//2-1]
    m2 = Y[N//2]
    for x in X:
        if x <= m1:
            print(m2)
        elif x >= m2:
            print(m1)

if __name__ == '__main__':
    main()

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

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

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

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

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

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 range(N):
  if X[i] <= m1:
    print(m2)
  else:
    print(m1)

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

lmid = sorted_x[n // 2 - 1]
rmid = sorted_x[n // 2]

for xi in x:
    if xi <= lmid:
        print(rmid)
    else:
        print(lmid)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
sorted_x = sorted(x)
i1 = sorted_x[n//2-1]
i2 = sorted_x[n//2]

ans = []

for a in x:
  if a >= i2:
    ans.append(i1)
  else:
    ans.append(i2)
    
print(*ans, sep='\n')

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 X:
    if i <= a:
        print(b)
    else:
        print(a)

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

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

Solution (Python):
import sys
n=int(input())
x=list(map(int,input().split()))
y=sorted(x)
mid1=y[(n//2)-1]
mid2=y[n//2]
if mid1==mid2:
  for j in range(n):
    print(mid1)
  sys.exit()
for i in range(n):
  if x[i]<mid1:
    print(mid2)
  if x[i]==mid1 and x.count(mid1)>2:
    print(mid1)
  if x[i]==mid1 and x.count(mid1)<3:
    print(mid2)
  if x[i]==mid2 and x.count(mid2)>2:
    print(mid2)
  if x[i]==mid2 and x.count(mid2)<3:
    print(mid1)
  if x[i]>mid2:
    print(mid1)

Solution (Python):

import copy
N = int(input())
X = list(map(int, input().split()))
X2 = []

X2 = copy.copy(X)
X2.sort(reverse=True)
Xm_1 = X2[N//2]
Xm_2 = X2[(N//2)-1]

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

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

Solution (Python):
n=int(input())
x=[int(i) for i in input().split()]
xs=sorted(x)
left=xs[n//2-1]
right=xs[n//2]
for i in x:
    if i <= left:
        print(right)
    else:
        print(left)

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

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

Solution (Python):


def main():


   X = int(input())
   oriList = list(map(int,input().split()))
   lis = sorted(list(oriList))

   if len(lis)%2==0:
      mid = lis[len(lis)//2-1]
      nextmid = lis[len(lis)//2]
   else:
      mid = lis[(len(lis)+1)//2-1]
      nextmid = lis[(len(lis)+1)//2]
   


   for i in oriList:
      if i <= mid:
         print(nextmid)
      else:
         print(mid)


   





if __name__== "__main__":
    main()

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

import copy

cp = copy.deepcopy(x)
cp.sort()
x_l = cp[n//2 - 1]
x_r = cp[n//2]

for ele in x:
    if ele <= x_l:
        print(x_r)
    else:
        print(x_l)

Solution (Python):
import bisect
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)

left=b[int(n/2)-1]
right=b[int(n/2)]
for i in a:
    pos=bisect.bisect_left(b, i)+1
    if 2*pos<=n:
        print(right)
    else:
        print(left)

Solution (Python):
N=int(input())
X=[int(x) for x in input().split()]
XX=sorted(X)
L=XX[N//2-1]
R=XX[N//2]
for x in X:
  print(L if x>=R else R)

Solution (Python):
def get_medians(nums):
    s = sorted(nums)
    mid = len(s) // 2
    return (s[mid - 1], s[mid])

input()
nums = [int(tok) for tok in input().split()]

medians = get_medians(nums)
for num in nums:
    if num <= medians[0]:
        print(medians[1])
    else:
        print(medians[0])

Solution (Python):

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

mid_1 = sort_x[n//2-1]
mid_2 = sort_x[n//2]

for i in range(n):
  
  if x[i] <= mid_1:
    print(mid_2)
  else:
    print(mid_1)

Solution (Python):

import sys
import math
from collections import defaultdict


sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]


mod = 10**9 + 7


def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))



def index_sort(A):
    x = []
    for i,a in enumerate(A):
        x.append((a,i))
    return sorted(x, key=lambda x: x[0])

N = I()
X = III()

y = index_sort(X)
order = [0]*N
for i in range(N):
    order[y[i][1]] = i

for i in range(N):
    if order[i]<=(N-1)//2:
        print(y[(N+1)//2][0])
    else:
        print(y[(N-1)//2][0])

Solution (Python):
import sys

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

X_sort = sorted(X)

ans_1 = X_sort[N//2-1]
ans_2 = X_sort[N//2]

if ans_1 == ans_2:
	for _ in range(N):
		print(ans_1)
	sys.exit()

for i in range(N):
	if X[i] < ans_2:
		print(ans_2)
	elif X[i] > ans_1:
		print(ans_1)

Solution (Python):
from math import ceil
N = int(input())

x = list(map(int,input().split()))
x_sort = sorted(x)
length = len(x)
median = (x_sort[ceil(length/2-1)]+x_sort[ceil(length/2)])/2

for i in range(length):
    if x[i] <= median:
        print(x_sort[ceil(length/2)])
    else:
        print(x_sort[ceil(length/2-1)])

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
X_sorted = sorted(X)
median_upper = X_sorted[N//2]
median_lower = X_sorted[N//2 - 1]

for x in X:
	if x < median_upper:
		print(median_upper)
	elif x > median_lower:
		print(median_lower)
	else:
		print(median_lower)

Solution (Python):
import sys
from statistics import *
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
xxx = na()
r = median_high(xxx)
l = median_low(xxx)
for i in range(n):
    if xxx[i] <= l:
        print(r)
    elif xxx[i] >= r:
        print(l)

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

Solution (Python):
def main():
    N = int(input())
    x = list(map(int, input().split()))
    x = sorted([(x[i], i) for i in range(N)])
    ans = [0] * N
    for i in range(N//2):
        ans[x[i][1]] = x[N//2][0]
    for i in range(N//2, N):
        ans[x[i][1]] = x[N//2 - 1][0]
    for i in range(N):
        print(ans[i])

if __name__ == "__main__":
    main()

Solution (Python):
from statistics import median_high, median_low
n = int(input())
x = list(map(int, input().split()))
h = median_high(x)
l = median_low(x)
for i in x : print(h if h>i else l)

Solution (Python):

import sys
from bisect import bisect_left

def solve(N: int, X: "List[int]"):
    y = sorted(X)
    b = y[int(N/2)-1]
    a = y[int(N/2)]

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

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    X = [int(next(tokens)) for _ in range(N)]  
    solve(N, X)

if __name__ == '__main__':
    main()

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

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

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

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