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()))
X_sorted = sorted(X)
pre_med_index = (N // 2) - 1
pos_med_index = N // 2
import bisect

for i in range(N):
    if X[i] <= X_sorted[pre_med_index]:
        print(X_sorted[pos_med_index])
    else:
        print(X_sorted[pre_med_index])

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

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

X.sort()

right = int(N // 2)
left = right - 1

med = (X[left] + X[right]) / 2

for x in org:
    if x >= med:
        print(X[left])
    else:
        print(X[right])

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

a = Y[(N-1)//2]
b = Y[(N+1)//2]

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

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

Solution (Python):

import sys 
import copy
input = sys.stdin.readline

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

l = xx[(n-1)//2]
r = xx[n//2]
mid = (l+r)/2

for i in range(n):
    if x[i] >= mid:
        print(l)
    else:
        print(r)

Solution (Python):
import math
import statistics

n = int(input())
xL = list(map(int, input().split(" ")))

xL2 = []
for i in range(n):
    xL2.append([i, xL[i]])
xL2 = sorted(xL2, key=lambda x: x[1])

if n % 2 == 0:
    center = n // 2
    centers = [xL2[center - 1], xL2[center]]
    for i in range(n):
        if i == centers[0][0] or i == centers[1][0]:
            print(statistics.median(xL[:i] + xL[i + 1:]))
        else:
            if centers[0][1] < xL[i]:
                print(centers[0][1])
            else:
                print(centers[1][1])
else:
    center = n // 2
    centers = [xL2[center - 1], xL2[center], xL2[center + 1]]
    for i in range(n):
        if i == centers[0][0] or i == centers[1][0] or i == centers[2][0]:
            print(statistics.median(xL[:i] + xL[i + 1:]))
        else:
            if centers[0][1] < xL[i]:
                print((centers[0][1] + centers[1][1]) / 2)
            else:
                print((centers[1][1] + centers[2][1]) / 2)

Solution (Python):
import numpy as np

N = int(input())
X = list(map(int, input().split()))
Y = sorted(X)
x = np.median(X)
index = N // 2
m1 = Y[index]
m2 = Y[index - 1]

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

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

Solution (Python):
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    X = nl()
    X_s = sorted(X)
    mid = X_s[n // 2]
    del_mid = (X_s[:n // 2] + X_s[n // 2 + 1:])[(n - 1) // 2]
    for x in X:
        if x < mid:
            print(mid)
        elif x > mid:
            print(X_s[n // 2 - 1])
        else:
            print(del_mid)


if __name__ == '__main__':
    main()

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

x.sort(key=lambda x:x[1])
for i in range(n):
  print(x[i][2])

Solution (Python):
n,*a=map(int,open(0).read().split())

b=sorted(a)
med=b[n//2]
medsmall=b[n//2-1]

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

Solution (Python):
import copy

n=int(input())

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

x2 = copy.copy(x)

x2.sort()

ans = [x2[n//2-1],x2[n//2]]

for xx in x:
    if xx <= ans[0]:
        print(ans[1])
    else:
        print(ans[0])

Solution (Python):
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n = k()
x = l()
p=sorted(x)
mid = len(p)//2
for i in x:
    a = bisect.bisect(p,i)
    if a <= mid:
        print(p[mid])
    else:
        print(p[mid-1])

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

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

nums = sorted(x)
m1 = n//2-1
m2 = n//2
for i in range(n):
  if x[i] <= nums[m1]: print(nums[m2])
  elif nums[m2] <= x[i]: print(nums[m1])

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

a = x2[n//2 - 1]
b = x2[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()))
y = sorted(x)

m_index = n//2-1
m = y[m_index]

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

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *X = map(int, read().split())

    X = [(x, i) for i, x in enumerate(X)]

    X.sort()

    ans = [0] * N
    for i, (x, j) in enumerate(X):
        if i < N // 2:
            ans[j] = X[N // 2][0]
        else:
            ans[j] = X[N // 2 - 1][0]

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


if __name__ == '__main__':
    main()

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

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

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

y = sorted([(a, i) for i, a in enumerate(x)])
x1 = y[n // 2 - 1][0]
x2 = y[n // 2][0]

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

for i in range(n):
    if x[i][1] < n // 2:
        print(x2)
    else:
        print(x1)

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

Y = sorted(X[:])
b_median = Y[N // 2 - 1]
a_median = Y[N // 2]

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

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

first_harf = Y[:int(N/2)]
second_harf = Y[int(N/2):]

for i in range(N):
    if X[i] <= first_harf[-1]:
        print(second_harf[0])
    else:
        print(first_harf[-1])

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

l = sorted(x)

m1 = l[n // 2 - 1]
m2 = l[n // 2]

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

Solution (Python):
import sys

N = int(sys.stdin.readline())
X = list(map(int, sys.stdin.readline().split()))

sort = sorted(X)
first = sort[N//2 - 1]
second = sort[N//2]

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

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

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

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

x=sorted(y)
c=n//2

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

for i in range(n):
  if y[i]>=ans2:
    print(ans1)
  else:
    print(ans2)

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

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

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()))
X2=sorted(enumerate(X),key=lambda x:x[1])
X3=sorted(enumerate(X2),key=lambda x:x[1][0])
ans=[0]*N
for i in range(N):
  if X3[i][0] < N//2:print(X2[N//2][1])
  else:print(X2[N//2-1][1])

Solution (Python):
import sys
input = sys.stdin.readline
import numpy as np
from numba import njit


def read():
    N = int(input().strip())
    X = np.fromstring(input().strip(), dtype=np.int32, sep=" ")
    return N, X


@njit
def solve(N, X):
    A = np.argsort(X)
    l, r = X[A[N//2-1]], X[A[N//2]]
    mid = (l + r) / 2
    for i in range(N):
        if X[i] <= mid:
            print(r)
        else:
            print(l)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

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


def read():
    N = int(input().strip())
    X = np.fromstring(input().strip(), dtype=np.int32, sep=" ")
    return N, X


def solve(N, X):
    A = np.argsort(X)
    l, r = X[A[N//2-1]], X[A[N//2]]
    mid = (l + r) / 2
    for x in X:
        if x <= mid:
            print(r)
        else:
            print(l)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Solution (Python):





import math
import fractions
import sys
import bisect
import heapq  
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr



def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod



def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

n = ir()
xx = lr()
x = sorted(xx)
min_m = x[n//2-1]
max_m = x[n//2]
for num in xx:
    if num <= x[n//2-1]:
        print(max_m)
    else:
        print(min_m)

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

Solution (Python):
N = int(input())
X = list(map(int,input().split()))
Y = sorted(X)
big,small = Y[N//2],Y[N//2-1]
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)
M2 = Y[N//2]
M1 = Y[N//2-1]
for i in range(N):
    if X[i]<=M1:
        print(M2)
    else:
        print(M1)

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

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

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

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

Solution (Python):
n = int(input())
if n == 2:
  a, b = map(str,input().split())
  print(b + " " + a)
else:
  L = list(map(int, input().split()))
  M = sorted(L)
  c = (n + 1) // 2 - 1
  a = M[c + 1]
  b = M[c]
  for l in L:
    if l> b:
      print(b)
    else:
      print(a)

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

lis = sorted(x)
median = lis[int(n/2)]
median2 = lis[int((n-2)/2)]

for i in range(n):
    if x[i] < median:
        print(median)
    else:
        print(median2)

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

Solution (Python):
def main():
    n=int(input())
    x=list(map(int,input().split()))
    sx = sorted(x)
    lx = len(x)//2
    m = sx[lx]
    _m = sx[lx-1] if 0 < m-1 else sx[0]
    for i in x:
        print(m if i<m else _m)

if __name__ == "__main__":
    main()

Solution (Python):

n, *x = map(int, open(0).read().split())
s = sorted(x)
m1 = s[n // 2 - 1]
m2 = s[n // 2]
for i in x:
    if i < m2:
        print(m2)
    else:
        print(m1)

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

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

Solution (Python):
from statistics import *
N = int(input())
X = list(map(int,input().split()))
Y = sorted(X)
m = median(X)

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

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

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

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
y=sorted(x)
ans1=y[(n//2)-1]
ans2=y[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()))

x_sort = sorted(x[:])
a,b = x_sort[n//2 - 1], x_sort[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 = sorted(X)
m = N // 2
for x in X:
    if x >= _X[m]:
        print(_X[m - 1])
    else:
        print(_X[m])

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

x = [(j, i) for i, j in enumerate(x)]
x.sort(key=itemgetter(0))
medi1 = x[len(x)//2][0]
medi2 = x[len(x)//2-1][0]
ans = [0]*n
for i in range(len(x)):
    if i<len(x)//2:
        ans[x[i][1]] = medi1
    else:
        ans[x[i][1]] = medi2

for a in ans:
    print(a)

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

sor = sorted(X)
l = sor[N//2-1]
r = sor[N//2]
for i in range(0,N,1):
    print(l if X[i]>=r else r)

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

alpha=Y[N//2-1]
beta=Y[N//2]

S=[0]*N
for k in range(N):
    x=X[k]
    if x<=alpha:
        S[k]=beta
    else:
        S[k]=alpha

print("\n".join(map(str,S)))

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

Solution (Python):
import sys
import itertools

import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines



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

A = sorted(X)

med1 = A[N // 2 - 1] 
med2 = A[N // 2]

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

Solution (Python):
N = int(input())
X = [int(T) for T in input().split()]
SortX = sorted(X)
MedL = SortX[(N//2)-1]
MedR = SortX[(N//2)]
Disp = [0]*N
for T in range(0,N):
    if X[T]<=MedL:
        Disp[T] = str(MedR)
    else:
        Disp[T] = str(MedL)
print('\n'.join(Disp))

Solution (Python):
N = int(input())
X = [int(T) for T in input().split()]
SortX = sorted(X)
MedL  = SortX[(N//2)-1]
MedR  = SortX[(N//2)]
if MedL==MedR:
    Disp = [str(MedL)]*N
    print('\n'.join(Disp))
else:
    Disp = [0]*N
    for T in range(0,N):
        if X[T] <=MedL:
            Disp[T] = str(MedR)
        else:
            Disp[T] = str(MedL)
    print('\n'.join(Disp))

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

x_sorted = sorted(x)
lower_med = statistics.median(x_sorted[1:])
upper_med = statistics.median(x_sorted[:len(x)-1])

median = statistics.median(x)

for i in range(n):
    if x[i] < median:
        print(lower_med)
    else:
        print(upper_med)

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

Solution (Python):
import bisect

N = int(input())
X = list(int(x) for x in input().split())
Y = sorted(X)
m1 = Y[N//2-1]
m2 = Y[N//2]

for x in X:
    if bisect.bisect_left(Y, x) > N//2-1:
        print(m1)
    else:
        print(m2)

Solution (Python):

import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect

sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


N = z()
X = zz()
orig_X = X[:]
index = list(range(N))

X, index = zip(*sorted(zip(X, index)))


small_median = X[N//2 - 1]
big_median = X[N//2]



for i in range(N):
    if(orig_X[i] > small_median):
        pass
        print(small_median)
    else:
        pass
        print(big_median)

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

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

Solution (Python):


import copy
import random
import bisect 
import fractions 
import math
import sys
import collections
from decimal import Decimal 

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

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
X = LI()

X_sort = sorted(X)


mid = X_sort[N // 2]

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

Solution (Python):

import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd





def solve():
    n = int(input())
    b = [int(x) for x in input().split()]
    a = []
    for i in range(n):
        a.append((b[i], i))
    a.sort()
    ans = [0] * n
    m = n // 2


    for i in range(n):
        j = a[i][1]
        if i < m:
            ans[j] = (a[m][0])
        else:
            ans[j] = (a[m-1][0])

    for e in ans:
        print(e)


t = 1

for case in range(1,t+1):
    ans = solve()


"""

2 3 4 4
3 4 4
2 3 4
2 3 4
2 4 4


"""

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

als = list(sorted(al))

x = als[n//2]
y = als[n//2-1]

for i in range(n):
    z = al[i]
    if z <=y:
        print(x)
    else:
        print(y)

Solution (Python):
def resolve():
    '''
    code here
    '''
    N = int(input())
    Xs = [int(item) for item in input().split()]

    sorted_xs = sorted(Xs)

    for item in Xs:
        if item <= sorted_xs[(N-1)//2]:
            print(sorted_xs[N//2])
        else:
            print(sorted_xs[(N-1)//2])

if __name__ == "__main__":
    resolve()

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

sortX = sorted(X)

lB = sortX[n//2-1]
rB = sortX[n//2]

for x in X:
    if x <= lB:
        print(rB)
    else:
        print(lB)

Solution (Python):






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





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

Solution (Python):
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n = readInt()
t = readInts()
x = []
for i in range(n):
	x.append([i,t[i]])
x = sorted(x, key=lambda x: x[1])
ans = [-1]*n
for i in range(len(x)):
	if i<n//2:
		ans[x[i][0]]=x[n//2][1]
	else:
		ans[x[i][0]]=x[n//2-1][1]

for i in ans:
	print(i,end=" ")

Solution (Python):
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from copy import deepcopy

def main():
    n, *x = map(int, read().split())
    if n == 2:
        print(x[1])
        print(x[0])
        sys.exit()

    x2 = deepcopy(x)
    x2.sort()
    r1 = x2[n//2-1]
    r2 = x2[n//2]
    for xe in x:
        if xe > r1:
            print(r1)
        else:
            print(r2)
if __name__ == '__main__':
    main()

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

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

l = sorted(x)
m1 = l[(n-1)//2]
m2 = l[(n-1)//2+1]
for i in x:
  if i <= m1: print(m2)
  else: print(m1)

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

Solution (Python):
N=int(input())
X=list(map(int,input().split()))
Z=sorted(X)
left=Z[N//2-1]
right=Z[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()))
xs = sorted(x)

default = (n+1)//2

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

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

X_dict={}
X_=X.copy()
X_.sort()
for x_idx,x in enumerate(X_):
    X_dict[x]=x_idx

median_idx = N//2-1
for x in X:


    x_sort_idx=X_dict[x]
    if median_idx < x_sort_idx:
        ans = X_[median_idx]
    else:
        ans = X_[median_idx+1]
    print(ans)

Solution (Python):
import copy
N = int(input())
X = list(map(int, input().split()))
x = copy.copy(X)
x.sort()
left = x[N//2-1]
right = x[N//2]

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

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

y = sorted(X)

a = y[N//2-1]
b = y[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)
h=n//2
a1=y[h]
a2=y[h-1]
for i in range(n):
    if x[i]<a1:
        print(a1)
    else:
        print(a2)

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

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

Solution (Python):
n = int(input())
x = list(map(int, input().split()))
pivot = n // 2
l = []
for i in range(n):
    l.append([x[i], i])
l.sort()
r = []
for i in range(n):
    l[i].append(i)
    l[i] = l[i][1:]
    r.append([l[i][1], l[i][0]])
d1 = dict(l)
d2 = dict(r)
for i in range(n):
    if d1[i] >= pivot:
        print(x[d2[pivot-1]])
    else:
        print(x[d2[pivot]])

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

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

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

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

a=n//2
p=sorted_lst[a-1]
q=sorted_lst[a]

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

Solution (Python):
n = int(input())
x_1 = list(map(int, input().split()))
x_2 = sorted(x_1)
median_1 = x_2[n//2-1]
median_2 = x_2[n//2]
for v in x_1:
    if v <= median_1:
        print(median_2)
    else:
        print(median_1)

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

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

N = int(input())
X =list(map(int,input().split()))
sX = sorted(X)
med_s = sX[((N-1)+1)//2-1]
med_b = sX[((N-1)+1)//2]
ave_med = (med_s+med_b)/2

for i in range(N):
    if X[i] <= ave_med:
        print(med_b)
    else:
        print(med_s)

Solution (Python):
import sys
from bisect import bisect_left
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    X = list(map(int, input().split()))
    Y = [(x, i) for i, x in enumerate(X)]
    Y.sort()

    for i, x in enumerate(X):
        idx = bisect_left(Y, (x, i))
        if idx < N // 2:
            print(Y[N//2][0])
        else:
            print(Y[N//2-1][0])


if __name__ == "__main__":
    main()

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

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

Solution (Python):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N = in_n()
    X = in_nl()
    X = [(num, i) for i, num in enumerate(X)]

    ans = [0] * N
    X.sort()
    for i in range(N):
        _, j = X[i]
        if i < N // 2:
            ans[j] = X[N // 2][0]
        else:
            ans[j] = X[N // 2 - 1][0]

    print('\n'.join(map(str, ans)))


if __name__ == '__main__':
    main()

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

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

Solution (Python):
import copy
n = int(input())
lst = list(map(int, input().split()))
clst = sorted(copy.deepcopy(lst))
lmed = clst[n // 2 - 1]
rmed = clst[n // 2]
for i in range(n):
  if lst[i] <= lmed:
    print(rmed)
  else:
    print(lmed)

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

newx=sorted(x)

lower_med=newx[n//2-1]
higher_med=newx[n//2]

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

Solution (Python):
import bisect,copy,heapq,itertools,string
from collections import *
from math import *
import sys
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
x = LIST()
y = sorted(x)

b0 = y[n//2-1]
b1 = y[n//2]
for a in x:
  if a<=b0:
    print(b1)
  else:
    print(b0)

Solution (Python):
def main():
    n = int(input())
    xs = list(map(int, input().split()))
    xs_sorted = sorted(xs)
    mid_n2, mid_n1 = (n+1)//2, (n-1)//2
    for x in xs:
        if x == xs_sorted[mid_n1]:
            print(xs_sorted[mid_n2])
        elif x == xs_sorted[mid_n2]:
            print(xs_sorted[mid_n1])
        elif x < xs_sorted[mid_n1]:
            print(xs_sorted[mid_n2])
        else:
            print(xs_sorted[mid_n1])


if __name__ == "__main__":
    main()