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):
def main():
    N = int(input())
    *a, = map(int, input().split())

    *b, = sorted(a)

    h = N // 2
    L = b[h - 1]
    R = b[h]

    for x in a:
        if x <= L:
            print(R)
        else:
            print(L)


if __name__ == '__main__':
    main()

Solution (Python):

import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

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

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

Y=sorted(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):
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):
import sys
import bisect
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


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


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


def main():
    N = readint()
    X = list(readnums())
    xs = sorted(X)
    for i in X:
        d = bisect.bisect_left(xs, i)
        if d >= N // 2:
            print(xs[N // 2 - 1])
        else:
            print(xs[N // 2])


if __name__ == "__main__":
    main()

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

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

Solution (Python):
import sys













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





def main():
    n = ni()
    d = na()

    tmp_d = sorted(d)

    front = tmp_d[n//2-1]
    rear = tmp_d[n//2]

    for num in d:

        if front>=num:
            print(rear)
        else:
            print(front)


if __name__ == '__main__':
    main()

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

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

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

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

Solution (Python):
n = int(input())
x = [(i, int(j)) for i, j in enumerate(input().split())]
x.sort(key=lambda x:x[1])
l = x[n//2-1][1]
r = x[n//2][1]
ans = [None]*n
for ind, (i, j) in enumerate(x):
    if ind<n//2:
        ans[i] = r
    else:
        ans[i] = l

for i in ans:
    print(i)

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

mid1=x[N//2-1]
mid2=x[N//2]

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

Solution (Python):
import sys
import bisect
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    X = list(map(int, input().split()))
    X_s = sorted(X)

    for i in range(n):
        idx = bisect.bisect_left(X_s, X[i])
        if idx <= n // 2 - 1:
            print(X_s[n // 2])
        else:
            print(X_s[n // 2 - 1])


if __name__ == '__main__':
    resolve()

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True


def search(arr, num):
    l = 0
    r = len(arr) - 1
    while r - l > 1:
        c = (r + l) // 2
        if arr[c] > num:
            r = c
        elif arr[c] < num:
            l = c
        else:
            r = c
            l = c
    if arr[l] == num:
        return l
    elif arr[r] == num:
        return r
    else:
        return -1

n = INT()
x = LIST()
arr1 = sorted(list(set(x)))
arr2 = Counter(x)
arr3 = [-1 for _ in range(len(arr1))]
for i in range(len(arr1)):
    arr3[i] = arr2[arr1[i]]
    arr3[i] += arr3[i - 1] if i > 0 else 0
med = n // 2 - 1
y = sorted(x)
mdx_mn = y[med]
mdx_mx = y[med + 1]

for xx in x:
    idx = search(arr1, xx)
    if idx == 0:
        print(mdx_mx)
        continue
    mn = arr3[idx - 1]
    mx = arr3[idx]
    if med < mn:
        print(mdx_mn)
    else:
        print(mdx_mx)

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

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

if __name__ == '__main__':
    main()

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

Solution (Python):
n = int(input())
X = list(map(int, input().split()))
X_sort = sorted(X)
L, R = X_sort[n//2-1], X_sort[n//2]
M = (L+R)/2
for x in X:
    if x < M:
        print(R)
    else:
        print(L)

Solution (Python):
from copy import deepcopy


def main():
    n = int(input())
    x = list(map(int, input().split()))
    y = deepcopy(x)
    y.sort()
    median = y[n // 2]
    next_median = y[n // 2 - 1]
    for xx in x:
        if xx >= median:
            print(next_median)
        else:
            print(median)


if __name__ == '__main__':
    main()

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

X_sort = sorted(X)

tmp_m = X_sort[N // 2 - 1]
tmp_p = X_sort[N // 2]

for x in X:
    if x <=tmp_m:
        print (tmp_p)
    else:
        print (tmp_m)

Solution (Python):
n = int(input())
x = [(ind, int(i)) for ind, i in enumerate(input().split())]
x.sort(key=lambda x:x[1])
ans = [None]*n
l = x[n//2-1][1]
r = x[n//2][1]
for ind, (i, _) in enumerate(x):
    if ind<n//2:
        ans[i] = r
    else:
        ans[i] = l
for i in ans:
    print(i)

Solution (Python):
from sys import stdin
def main():
    
    readline=stdin.readline
    N=int(readline())
    A=list(map(int,readline().split()))

    B=sorted(A)
    left=B[N//2-1]
    right=B[N//2]

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

if __name__=="__main__":
    main()

Solution (Python):
import statistics

n = int(input())
li = list(map(int,input().split()))
median_low = statistics.median_low(li)
median_high = statistics.median_high(li)

for i in li:
    if i <= median_low:
        print(median_high)
    else:
        print(median_low)

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

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

A_sorted = sorted(As)
med1 = A_sorted[N//2-1]
med2 = A_sorted[N//2]

for A in As:
  if A <= med1:
    print(med2)
  else:
    print(med1)

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

sorted_x = sorted(x)

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

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

Solution (Python):
n = int(input())
xl = list(map(int, input().split()))
xl_s = sorted(xl)

l = xl_s[n//2-1]
r = xl_s[n//2]

for x in xl:
    if x >= r:
        print(l)
    else:
        print(r)

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

y = sorted(x)
mid1 = y[(n + 1) // 2]
mid2 = y[(n - 1) // 2]

for i in range(n):
    if mid1 == mid2:
        ans = mid1
    elif x[i] >= mid1:
        ans = mid2
    elif x[i] <= mid2:
        ans = mid1

    print(ans)

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

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

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

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

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

Solution (Python):
import math
n = int(input())
a = [int(x) for x in input().split()]
b = sorted(a)
if n%2:
  k1 = (b[n//2-1]+b[n//2])/2
  k2 = (b[n//2+1]+b[n//2])/2
  k3 = (b[n//2-1]+b[n//2+1])/2
else:
  k1 = b[n//2-1]
  k2 = b[n//2]
  k3 = -1

if k1 == k2:
  for i in range(n):
    print(k1)
else:
  for i in range(n):
    if n%2 and a[i] == b[n//2]:
      print(k3)
    elif a[i] <= k1:
      print(k2)
    else:
      print(k1)

Solution (Python):
def myAnswer(N:int,X:list) -> None:
   tmp = sorted(X)
   r1 = tmp[N//2-1]
   r2 = tmp[N//2]
   for x in X:
      if(x <=r1):
         print(r2)
      else:
         print(r1)




def modelAnswer():
   return
def main():
   N = int(input())
   X = list(map(int,input().split()))
   myAnswer(N,X)
if __name__ == '__main__':
   main()

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

L = sorted_x[(N-1)//2]
M = sorted_x[(N+1)//2]
base = (L+M)/2


for i in  list_x:
    if i >= base:
        print(L)
    else:
        print(M)

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

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

Solution (Python):



from statistics import median_low,median_high













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


X = sorted(arrX)
low = median_low(X)
high = median_high(X)

for i in arrX:
    if i <= low:
        print(high)
    elif i >= high:
        print(low)

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

y = sorted(x)

m = (y[len(y)//2]+y[len(y)//2-1])/2



for i in range(len(x)):
    if x[i] > m:
        print(y[len(y)//2-1])
    else:
        print(y[len(y)//2])

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 

def ii(): return int(sys.stdin.readline().rstrip()) 
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) 
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]

def ss(): return sys.stdin.readline().rstrip() 
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) 
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]





n=ii()
arr0=limii()
arr=sorted(arr0)



cenleft=arr[n//2 -1]
cenright=arr[n//2]
for i in range(n):
    if arr0[i]==cenleft:
        print(cenright)
    elif arr0[i]==cenright:
        print(cenleft)
    elif arr0[i]>=cenright:
        print(cenleft)
    else:
        print(cenright)

Solution (Python):
n = int(input())
li = list(map(int,input().split()))
lee = len(li)
sorted_li = sorted(li)
mid = sorted_li[lee//2]
mid_mae = sorted_li[lee//2-1]
tmp = mid
for l in li:
    if l < mid:
        print(mid)
    else:
        print(mid_mae)

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

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

Solution (Python):
import statistics
n = int(input())-1
a = list(map(int, input().split()))
N = sorted([[x,y] for y, x in enumerate(a)])

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

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

for x in X:
  if x >= R:
    print(L)
  else:
    print(R)

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

for x in X:
  print(L if x >= R else R)

Solution (Python):

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

y=sorted(x)

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

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

sx = sorted(x)
m = (n+1)//2
med1 = sx[m - 1]
med2 = sx[m]

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

Solution (Python):
import sys
input = sys.stdin.readline
ma = lambda : map(int,input().split())
ni = lambda : int(input())
import collections
n = ni()
x = list(ma())
x2 = sorted(x)
me1 = x2[n//2]
me2 = x2[n//2-1]
for nu in x:
    if nu<me1:
        print(me1)
    else:
        print(me2)

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

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

Solution (Python):
def binary_search_loop(data, target):
    imin = 0
    imax = len(data) - 1
    while imin <= imax:
        imid = imin + (imax - imin) // 2
        if target == data[imid]:
            return imid
        elif target < data[imid]:
            imax = imid - 1
        else:
            imin = imid + 1
    return False
n = int(input())
lista = list(map(int, input().split()))
listb = sorted(lista)
for i in range(n):
    if binary_search_loop(listb, lista[i]) + 1 <= (n // 2):
        print(listb[(n // 2)])
    else:
        print(listb[(n // 2) - 1])

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

Solution (Python):
n=int(input())
x=list(map(int,input().split()))
lr,rr=sorted(x)[n//2-1:n//2+1]
print('\n'.join([str(lr) if lr<i else str(rr) for i in x]))

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

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

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






def main():
    N = int(input())
    X = list(map(int, input().split()))
    A = sorted(X)

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


main()

Solution (Python):
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    n = ni()
    x = nl()

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

    x.sort(key=lambda x: x[0])

    left = n//2 - 1
    right = left + 1

    for i, arr in enumerate(x):
        arr.append(x[right][0] if i <= left else x[left][0])

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


if __name__ == '__main__':
    main()

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

mid1, mid2 = sorted(X)[N//2-1:N//2+1]
smid1 = str(mid1)
smid2 = str(mid2)
print('\n'.join(smid1 if xi>mid1 else smid2 for xi in X))

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

mid1, mid2 = sorted(X)[N//2-1:N//2+1]
print('\n'.join(str(mid1) if xi>mid1 else str(mid2) for xi in X))

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

mid1, mid2 = sorted(X)[N//2-1:N//2+1]
print(*[mid1 if xi>mid1 else mid2 for xi in X], sep="\n")

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

mid = sorted(X)[N//2-1:N//2+1]
for xi in X:
    if xi > mid[0]:
        print(mid[0])
    else:
        print(mid[1])

Solution (Python):


import io
import sys

data = int(input())
array = list(map(int,input().split()))
qwe = sorted(array)
a = qwe[data//2]
b = qwe[data//2-1]
for i in array:
  if i >= a:
    print(b)
  else:
    print(a)

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

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

left = x[n//2-1]
right = x[n//2]
mid = (left+right)/2

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

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

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

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

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

a.sort()

ans = [0] * n

for i in range(n):
  ans[a[i][1]] = a[n//2 - (i >= n//2)][0]

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

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
xs = sorted(x)
mid = xs[n//2]
tmp = n//2
for i, xx in enumerate(x):
    if xx < mid:
        print(mid)
    elif xx > mid:
        if xx == xs[tmp-1]:
            print(xs[tmp-2])
        else:
            print(xs[tmp-1])
    else:

        print(xs[tmp-1])

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

if __name__ == '__main__':
  main()

Solution (Python):
import sys

def main():
    N = int(sys.stdin.readline())
    X = list(map(int, sys.stdin.readline().rstrip().split()))
    
    x_asc = sorted(X)
    m1, m2 = x_asc[N//2-1], x_asc[N//2]
    for x in X:
        if x <= m1:
            print(m2)
        else:
            print(m1)


if __name__ == '__main__':
    main()

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

Xs = sorted(As)

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

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

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

a1=li[n//2-1]
a2=li[n//2]

for i in x:
    if i<=a1:
        print(a2)
    else:
        print(a1)

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

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

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


def binary_search(l, item):
    left = 0
    right = len(l) - 1
    while left <= right:
        mid  = (left + right) // 2
        if l[mid] == item:
            return mid
        elif l[mid] < item:
            left = mid + 1
        else:
            right = mid - 1
    return -1

for i in range(n):
    target_ind = binary_search(sorted_x, x_ls[i])
    if target_ind <= n // 2 - 1:
        ans = bigger
    else:
        ans = smaller
    print(ans)

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

Y_mid_left,Y_mid_right = Y[N//2-1],Y[N//2]

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

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

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


idx_dict = {}
for i in range(N):
    idx_dict[i] = l[i]

l.sort()
smaller_middle_idx = int(N / 2) - 1
bigger_middle_idx = int(N / 2)

for i in range(N):
    except_num = idx_dict[i] 
    
    if l[smaller_middle_idx] == l[bigger_middle_idx]:
        print(l[smaller_middle_idx])

    elif except_num < l[bigger_middle_idx]:
        print(l[bigger_middle_idx])
    
    else:
        print(l[smaller_middle_idx])

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

sorted_a = sorted(a)


med = [sorted_a[n // 2 - 1], sorted_a[n // 2]]


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

Solution (Python):
n = int(input())
x = list(map(int,input().split()))
y = x.copy()
y.sort()
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):
N = int(input())
X = list(map(int, input().split()))

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

indices = {(i + 1): x for i, (x, _) in enumerate(argsort)}

argsort = [[i, j] for j, [_, i], in enumerate(argsort)]
argsort.sort()

ranks = [j + 1 for _, j in argsort]

median = N // 2
for i in range(0, N):
    r = ranks[i]
    if r <= median:
        print(indices[median + 1])
    else:
        print(indices[median])

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

tmp = num_list.copy()
tmp.sort()

mid = tmp[n//2-1]
midu =  tmp[n//2]
for i in num_list:
    if i <= mid:
        print(midu)
    else:
        print(mid)

Solution (Python):
import copy

n = int(input())
x = list(map(int,input().split()))
key = {}
base = copy.deepcopy(x)
base.sort()

for i in range(n):

  if n//2 > i:
    ans = base[n//2]
  elif n//2 <= i:
    ans = base[n//2-1]
   
  if not ("key" + str(base[i]) in key):
    key["key" + str(base[i])] = ans
    
for i in range(n):
  print(key["key" + str(x[i])])

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

sort_x = sorted(X, key= lambda x: x)

mid_left = sort_x[N // 2 - 1]
mid_right = sort_x[N // 2]

for i in X:
    if i <= mid_left:
        print(mid_right)
    else:
        print(mid_left)

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

tmp = [0] * N
for i in range(N):
    tmp[i] = X[i]

tmp.sort()
mid_left = tmp[N // 2 - 1]
mid_right = tmp[N // 2]



for i in X:
    if i <= mid_left:
        print(mid_right)
    else:
        print(mid_left)

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

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

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

ansmed = ans[N//2]

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

Solution (Python):
import sys

read = sys.stdin.buffer.read

def main():
    N, *X = map(int, read().split())
    A = sorted(X)
    
    j = N//2 - 1
    Aj = A[j]; Aj1 = A[j+1]
    for i in range(N):
        if X[i] <= Aj:
            print(Aj1)
        else:
            print(Aj)
    
    
    
    
    
    
    
    
    
    
    
    
    

if __name__ == "__main__":
    main()

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

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
res = []
ind = {}
for i in range(n):
    res.append([a[i],i])
jun = [0]*n
res.sort()
for i in range(n):
    jun[res[i][1]] = i+1


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

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

d = N // 2
dn = Xc[d]

for i in range(N):
    if X[i] < dn:
        print(Xc[d])
    else:
        print(Xc[d-1])

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

Xcmed = Xc[N//2]

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

Solution (Python):
import sys

n, *x = map(int, sys.stdin.read().split())

def main():
    a = sorted(x)
    l = a[n//2-1]; r = a[n//2]
    for i in range(n):
        print(l if x[i] >= r else r)

if __name__ ==  '__main__':
    main()

Solution (Python):




mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    X = readInts()

    A = sorted(X)[n//2-1:n//2+1] 
    
    for x in X:
        
        print(A[x <= A[0]]) 




if __name__ == '__main__':
  main()

Solution (Python):
import copy
N = int(input())
Listx = list(map(int,input().split()))
Listxs = sorted(Listx)
A = Listxs[N//2]
B = Listxs[N//2-1]

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

Solution (Python):

url = "https://atcoder.jp//contests/abc094/tasks/arc095_a"

def main():
    N = int(input())
    Xs = list(map(int, input().split()))
    sort_Xs = sorted(Xs)
    front = len(sort_Xs) // 2 - 1
    rear = len(sort_Xs) // 2
    for X in Xs:
        if sort_Xs[rear] > X:
            print(sort_Xs[rear])
        else:
            print(sort_Xs[front])



if __name__ == '__main__':
    main()

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

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

Solution (Python):
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))

def main():
    n = II()
    xx = MII()
    xx_s = sorted(xx)
    ml = xx_s[n//2-1]
    mr = xx_s[n//2]
    
    
    for x in xx:
        if x < mr: print(mr)
        elif x >= ml: print(ml)

if __name__ == '__main__':
    main()

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

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

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


for x in X:
    if x <= median1:
        print(median2)
    else:
        print(median1)

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


if median1 == median2:
    for _ in range(n):
        print(median1)
    exit()
else:
    for x in X:
        if x <= median1:
            print(median2)
        else:
            print(median1)

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

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

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