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

M_small = sorted(X)[N // 2 - 1]
M_large = sorted(X)[N // 2]

for xi in X:
    if xi <= M_small:
        print(M_large)
    else:
        print(M_small)

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

n1, n2 = xsort[n//2-1], xsort[n//2]

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

Solution (Python):
n = int(input())
x = [int(i) for i in input().split()]
xx = sorted(x)
l = xx[n//2-1]
r = xx[n//2]

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

Solution (Python):
n = int(input())
x = [int(i) for i in input().split()]
xx = sorted(x)
l = xx[n//2-1]
r = xx[n//2]

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

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


if __name__ == "__main__":
    resolve()

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

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

Solution (Python):


import copy

n = int(input().split()[0])
x_list = list(map(int, input().split()))
sorted_x_list = sorted(x_list)
mean_index = int((n + 1)/ 2) - 1
mean_list = []

a = sorted_x_list[mean_index]
b = sorted_x_list[mean_index + 1]
for x in x_list:
    if x <= a:
        mean_list.append(str(b))
    else:
        mean_list.append(str(a))

ans = '\n'.join(mean_list)
print(ans)

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

x_med_l = x_sorted[n//2 - 1]
x_med_r = x_sorted[n//2]

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

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

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

for x in X:
    if x < a[N // 2]:
        print(a[N // 2])
    else:
        print(a[N // 2 - 1])

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

if __name__ == '__main__':
    main()

Solution (Python):
import copy

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

Y = copy.copy(X)
Y.sort()

first = (N // 2) - 1
second = N // 2

for i in X:
    if i <= Y[first]:
        print(Y[second])
    else:
        print(Y[first])

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

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

for x in X:
    if x < CR:
        print(CR)
    else:
        print(CL)

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

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]<b:
        print(b)
    else:
        print(a)

Solution (Python):
import statistics

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

y = sorted(x)
med = statistics.median(x)
med_1 = y[int((n-2)/2)]
med_2 = y[int(n/2)]

for i in range(n):
    if x[i] < med:
        print(med_2)
    elif x[i] >= med:
        print(med_1)

Solution (Python):
"""
中央値

2 4 4 3
2 3 4 4
真ん中の2つの値を取り出す
⇨
"""

N = int(input())
Xs = list(map(int, input().split()))
X_sort = sorted(Xs)
M1 = X_sort[N//2-1]
M2 = X_sort[N//2]


for x in Xs:
    if x <= M1:
        print(M2)
    else:
        print(M1)

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

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

Solution (Python):
import copy

n = int(input())
x = [int(i) for i in input().split()]

x1 = copy.deepcopy(x)

x1.sort()

mae = x1[(n//2)-1]
ato = x1[(n//2)]

for i in range(len(x)):
    if x[i] > mae:
        print(mae)
    else:
        print(ato)

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

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

Solution (Python):
import copy
N = int(input())

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

sorted_lst = sorted(lst)
idx = (N-1) // 2
low = sorted_lst[idx]
high = sorted_lst[idx+1]
for i in range(N):
  if lst[i] <= low:
    print(high)
  else:
    print(low)

Solution (Python):
n = int(input())
l = list(map(int, input().split()))
m = sorted(l)

for i in range(n):
  if l[i] <= m[n//2-1]:
    print(m[n//2])
  else:
    print(m[n//2-1])

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

if N==2:
    print(A[1])
    print(A[0])
    exit(0)

for i in range(N):
    B.append(A[i])

B.sort()

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

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

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

    sort_X = sorted(X)
    X1 = sort_X[N//2]
    X2 = sort_X[(N//2) - 1]

    for x in X:
        if x <= X2:
            print(X1)
        else:
            print(X2)
main()

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

nX  = sorted(X)
l = N-1

med_1 = nX[(l+1)//2] 
med_2 = nX[(l+1)//2-1]

for x in X:
    if x<med_1:
        print(med_1)
    else:
        print(med_2)

Solution (Python):
n = int(input())
x = [int(i) for i in input().split()]
s = sorted(x)
l = s[len(s) // 2 - 1]
r = s[len(s) // 2]
print(*[r if i <= l else l for i in x], sep='\n')

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

Solution (Python):
from collections import defaultdict

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

B = sorted(A)
index = defaultdict(lambda: -1)
for i, b in enumerate(B):
    index[b] = i

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

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

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

Solution (Python):
from sys import stdin
N = int(stdin.readline().rstrip())
data = [int(x) for x in stdin.readline().rstrip().split()]

d1 = sorted(data)[(N//2)-1]
d2 = sorted(data)[(N//2)]

for i in data:
    if i <= d1:
        print(d2)
    else:
        print(d1)

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

Xs = sorted(X)
med_d = Xs[N // 2 - 1]
med_u = Xs[N // 2]

for i in range(N):
    if X[i] <= med_d:
        print(med_u)
    elif X[i] >= med_u:
        print(med_d)

Solution (Python):
n = int(input())
ls = [x for x in map(int, input().split(' '))]
dam = sorted(ls.copy())

for x in range(0, n):
    if ls[x] < dam[n // 2]:
        print(dam[n // 2])
    else:
        print(dam[(n // 2) - 1])

Solution (Python):
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
X = list(map(int, sys.stdin.readline().split()))
X2 = list(sorted(X))
x1 = X2[N // 2 - 1]
x2 = X2[N // 2]


for x in X:
    if x <= x1:
        print(x2)
    else:
        print(x1)

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

Solution (Python):

from bisect import bisect_left,bisect_right

n=int(input())
x=list(map(int,input().split()))
xx=sorted(x)
mid=n//2

ans=[]
for i in range(n):
    if bisect_left(xx,x[i])<mid:
        ans.append(xx[mid])
    else:
        ans.append(xx[mid-1])
print(*ans,sep='\n')

Solution (Python):


from bisect import bisect_left,bisect_right

n=int(input())
x=list(map(int,input().split()))
xx=sorted(x)
mid=n//2

for i in range(n):
    if bisect_left(xx,x[i])<mid:
        print(xx[mid])
    else:
        print(xx[mid-1])

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

Solution (Python):

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

n = getint()
xs = getints()
ys = list(sorted(xs))

mid1 = ys[n//2-1]
mid2 = ys[n//2]

for x in xs:
    y = mid2 if x <= mid1 else mid1
    print(y)

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

leftB = A[N//2 - 1]
rightB = A[N//2]

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

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

Solution (Python):
n = int(input())
lst = [int(i) for i in input().split()]
lst_sort = sorted(lst)
med = (lst_sort[n//2] + lst_sort[n//2-1])/2

for i in range(n):
    if lst[i] < med:
        print(lst_sort[n//2])
    else:
        print(lst_sort[n//2-1])

Solution (Python):
a,*l=map(int,open(0).read().split())
k=sorted(l)
n,m=k[a//2-1],k[a//2]
for i in l:
	print((n,m)[i<m])

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

Solution (Python):
n = int(input())
li = list(map(int, input().split()))
mid_id = (len(li)//2)
temp = li.copy()
temp.sort()
mid1 = temp[mid_id-1]
mid2 = temp[mid_id]
for i in li:
    if i <= mid1:
        print(mid2)
    else:
        print(mid1)

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

x1=sorted(x)

ans1=x1[n//2-1]
ans2=x1[n//2]

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()))
l=sorted(x)[n//2-1:n//2+1]
for i in range(n):print(l[x[i]<=l[0]])

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

mylist = sorted(X)
for i in range(N):
	ans = mylist[N//2-1]
	if X[i] > ans:
		print(ans)
	else:
		print(mylist[N//2])

Solution (Python):
N = int(input())
X = [int(s) for s in input().split()]
Y = sorted(X)
xl = Y[N // 2 - 1]
xr = Y[N // 2]
for x in X:
    print(xr if x <= xl else xl)

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

li1 = sorted(li)
p = li1[n//2]
q = li1[n//2-1]

for i in li:
    if i <= q:
        print(p)
    else:
        print(q)

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

B = A.copy()

B.sort()

for num in A:
  if B[N//2] > num:
    print(B[N//2])
  else:
    print(B[N//2-1])

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

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

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
sorted_X = sorted(X)
sorted_indices = sorted(range(len(X)), key=lambda k: X[k])
median_index = N // 2 - 1
ans = []
for i, x in enumerate(sorted_X):
    if i <= median_index:
        ans.append((sorted_indices[i], sorted_X[median_index + 1]))
    elif median_index < i:
        ans.append((sorted_indices[i], sorted_X[median_index]))
ans = sorted(ans, key=lambda x: x[0])
for x in ans:
    print(x[1])

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

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
X = [[X[i],i] for i in range(N)]


X.sort()
medind = (N-2)//2 
med = X[medind][0]
res = [0]*N

for i in range(N):
    if i <= medind:
        res[X[i][1]] = X[medind+1][0]
    else:
        res[X[i][1]] = med


for i in range(N):
    print(res[i])

Solution (Python):
N = int(input())
arr = []
for x in list(map(int,input().split())):
    arr.append(x)
sort_arr = sorted(arr)
mid1 = sort_arr[N//2-1]
mid2 = sort_arr[N//2]

for x in arr:
    if x <= mid1:
        print(mid2)
    else:
        print(mid1)

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:
    if x <= l:
        print(r)
    else:
        print(l)

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

Solution (Python):
n = int(input())
X = [int(i) for i in input().split()]
sX = sorted(X)
r,l = sX[n//2],sX[n//2-1]
if r != l:
    for x in X:
        if x<=l: print(r)
        else: print(l)
else:
    for _ in range(n): print(l)

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

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




Xsort=sorted(X)
l=(N-1)//2
r=l+1
th=Xsort[l]
for i in range(N):
    if X[i]<=th:
        ans=Xsort[r]
    else:
        ans=Xsort[l]
    print(ans)

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

medi1 = X_sort[int(N/2) - 1]
medi2 = X_sort[int(N/2)]

for i in range(N):
    if X[i] >= medi2:
        print(medi1)
    else:
        print(medi2)

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


buff_x = X.copy()


X.sort()
mm = X[N//2-1]
mx = X[N//2]
for i in range(N):
    if buff_x[i] < mx:
        print(mx)
    else:
        print(mm)

Solution (Python):
input()
x=list(map(int,input().split()))
z=sorted(x)[(len(x))//2-1:]
for c in x:print(z[c<=z[0]])

Solution (Python):



from copy import deepcopy
from operator import itemgetter
n = int(input())
x = list(map(int,input().split()))
y = sorted(x)
c1 = y[n//2-1]
c2 = y[n//2]
for i in x:
    if i < c2:
        print(c2)
    elif i >= c2:
        print(c1)

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

Solution (Python):

import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import numpy as np
import statistics
from statistics import mean, median,variance,stdev
import math

def main():
	N = int(input())
	A = input().split(" ")
	A = [int(s) for s in A]
	
	tmp = copy.deepcopy(A)
	tmp.sort()
	
	m1_p = (len(tmp) / 2) - 1
	m1 = tmp[int(m1_p)]
	m2_p = (len(tmp) / 2)
	m2 = tmp[int(m2_p)]
	
	ans = []
	for i, val in enumerate(A):
		if val <= m1:
			ans.append(m2)
		else:
			ans.append(m1)
			
	for i in ans:
		print(i)
			
	
if __name__ == "__main__":
	main()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
indexedA = []
for i in range(0, N):
	indexedA.append([i, A[i]])
indexedA.sort(key = lambda v: v[1])
m1 = indexedA[N//2-1][1]
m2 = indexedA[N//2][1]
anslist = []
for i in range(0, N):
	if i < N//2:
		anslist.append([indexedA[i][0], m2])
	else:
		anslist.append([indexedA[i][0], m1])
anslist.sort(key = lambda v: v[0])
for i in range(0, N):
	print(anslist[i][1])

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

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]:
        print(y[n//2 - 1])
    else:
        print(y[n//2])

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

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

sm = SX[N//2-1]
bi = SX[N//2]

for x in X:
    if x <= sm:
        print(bi)
    else:
        print(sm)

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

Solution (Python):

N = int(input())
X = [int(_) for _ in input().split()]
tmp = sorted(X)

one = N // 2 - 1
two = N // 2

for x in X:
    if x <= tmp[one]:
        print(tmp[two])
    else:
        print(tmp[one])

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

Solution (Python):
from functools import reduce
import math
import copy
def main():
    
    
    
    

    
    
    
    
    
    

    
    

    
    
    
    
    
    
    
    
    
    INF = float("inf")

    
    MOD = 10**9+7
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    
    N = int(input())
    X = list(int(_) for _ in input().split())
    X_tmp = copy.deepcopy(X)
    X_tmp.sort()
    X_avg = (X_tmp[(N//2)-1] + X_tmp[(N//2)])/2
    for i in range(N):
        if X[i] > X_avg:
            print(X_tmp[(N//2)-1])
        else:
            print(X_tmp[(N//2)])
            
if __name__ == '__main__':
    main()

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

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]:
        print(y[n//2])
    else:
        print(y[n//2 - 1])

Solution (Python):
def resolve():
	n=int(input())
	x=list(map(int,input().split()))
	s=sorted(x)
	m=s[(n-2)//2]
	for i in x:
		ans=s[(n-2)//2+1] if i<=m else m
		print(ans)
	
resolve()

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

middle = int(n/2) - 1
next_middle = middle + 1

for i in range(n):
  if x[i] <= sort_x[middle]:
    print(sort_x[next_middle])
  elif x[i] >= sort_x[next_middle]:
    print(sort_x[middle])

Solution (Python):

def main():
    n = int(input())
    x = list(map(int, input().rstrip().split()))
    sort_x = sorted(x)
    l, h = sort_x[n // 2 - 1], sort_x[n // 2]
    for i in x:
        if i <= l:
            print(h)
        else:
            print(l)


if __name__ == "__main__":
    main()

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

temp = sorted(X)

l = temp[N//2-1]
r = temp[N//2]

for i, x in enumerate(X):
    if x <= l:
        print(r)
    else:
        print(l)

Solution (Python):
n = int(input())
lst_x = list(map(int, input().split()))
lst = lst_x[:]
lst.sort()
b1 = lst[n//2 - 1]
b2 = lst[n//2]


for x in lst_x:
    print(b2 if x <= b1 else b1)

Solution (Python):
n = int(input())
lst_x = list(map(int, input().split()))
lst = lst_x[:]
lst.sort()
b1 = lst[n//2 - 1]
b2 = lst[n//2]


for x in lst_x:
    if x <= b1:
        ans = b2
    else:
        ans = b1
    print(ans)

Solution (Python):
n = int(input())
lst_x = list(map(int, input().split()))
lst = lst_x[:]
lst.sort()
b1 = lst[n//2 - 1]
b2 = lst[n//2]


for x in lst_x:
    if x <= b1:
        ans = b2
    else:
        ans = b1
    print(ans)

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

Y = sorted(X)

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

ans = []

for x in X :
    if x <= a :
        ans.append(b)
    else :
        ans.append(a)

print(*ans,sep="\n")

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
X2=sorted(X)
x=X2[N//2-1]
y=X2[N//2]

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

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])
    else:
        print(y[n//2-1])

Solution (Python):
N = int(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 X[i] <= a:
        print(b)
    else:
        print(a)

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

Y=sorted(X)

a1=Y[N//2-1]
a2=Y[N//2]

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

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

Solution (Python):

N = int(input())

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

X_c = X.copy()

X_c.sort()





bh = X_c[(N//2)-1]
fr = X_c[N//2]





for i in X:

    if i < fr:
        print (fr)
    else:
        print (bh)

Solution (Python):
import bisect
n=int(input())
x=list(map(int,input().split()))
y=[]
for i in range(n):
    y.append(x[i])

x.sort()

for i in range(n):
    if bisect.bisect_left(x,y[i])+1 <= len(x)/2:
        print(x[int(len(x)/2)])
    else:
        print(x[int(len(x)/2)-1])

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

for i in range(N):
  print(sortedX[N // 2] if sortedX[N // 2] > X[i] else sortedX[N // 2 - 1])

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

Solution (Python):
N = int(input())
X = [int(x) for x in 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 = [[int(x), i] for i,x in enumerate(input().split())]
M = sorted(X)
median = N // 2
for i in range(N):
    X[M[i][1]][1] = i
for i in range(N):
    print(M[median][0] if X[i][1] < median else M[median-1][0])

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

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

Solution (Python):
N = int(input())
X = [int(i) for i in input().split()]
X_sorted = sorted(X)
a = X_sorted[len(X_sorted)//2]
b = X_sorted[len(X_sorted)//2-1]
for i in X:
  if i <= b:
    print(a)
  elif i >= a:
    print(b)

Solution (Python):
import copy


if __name__ == '__main__':
    N = int(input())
    X_list = list(map(int, input().split()))
    tmp_X_list = copy.deepcopy(X_list)
    tmp_X_list = sorted(tmp_X_list)
    med_minus1 = tmp_X_list[N//2-1]
    med_plus1 = tmp_X_list[N//2]

    answer = -1
    for i in range(0, N):
        if X_list[i] <= med_minus1:
            answer = med_plus1
        elif X_list[i] >= med_plus1:
            answer = med_minus1

        print(answer)

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

s = sorted(x)
h = n // 2

for i in x:
    if i < s[h]:
        print(s[h])
    else:
        print(s[h-1])

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

y = range(n)

z = [[x[i],y[i],0] for i in range(n)]

z.sort(key = lambda t:t[0])
for i in range(n):
    if i < int(n/2):
        z[i][2] = z[int(n/2)][0]
    else:
        z[i][2] = z[int(n/2)-1][0]
z.sort(key = lambda t:t[1])
for i in range(n):
    print(z[i][2])

Solution (Python):
N = int(input())
s = input().split()
X = []
for i in range(N):
    X.append(int(s[i]))
sortedX = sorted(X)

mid = int((len(X))/2)



for i in range(N):
   
    if X[i] < sortedX[mid]:
        print(sortedX[mid])
        
    else:
        print(sortedX[mid-1])

Solution (Python):
N = int(input())
a = sorted(map(lambda x, y: [int(y), x], range(1, N+1), input().split()))
 
m = N // 2
am = a[m][0]
amp = a[m-1][0]

a = sorted(zip(a, range(N)), key=lambda x:x[0][1])
for _, i in a:
  print(am if i < m else amp)

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

X_sort = sorted(X)
median_min = X_sort[N//2-1]
median_max = X_sort[N//2]

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

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

y = sorted(x)
med1 = y[n//2-1]
med2 = y[n//2]

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

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

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

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

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

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

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
Xn = sorted(X)
X1 = Xn[:-1]
X2 = Xn[1::]
m1 =  X1[N//2-1]
m2 =  X2[N//2-1]

for i in range(N):
    if X[i] >= m2:
        print(m1)
    else:
        print(m2)

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

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

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  _l=sorted(l)

  if n%2==0:
    a=_l[n//2-1]
    b=_l[n//2]

    for x in l:
      if x<=a:
        print(b)
      else:
        print(a)

main()

Solution (Python):

def solve(X):
    N = len(X)
    
    A = sorted([(x, i) for i, x in enumerate(X)])
    
    R = sorted([(i, x, rank) for rank, (x, i) in enumerate(A)])
    
    
    
    
    
    
    
    t = N // 2 - 1
    for i, x, rank in R:
        if rank <= t:
            print(A[t+1][0])
        else:
            print(A[t+0][0])


N = int(input())
X = [int(x) for x in input().split()]
solve(X)

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

arr = list(map(int, input().split()))
sorted_arr = sorted(arr)

median_big = sorted_arr[n // 2]
median_small = sorted_arr[n // 2 - 1]

for a in arr:
    if a >= median_big:
        print(median_small)
    else:
        print(median_big)

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


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

sort_x = sorted(x, reverse = True)

middle = int(N / 2)
for i in x:
    if i <= sort_x[middle]:
        print(sort_x[middle - 1])
    else:
        print(sort_x[middle])

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

Solution (Python):
import math
import fractions
import copy

def j(q):
    if q==1: print("Yes")
    elif q == 0:print("No")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def printrow(a):
    for i in a:
        print(i)
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


n = ip()                                     

a = [int(i) for i in input().split()]        









b = sorted(a)
leftmed = b[n//2-1]
rightmed = b[n//2]
for i in range(n):
    if a[i] >= rightmed:
        print(leftmed)
    else:
        print(rightmed)

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

Solution (Python):
import copy
N=int(input())
X=list(map(int,input().split()))
Y=copy.deepcopy(X)
Y.sort()

for i in X:
    if i>Y[(N-2)//2]:
        print(Y[(N-2)//2])
    else:
        print(Y[N//2])