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

p,q=A[N//2-1:N//2+1]

for i in List:
  print(p if i>=q else q)

Solution (Python):
import bisect
n=int(input())
X=list(map(int,input().split()))
sortX = sorted(X)
ansl = sortX[n//2-1]
ansu = sortX[n//2]
for x in X:
  if bisect.bisect(sortX,x) > n//2:
    print(ansl)
  else:
    print(ansu)

Solution (Python):
import statistics
n = int(input())
X = list(map(int, input().split()))
X_ = sorted(X)
med = X_[n//2-1]
med_2 = X_[n//2]
for i in range(n):
    if X[i]>med:
        print(med)
    else:
        print(med_2)

Solution (Python):








import copy

N = int(input())



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


































































X = [[i, x] for i, x in enumerate(X)]
X = sorted(X, reverse=False, key=lambda x:x[1])
X_ranked = copy.copy(X)
X = [[l[0], i, l[1]] for i, l in enumerate(X)]
X = sorted(X, reverse=False, key=lambda x:x[0])

med = len(X) // 2

for l in X:
    if l[1] < med:
        print(X_ranked[med][1])
    else:
        print(X_ranked[med - 1][1])

Solution (Python):
import numpy as np

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

xlsorted = np.sort(xl)
m1 = xlsorted[int(N/2)-1]
m2 = xlsorted[int(N/2)]

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

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

sxs = sorted(XS)
a1 = sxs[N//2-1]
a2 = sxs[N//2]

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

Solution (Python):
N = int(input())
N_List = list(map(int,input().split()))
N_List_Sorted = sorted(N_List)
B = N_List_Sorted[N//2]
A = N_List_Sorted[N//2 - 1]

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

Solution (Python):


import collections
import itertools


def main():
    n = int(input())
    x = input_list()
    sx = list(sorted(x))
    h = n//2
    a1 = sx[h-1]
    a2 = sx[h]
    for v in x:
        if v <= a1:
            print(a2)
        else:
            print(a1)


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


def input_list_str():
    return list(map(str, input().split()))


if __name__ == "__main__":
    main()

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

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

for i in x:
  if i<=left:
    print(right)
  else:
    print(left)

Solution (Python):


def main():
    n = int(input())
    x = list(map(int, input().split()))
    ans = [0] * n
    x_sort = sorted(x)
    a = x_sort[1:n]
    a_med = a[n // 2 - 1]
    b = x_sort[0:n - 1]
    b_med = b[n // 2 - 1]
    for i in range(n):
        if x[i] < a_med:
            ans[i] = a_med
        else:
            ans[i] = b_med

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


if __name__ == "__main__":
    main()

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

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

Solution (Python):
N = int(input())
X_list = list(map(int, input().split()))
tmp = X_list.copy()

tmp.sort()
a = tmp[int(N/2)-1]
b = tmp[int(N/2)]
for i in range(N):
    if(X_list[i] <= a):
        print(b)
    else:
        print(a)

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

Solution (Python):

"""
Created on Tue Sep 22 14:57:09 2020

@author: liang
"""

N = int(input())
X = [int(x) for x in input().split()]
Y = X.copy()
Y.sort()
upper = Y[N//2]
lower = Y[N//2-1]

for i in range(N):
    if X[i] < upper:
        print(upper)
    else:
        print(lower)

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

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

sorted_x = sorted(X)

l, r = sorted_x[n//2-1], sorted_x[n//2]

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

Solution (Python):
import bisect

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

sorted_x = sorted(X)

l, r = sorted_x[n//2], sorted_x[n//2-1]

for x in X:
    if bisect.bisect_left(sorted_x, x) < n // 2:
        print(l)
    else:
        print(r)

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

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
y = x.copy()
y.sort()
z = set(x)
t1 = y[n//2-1]
t2 = y[n//2]
idx = dict([])
idx[y[0]] = 0
l = y[0]
cnt = 0
for i in y:
    if i == l:
        cnt += 1
        continue
    else:
        idx[i] = cnt
        l = i
        cnt += 1

for i in x:
    t = idx[i]
    if t<n//2:
        print(t2)
    else:
        print(t1)

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

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

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

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 range(N):
  a=A[i]
  if a<=l:
    print(r)
  else:
    print(l)

Solution (Python):
N = int(input())
X = list(map(int, input().split()))
Xs = sorted(X)
c = int(N/2)
a, b = Xs[c-1], Xs[c]
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()))
b=sorted(x)
m=(n-1+1)//2-1
for i in x:
    if i<=b[m]:print(b[m+1])
    else:print(b[m])

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

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

Solution (Python):
import copy

n = int(input())

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

XX = copy.deepcopy(X)
XX.sort()
high = XX[n//2]
low = XX[n//2-1]

for i in range(n):
    if high == low:
        print(high)
        continue
    if X[i] < high:
        print(high)
    else:
        print(low)

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

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

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

def main(n,x):
    y = sorted(x)
    a,b = y[(n-1)//2],y[(n-1)//2+1]
    for i in x:
        if i>a:
            print(a)
        else:
            print(b)

if __name__=="__main__":
    n,x = getval()
    main(n,x)

Solution (Python):
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    import statistics
    n = i_input()
    l = i_list()
    ml = min(l)
    Ml = max(l)
    ol = statistics.median(l)

    L = l.copy()

    L.remove(ml)
    pol = statistics.median(L)
    L.append(ml)

    L.remove(Ml)
    mol = statistics.median(L)
    L.append(Ml)

    ans = []

    for i in l:
        if i >= ol:
            ans.append(mol)
        else:
            ans.append(pol)

    for i in ans:
        print(i)



if __name__=="__main__":
    main()

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

m1=Y[N//2-1]
m2=Y[N//2]

medians = [m2 if x < m2 else m1 for x in X]
print('\n'.join(map(str,medians)))

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

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

for x in xx:
  if x <= a:
    print(b)
  elif x >= b:
    print(a)

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

Solution (Python):
N=int(input())
x=list(map(int,input().split()))
sort_dict={}
count=0
from collections import deque

_x = deque()
for i in sorted(enumerate(x), key=lambda x:x[1]):
    sort_dict[i[0]]=count
    _x.append(i[1])
    count+=1
_x=list(_x)

cut=N//2-1

for i in range(N):
    
    
    
    sort_idx=sort_dict[i]
    if sort_idx<=cut:
        print(_x[cut+1])
    else:
        print(_x[cut])

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

Solution (Python):
import sys



def input():
    return sys.stdin.readline().rstrip()


def main():
    N=int(input())
    A=list(map(int,input().split()))
    AS =sorted(A)
    right = AS[N//2]
    left = AS[N//2 -1]
    for a in A:
        if a<=left:
            print(right)
        else:
            print(left)




if __name__ == "__main__":
    main()

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

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

Solution (Python):
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right 
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x):
        self.setdefault(x,0)
        self[x] += 1

N,X = ilint()
L = [(i,X[i]) for i in range(N)]
L.sort(key=lambda x:x[1])
B1,B2 = L[N//2-1][1],L[N//2][1]
ans = [B1]*N
for i in range(N//2):
    ans[L[i][0]] = B2
lprint(ans)

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

    median1 = x_sorted_lst[n // 2 - 1]
    median2 = x_sorted_lst[n // 2]

    if median1 == median2:
        lst = [median1] * n

    else:
        lst = []
        for i in range(n):
            x = x_lst[i]

            if x <= median1:
                lst.append(median2)
            elif median2 <= x:
                lst.append(median1)

    for i in range(n):
        print(lst[i])


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
s = list(sorted(a))
ind = {}
for i in range(N):
    if s[i] not in ind:
        ind[s[i]] = i
for i in range(N):
    if ind[a[i]] < N//2:
        print(s[N//2])
    else:
        print(s[N//2-1])

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

pivots = (sorted(a)[n//2-1], sorted(a)[n//2])

for el in a:
    if el <= pivots[0]:
        print(pivots[1])
    else:
        print(pivots[0])

Solution (Python):
n=int(input())
x=list(map(int, input().split()))
y=sorted(x)
a=y[n//2-1]
b=y[n//2]
if a==b:
  for _ in range(n): print(a)
else:
  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_sorted = sorted(x)
med_low = x_sorted[(n // 2) - 1]
med_upper = x_sorted[(n // 2)]

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

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

mid_ls = [sort_X[N//2-1],sort_X[N//2]]

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

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

for i in range(n):
    x[i] = (x[i], i)

x.sort()

answers = [x[n//2 - 1][0]] * n

ans = x[n//2][0]
for i in range(n//2):
    answers[x[i][1]] = ans

for i in answers:
    print(i)

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

for i in range(n):
    x[i] = (x[i], i)

x.sort()

answers = [x[n//2 - 1][0]] * n

ans = x[n//2][0]
for i in range(n//2):
    answers[x[i][1]] = ans

for i in answers:
    print(i)

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

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

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

Solution (Python):

N = int(input())
X = list(map(int,input().split()))
Xsrt = sorted(X,reverse = False)
XL = set(Xsrt[:N//2])
XR = set(Xsrt[N//2:])

ans = []
for x in X:
    if x in XR:
        ans.append(Xsrt[N//2-1])
    elif x in XL:
        ans.append(Xsrt[N//2])
for a in  ans:
    print(a)

Solution (Python):
N = int(input())
Xls = list(map(int,input().split()))
X2ls = sorted(Xls)
M1 = X2ls[N//2-1]
M2 = X2ls[N//2]
lsans = []
for i in range(N):
    if Xls[i] <= M1:
        M = M2
    else:
        M = M1
    lsans.append(M)
for i in lsans:
    print(i)

Solution (Python):
from copy import *

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

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] <= B:
    print(A)
  else:
    print(B)

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())
a=[int(i) for i in input().split()]

b=a[:]
a.sort()

one=a[n//2-1]
two=a[n//2]

def get_median(i):
    if b[i]<=one:
        return two
    return one

for i in range(n):
	print(get_median(i))

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

c = sorted(b, reverse=True)

m = int(a / 2) - 1
anslist = [0] * a
for i, data in enumerate(b):
    if c[m] > data:
        anslist[i] = c[m]
    elif c[m] <= data:
        anslist[i] = c[m + 1]
        
for j in range(a):
    print(anslist[j])

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

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()))
s_x = sorted(x)
small_ans = s_x[n//2 - 1]
large_ans = s_x[n//2]
for i in range(n):
    if x[i] < large_ans:
        print(large_ans)
    elif x[i] > small_ans:
        print(small_ans)
    else:
        print(small_ans)

Solution (Python):
import copy

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

x = copy.deepcopy(X)
x.sort()

x1 = x[N // 2 - 1]
x2 = x[N // 2]

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

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

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

Solution (Python):
'''
Created on 2020/08/29

@author: harurun
'''
def main():
  import copy
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N=int(pin())
  X=list(map(int,pin().split()))
  t=(N+1)//2
  Y=sorted(X)
  ans1=Y[t-1]
  ans2=Y[t]
  median=ans1+ans2
  for i in range(N):
    s=X[i]
    if s==ans1:
      print(ans2)
    elif s==ans2:
      print(ans1)
    elif  2*s<median:
      print(ans2)
    elif 2*s>median:
      print(ans1)
  return 

main()

Solution (Python):


import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N = int(readline())
X = list(map(int, readline().split()))
X_sorted = sorted(X)


small, large = X_sorted[(N-1)//2], X_sorted[(N+1)//2]

for x in X:
    if x <= small:
        print(large)
    else:
        print(small)

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
x_sort = sorted(x)
half_l = x_sort[(n-1)//2]
half_r = x_sort[(n)//2]

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

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

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

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

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

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

med_low = s[n//2 - 1]
med_high = s[n//2]

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

Solution (Python):
def main():
    n = int(input())
    x = [int(xn) for xn in input().split()]
    x_sorted = sorted(x)
    idx_median = n // 2
    median_low = x_sorted[idx_median - 1]
    median_high = x_sorted[idx_median]
    for xn in x:
        print(median_high if xn <= median_low else median_low)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    n = int(input())
    x = [int(xn) for xn in input().split()]
    x_sorted = sorted(x)
    idx_median = n // 2
    median_low = x_sorted[idx_median - 1]
    median_high = x_sorted[idx_median]
    for xn in x:
        print(median_high if xn <= median_low else median_low)


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
ans=sorted(x)
ans2=ans[n//2-1]
ans1=ans[n//2]

for i in range(n):
  if x[i]>=ans[n//2]:
    print(ans2)
  else:
    print(ans1)

Solution (Python):



from fractions import gcd
from itertools import combinations,permutations,accumulate, product 

from collections import deque,defaultdict,Counter
import decimal
import re
import math















import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7


from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
n = I()
X = readInts()
nya = sorted(X)
m1 = nya[n//2-1]
m2 = nya[n//2]
for x in X:
    if x <= m1:
        print(m2)
    else:
        print(m1)

Solution (Python):
N, *X = map(int, open(0).read().split())
sorted_X = sorted(X)
median_l = sorted_X[N // 2 - 1]
median_r = sorted_X[N // 2]

for x in X:
    if x < median_l:
        print(median_r)
    elif x == median_l:
        print(median_r)
    elif x == median_r:
        print(median_l)
    else:
        print(median_l)

Solution (Python):
import copy
N = int(input())
X = list(map(int, input().split()))
tmp_X = copy.deepcopy(X)
tmp_X.sort()
m1 = tmp_X[N // 2]
m2 = tmp_X[N // 2 - 1]
for x in X:
    if x < m1:
        print(m1)
    else:
        print(m2)

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

Solution (Python):
import copy
N = int(input())
X = list(map(int, input().split()))
Xsort = copy.copy(X)
Xsort.sort()
centerR = Xsort[N//2]
centerL = Xsort[N//2-1]
for i in range(N):
    if X[i] >= centerR:
        print(centerL)
    else:
        print(centerR)

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

Solution (Python):
from copy import copy
n, *x = map(int, open(0).read().split())
a = []
for i, v in enumerate(x):
    a.append((v, i))
a.sort()


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

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

 
 
def main():
    N = int(input().strip())
    X_list = [int(i) for i in input().strip().split()]
    sorted_x = sorted(X_list)
 
    left = sorted_x[(N // 2)-1]
    right = sorted_x[N // 2]
    for x in X_list:
        if x <= left:
            print(right)
        else:
            print(left)
 
 
if __name__ == "__main__":
    main()

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

import copy
Y = copy.copy(X)

L = []
U = []
X.sort()
for i in range(n):
    if i < n//2:
        L.append(X[i])
    else:
        U.append(X[i])



L_ = set(L)
U_ = set(U)

ans = [0]*n
for i, y in enumerate(Y):
    if y in L_:
        ans[i] = U[0]
    else:
        ans[i] = L[-1]
print(*ans, sep='\n')

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
X.insert(0,0)
A = sorted(X[:])
a = A[N//2]
b = A[N//2+1]
for i in range(1,N+1):
    if X[i]>a:
        print(a)
    else:
        print(b)

Solution (Python):
n = int(input())
xl = list(map(int, input().split()))
xs = xl[:]
xs.sort()
med1 = xs[n//2-1]
med2 = xs[n//2]

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inl = lambda: [int(x) for x in sys.stdin.readline().split()]
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


def solve():
    n = ini()
    x = inl()
    y = sorted(x)

    p = y[n // 2 - 1]
    q = y[n // 2]

    for i in range(n):
        if x[i] < q:
            print(q)
        else:
            print(p)


solve()

Solution (Python):
from decimal import Decimal

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

y = x.copy()

y.sort()

m1 = y[n//2]
m2 = y[n//2 - 1]
m = Decimal(m1 + m2) / Decimal(2) 


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

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


if __name__ == '__main__':
    main()

Solution (Python):
import copy

def main():
	N = int(input())
	X = [int(x) for x in input().split(" ")]
	sortedX = copy.deepcopy(X)
	sortedX.sort()
	cand = [sortedX[int(N / 2) - 1], sortedX[int(N / 2)]]

	for xi in X:
		if xi <= cand[0]:
			print(cand[1])
		else:
			print(cand[0])

main()

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

sort = sorted(lst)
medi1 = sort[n//2-1]
medi2 = sort[n//2]
    
for i in range(n):
  if lst[i] <= medi1:
    print(medi2)
  else:
    print(medi1)

Solution (Python):
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial

from functools import reduce
from pprint import pprint
from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

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

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]







n = I()
x = RI()

a = sorted(x)
M = a[n//2]
m = a[n//2-1]

for i in range(n):
    if x[i]<=m:
        print(M)
    else:
        print(m)
exit()

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

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

Solution (Python):


import numpy as np


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

median = np.median(x)
x_sorted = sorted(x)

index = len(x)//2-1

for i in x:
    if i == median:
        print(i)
    elif i < median:
        print(x_sorted[index+1])
    else:
        print(x_sorted[index])

Solution (Python):
import sys
import math


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())


n = inint()
X = inintl()

X_sorted = sorted(X)

a, b = X_sorted[n//2-1],X_sorted[n//2]

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

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

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
y = sorted(x)
index = n//2

for i in range(n):
  print(y[-index] if x[i]<y[index] else y[-index-1])

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

Solution (Python):
import statistics

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

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

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

Solution (Python):
import numpy
N = int(input())
X = [int(x) for x in input().split()]
S = sorted(X)
m0 = numpy.median(S[:-1])
m1 = numpy.median(S[1:])

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

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

x_sort = sorted(x)
lenth = len(x)
low = x_sort[int(lenth/2)-1]
high = x_sort[int(lenth/2)]

for y in x:
    if y <= low:
        print(high)
    else:
        print(low)

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

Solution (Python):
N=int(input())
*X,=map(int,input().split())
s=sorted(X)

t1=s[N//2-1]
t2=s[N//2]

for x in X:
    if x<=t1:
        print(t2)
    else:
        print(t1)

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

x = list(enumerate(X))

x.sort(key=lambda x: x[1])
A = list(map(lambda x: x[1], x[n//2-1:n//2+1]))

for v in X:
    if v <= A[0]:
        print(A[1])
    else:
        print(A[0])

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

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

res1 = x[n//2]
res2 = x[n//2 -1]

for i in range(n):
  if X[i] >= res1:
    print(res2)
  elif X[i] <= res2:
    print(res1)