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())
xlist=list(map(int,input().split()))

x2list=xlist[:]
x2list.sort()
mid_l=x2list[N//2-1]
mid_r=x2list[N//2]


for x in xlist:
  if x<=mid_l:
    print(mid_r)
  else:
    print(mid_l)

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



middle_left = X_sort[N//2-1]
middle_right = X_sort[N//2]


for idx, x in enumerate(X):
    if x <= middle_left:
        print(middle_right)
    elif middle_right <= x:
        print(middle_left)

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

Solution (Python):
import sys
sys.setrecursionlimit(10000)
def resolve():
    N = int(input())
    X = list(map(int, input().split(" ")))
    inputOrder = [{"idx": i, "value": v} for i, v in enumerate(X)]
    valueOrder = sorted(inputOrder, key=lambda x: x["value"])
    for i, v in enumerate(valueOrder):
        v["order"] = i

    for i in range(N):
        
        
        
        o = inputOrder[i]
        if o["order"] < N//2:
            print(valueOrder[N//2]["value"])
        else:
            print(valueOrder[N//2-1]["value"])
        

    
if '__main__' == __name__:
    resolve()

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

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

    X_sorted = list(X)
    X_sorted.sort()
    middle = X_sorted[(n+1)//2]
    middle_l = X_sorted[(n+1)//2-1]
    for i in range(n):
        if middle_l==middle:
            print(middle)
        else:
            if X[i]>=middle:
                print(middle_l)
            else:
                print(middle)


if __name__ == '__main__':
    main()

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

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

y = sorted(x)
ans = [y[n // 2 - 1], y[n // 2]]
for xi in x:
    if xi > ans[0]:
        print(ans[0])
    else:
        print(ans[1])

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

xs = sorted(x)
med = dict()
for i, k in enumerate(xs):
  if i < n//2:
    med[k] = xs[n//2]
  else:
    med[k] = xs[n//2 - 1]

for k in x:
  print(med[k])

Solution (Python):
a = int(input())
l = list(map(int, input().split()))

m = len(l)
lsort = sorted(l)
lmedlow = lsort[int(m/2)]
lmedhigh = lsort[int(m/2)-1]

for i in range (0, m):
	if l[i] < lmedlow:
		print(lmedlow)
	else:
		print(lmedhigh)

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

Y = sorted(X)

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

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

a_L = list(sorted(x_L))

center_l = a_L[int(n/2)-1]
center_r = a_L[int(n/2)]

for i in x_L:
    if i <= center_l:
        print(center_r)
    elif i >= center_r:
        print(center_l)

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

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

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
Y = list(enumerate(X))
Y.sort(key=lambda x:x[1])
mid = [Y[N//2-1][1], Y[N//2][1]]
ans = [-1] * N
for i, y in Y:
  if y <= mid[0]:
    ans[i] = mid[1]
  else:
    ans[i] = mid[0]

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

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

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

Solution (Python):
n = int(input())
list_A = list(map(int, input().split()))
list_S = list_A.copy()
list_S.sort()
left = list_S[n//2-1]
right = list_S[n//2]

for num in list_A:
    if num < right:
        print(right)
    if num > left:
        print(left)
    if num == right and num == left:
        print(num)

Solution (Python):
n = int(input())
xs = [int(elem) for elem in input().split()]
sorted_xs = sorted(xs)
base = sorted_xs[(n//2 - 1)]

for i in range(n):
  if xs[i] <= base:
    print(sorted_xs[n//2])
  else:
    print(base)

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

Solution (Python):
import copy
n = int(input())
x = list(map(int, input().split()))
y = copy.deepcopy(x)
y.sort()
mid_bigger = y[int(n/2)]
mid_smaller = y[int(n/2)-1]
ans = [0]*n
for i in range(0,n):
    if (x[i]<mid_bigger):
        ans[i]=mid_bigger
    elif (x[i]>mid_smaller):
        ans[i]=mid_smaller
    elif (mid_smaller == x[i]):
        ans[i] = mid_bigger
    else:
        ans[i] = mid_smaller
print(*ans, sep='\n')

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

cp = sorted(x, reverse=False)
for i in range(n):
    s = bisect.bisect_left(cp, x[i])
    if s + 1 <= n // 2:
        print(cp[n // 2])
    else:
        print(cp[(n // 2) - 1])

Solution (Python):
N = int(input())
A = list(map(int,(input().split())))
B = sorted(A)
m = B[N//2-1]
M = B[N//2]
for i in range(N):
    if A[i] >= M:
        print(m)
    else:
        print(M)

Solution (Python):
import copy
n = int(input())
x = list(map(int,input().split()))
xs = copy.deepcopy(x)
xs.sort()
l = xs[n//2-1]
r = xs[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()))

x=[]
for i in range(N):
  x.append(X[i])
x.sort()

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

Solution (Python):
import heapq
N = int(input())
A = list(map(int, input().split()))
h = []
for i, num in enumerate(A):
  heapq.heappush(h,(num, i))
sorted_h = [heapq.heappop(h) for i in range(len(h))]
B = []
for i in range(N):
  if(i < (N // 2)):
    heapq.heappush(B, (sorted_h[i][1], sorted_h[((N//2))][0]))
  else:
    heapq.heappush(B,(sorted_h[i][1], sorted_h[((N//2) - 1)][0]))
for i in range(len(B)):
  print(heapq.heappop(B)[1])

Solution (Python):

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

data = sorted(x)
under = data[n // 2 - 1]
over = data[n // 2]
for i in range(n):
    if x[i] <= under:
        print(over)
    else:
        print(under)

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

if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np

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

x = np.array(x)

y = np.sort(x)

left = y[n//2 - 1]
right = y[n//2 ]

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

Solution (Python):
import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
INF = 1 << 60
sys.setrecursionlimit(10 ** 6)


n = int(input())
x = list(map(int, input().split()))
x_sorted = sorted(x)
left = x_sorted[n // 2 - 1]
right = x_sorted[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)
k,l=y[n//2-1],y[n//2]
for i in range(n):
    if x[i]<=k:
        print(l)
    else:
        print(k)

Solution (Python):

n = int(input())

x = list(map(int, input().split()))
xs = sorted(x)
left = xs[n // 2 - 1]
right = xs[n // 2]

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

Solution (Python):
from statistics import median

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

mn = median(y[:n-1])
mx = median(y[1:])

for i in x:
  if i <= mn:
    print(mx)
  else:
    print(mn)

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

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

Solution (Python):
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):
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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):
import math
n = int(input())
x = list(map(int,input().split()))
sums = sum(x)
xsort = sorted(x,reverse=True)
temp = math.ceil((n-1)/2)
if n % 2 == 0:
    medi = xsort[temp]
else:
    medi = xsort[n//2]

medi2 = xsort[temp-1]

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

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

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

Solution (Python):
def main():
    n = int(input())
    center = (n+1)//2
    x_s = list(map(int,input().split()))
    sorted_x_s = sorted(x_s)
    center_num = sorted_x_s[center]

    for i in x_s:
        if i < center_num:
            print(sorted_x_s[center])
        else:
            print(sorted_x_s[center-1])






if __name__ == '__main__':
    main()

Solution (Python):
n, *xs = map(int, open(0).read().split())
sorted_xs = sorted(xs)
med1 = sorted_xs[n//2]
med2 = sorted_xs[n//2-1]

for x in xs:
    if x <= med2:
        print(med1)
    else:
        print(med2)

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

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

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

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

Solution (Python):
n=int(input())
x=[[int(x),i] for i,x in enumerate(input().split())]
ans=[0]*n
x.sort(key=lambda x: x[0])

for i,val in enumerate(x):
    
    pos=(n-1)//2
    if i>pos:
        ans[val[1]]=x[pos][0]
    else:
        ans[val[1]]=x[pos+1][0]
for i in ans:
    print(i)

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

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

lst2 = sorted(lst)
ans1 = lst2[n//2-1]
ans2 = lst2[n//2]

for i in lst:
    if i<=ans1:
        print(ans2)
    else:
        print(ans1)

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

large = Y[N//2-1]
small = Y[N//2]

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

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

arr = sorted(x)

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

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

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

y = sorted(x)
l = y[n//2 - 1]
r = y[n//2]

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

Solution (Python):
def main():
    n = int(input())
    num_list = list(map(int, input().split()))

    c_num_list = num_list[:]

    num_list.sort()

    for i in range(n):
        tmp = num_list[n//2]
        if c_num_list[i] >= tmp:
            print(num_list[n//2-1])
        else:
            print(num_list[n//2])
        

if __name__ == '__main__':
    main()

Solution (Python):
def resolve():
    N=int(input())
    X=list(map(int,input().split()))
    Y=sorted(X)
    l=Y[N // 2-1]
    r=Y[N//2]


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






resolve()

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

Solution (Python):
n = int(input())
x = [int(t) for t in input().split()]
d = sorted(x)
m1 = d[n//2-1]
m2 = d[n//2]

for i in range(n):
    if m1 < x[i]:
        print(m1)
    else:
        print(m2)

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

l=sortx[(N//2)-1]
r=sortx[N//2]

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

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
s_X = sorted(X)
c = s_X[-(N//2)]
c2 = s_X[-(N//2)-1]

for i in range(N):
    if X[i] < c:
        print(c)
    else:
        print(c2)

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

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

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

sort_A = sorted(A)
med_index = (n-2) // 2

for i in A:
    if i <= sort_A[med_index]:
        print(sort_A[med_index+1])
    else:
        print(sort_A[med_index])

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

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

b = sorted(a)
big = b[len(b)//2 -1]
small = b[len(b)//2]

for i in a:
    if i <= big:
        print(small)
    else:
        print(big)

Solution (Python):
import copy

def Many_Medians(n , xl):

    ans = []
    left = n // 2
    right = n // 2 - 1
    sort_xl = sorted(xl)

    for x in xl:
        if x < sort_xl[left]:
            ans.append(sort_xl[left])
        else:
            ans.append(sort_xl[right])

    return ans

def main():
    n = int(input())
    xl = list(map(int , input().split()))
    ans = Many_Medians(n, xl)
    for i in range(n):
        print(ans[i])

if __name__ == '__main__':
    main()

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

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

S = sorted(X)
ml = S[n//2-1]
mr = S[n//2]
for x in X:
  if x <= ml:
    print(mr)
  else:
    print(ml)

Solution (Python):




def main():
    N = int(input())
    X = list(map(int, input().split()))
    x = sorted(X)[N // 2 - 1:N // 2 + 1]
    for i in X:
        print(x[i <= x[0]])


if __name__ == "__main__":
    main()

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

Solution (Python):
N = int(input())
X = []
for i, x in enumerate(map(int, input().split())):
    X.append((x, i))

X.sort()
Y = [0] * N
for j, (x, i) in enumerate(X):
    Y[i] = j

mid = N / 2
l = X[N // 2 - 1][0]
r = X[N // 2][0]
ans = []
for j in Y:
    if j < mid:
        ans.append(r)
    else:
        ans.append(l)

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

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

Solution (Python):
n = int(input())
l = list(map(int,input().split()))
sorted_l = sorted(l)
left_med,right_med = sorted_l[int(n/2)-1], sorted_l[int(n/2)]

for i in l:
    if i <= left_med:
        print(right_med)
    
    else:
        print(left_med)

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

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

y = sorted(x)
mid_low = y[n//2-1]
mid_high = y[n//2]
for i in x:
    if i <= mid_low:
        print(mid_high)
    else:
        print(mid_low)

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

Solution (Python):
n=int(input())
a=[int(x) for x in input().split()]
b=sorted(a)
for x in a:
    if(x<=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_ = sorted(x.copy())
for i in range(n):
    if x[i] <= x_[n//2-1]:
        print(x_[n//2])
    else:
        print(x_[n//2-1])

Solution (Python):
n=int(input())
n//=2
l=list(map(int,input().split()))
sl=sorted(l)
m,h=sl[n-1],sl[n]
print(*[h if i<=sl[n-1] else m for i in l],sep="\n")

Solution (Python):
def solve():
    N = int(input())
    X = list(map(int, input().split()))
    
    sorted_X = sorted(X)
    mid_l = sorted_X[N // 2 - 1]
    mid_r = sorted_X[N // 2]
    
    for xi in X:
        if xi <= mid_l:
            print(mid_r)
        else:
            print(mid_l)


if __name__ == '__main__':
    solve()

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

Y = sorted(X)
c1 = Y[N//2-1]
c2 = Y[N//2]

for i in range(N):
  if X[i]<=c1:
    ans = c2
  else:
    ans = c1
  print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
aa = a[:]
sa = list(sorted(a))
upper = sa[n//2]
down = sa[(n//2)-1]
mid = n//2

for i in range(n):
  if aa[i] <= down:
    print(upper)
  else:
    print(down)

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

B = sorted(A)

median_a = B[n//2 - 1]
median_b = B[n//2]


for i in A:
    if i <= median_a:
        print(median_b)
    else:
        print(median_a)

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

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

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

for a in X:
    print(m2 if a <= m1 else m1)

Solution (Python):

def main():
    import sys
    
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    
    from itertools import combinations, permutations
    
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    

    

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

if __name__ == '__main__':
    main()

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

small = Y[N//2 - 1]
big = Y[N//2]

for x in X:
    if x <= small:
        print(big)
    elif x >= big:
        print(small)

Solution (Python):
import copy
N=int(input())
X=list(map(int,input().split()))
X2=copy.deepcopy(X)
X2.sort()
upper=X2[N//2]
downer=X2[(N-2)//2]

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

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

Solution (Python):
import sys


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


s_points = sorted(points)
x = s_points[int(N/2) - 1]
y = s_points[int(N/2)]


if x == y:
    for _ in range(N): 
        print(x)
    sys.exit()


for point in points:
    if x >= point:
        print(y)
    else:
        print(x)

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

x_sort = sorted(x)

med1_ix = n//2-1
med2_ix = n//2

med1 = x_sort[med1_ix]
med2 = x_sort[med2_ix]

for i in x:
    if i <= med1:
        print(med2)
    else:
        print(med1)

Solution (Python):

N = int(input())

ARR = [int(s) for s in input().split(" ")]

def calculate(n,arr):

    brr = []
    for index,ar in enumerate(arr):
        obj = {}
        obj.__setitem__("index",index)
        obj.__setitem__("value",arr[index])
        brr.append(obj)

    brr = sorted(brr,key=lambda x:x.get("value"))

    dict = {}

    for index,br in enumerate(brr):
        dict.__setitem__(br.get("index"),index)

    midIndexMin = (N - 1) // 2
    midIndexMax =  N // 2
    midIndexMinValue = brr[midIndexMin].get("value")
    midIndexMaxValue = brr[midIndexMax].get("value")

    for index,arr in enumerate(arr):
        m = dict.get(index)
        if m <= n // 2 - 1:
            print(midIndexMaxValue)
        else:
            print(midIndexMinValue)



calculate(N,ARR)

Solution (Python):
from statistics import median, median_low, median_high

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

m_l=median_low(l)
m_h=median_high(l)

for i in range(n):
    if l[i] <= m_l:
        print(m_h)
    elif l[i] >= m_h:
        print(m_l)

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

Solution (Python):
from copy import deepcopy

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

for i in range(N):
    if X[i] > med1:
        print(med1)
    else:
        print(med2)

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

Solution (Python):









import sys



ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    n = int(input())
    x = list(map(int,ipti().split()))
    x_sorted = sorted(x)

    med_small = x_sorted[n//2 - 1]
    med_big = x_sorted[n//2]

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

if __name__ == '__main__':
    main()

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

Y = sorted(X)
med_low = Y[N//2 - 1]
med_high = Y[N//2]

for x in X :
    if x <= med_low :
        print(med_high)
    else :
        print(med_low)

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

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

s = sorted(x)

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

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

S = sorted(X)


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

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

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

t2 = copy.copy(t1)

t2.sort()

for i in t1:
    if i <= t2[(n//2)-1]:
        print(t2[(n//2)])
    else:
        print(t2[(n//2)-1])

Solution (Python):
n = int(input())
x = [int(i) for i in input().split()]
x_ = x.copy()
x_.sort()
b1, b2 = x_[n//2-1], x_[n//2]
for xi in x:
    if xi <= b1: print(b2)
    else: print(b1)

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

y=sorted(x)

xn=y[n//2-1]
xnp=y[n//2]

for i in range(n):
    if x[i]>xn:
        print(xn)
    else:
        print(xnp)

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

if __name__=="__main__":
    main()

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

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
b = sorted(a)
l = b[n//2-1]
r = 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()))
s_x = sorted(x)
med1=s_x[n//2 - 1]
med2=s_x[n//2]

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

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

middleIdx = n//2
s1 = sorted(x)[middleIdx-1]
s2 = sorted(x)[middleIdx]

for i in range(n):
    if x[i]<=s1:
        print(s2)
    elif x[i]>=s2:
        print(s1)

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

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
sorted_X = sorted(X)
left = sorted_X[N // 2 - 1]
right = sorted_X[N // 2]

for i in range(N):
    if X[i] > left:
        print(left)
    else:
        print(right)

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

Y = sorted(X)

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

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


Y = sorted(X)
a, b = Y[n // 2 - 1], 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()))
X_sort = sorted(X)
xm1 = X_sort[n//2-1]
xm2 = X_sort[n//2]
xm = (xm1+xm2)/2
for i in range(n):
    if X[i]<xm:
        print(xm2)
    else:
        print(xm1)

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

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

mid_n = len(a)//2
right = a[mid_n]
left = a[mid_n-1]

for i in range(n):
    if right > x[i]:
        print(right)
    else:
        print(left)

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

X_sort = sorted(X)

mid_r = X_sort[N//2]
mid_l = X_sort[N//2-1]

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

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

X_sort=sorted(X)
mid_l = X_sort[N // 2 - 1]
mid_r = X_sort[N // 2]

for i in range(N):

    if (X[i] <= mid_l):
        ans = mid_r
    
    else:
        ans = mid_l
    
    print(ans)

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

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

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

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

Solution (Python):
from copy import deepcopy
import bisect
n = int(input())
dat = list(map(int, input().split()))
odat = deepcopy(dat)
dat.sort()
x1 = dat[len(dat) // 2 - 1]
x2 = dat[len(dat) // 2]
for i in range(n):
    c = odat[i]
    j = bisect.bisect_left(dat, c)
    if j < len(dat) // 2:
        print(x2)
    else:
        print(x1)

Solution (Python):
n = int(input())
X = list(map(int, input().split()))
X_mid = sorted(X)[n//2 - 1: n//2 + 1]

for i in X:
    print(X_mid[i <= X_mid[0]])

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

Solution (Python):
n=int(input())
nums=list(map(int,input().split()))
nums=list(enumerate(nums))
nums.sort(key=lambda x:x[1])

med=[0]*n
for i in range(n):
    ind=nums[i][0]
    if i<n//2:
        med[ind]=nums[n//2][1]
    else:
        med[ind]=nums[n//2-1][1]
print(*med,sep='\n')

Solution (Python):
m=int(input())//2-1
x=list(map(int,input().split()))
l,r=sorted(x)[m:m+2]
for i in x: print([l,r][i<r])

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

X_sorted = sorted(X)
if N >= 4:
  bigger = X_sorted[N//2]
  smaller = X_sorted[N//2-1]

  for _ in X:
    if _ >= bigger:
      ans = smaller
    else:
      ans = bigger
    print(ans)

else:
  for n in range(2):
    if n == 0:
      print(X[1])
    else:
      print(X[0])

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

sorted_x = sorted(x)
smaller = sorted_x[n//2 - 1]
bigger = sorted_x[n//2]

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

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

import copy
x=copy.deepcopy(X)
x.sort()
A=x[N//2-1]
B=x[N//2]

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