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



Sample input:
4
2 4 4 3


Sample output:
4
3
3
4

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    n = I()
    x = LI()
    f = [(i,x[i]) for i in range(n)]
    f.sort(key = lambda x:x[1])
    g = [(f[i][0],i) for i in range(n)]
    g.sort(key = lambda x:x[0])
    for i in range(n):
        if g[i][1] < n//2:
            print(f[n//2][1])
        else:
            print(f[n//2-1][1])
    return

#H
def H():
    return

#I
def I_():
    return

#J
def J():
    return

#Solve
if __name__ == "__main__":
    G()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
X = [int(i) for i in input().split()]
Y = X.copy()
Y.sort()
y1 = Y[N//2-1]
y2 = Y[N//2]

for i in X:
  if i <= y1:
    print(y2)
  else:
    print(y1)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
x_sort = sorted(x)
def median(L):
    #L = sorted(L)
    n = len(L)
    m = int(n/2)
    if n % 2 == 0:
        return (L[m - 1] + L[m]) / 2
    else:
        return L[(n - 1) // 2]
x_median = median(x_sort)
l = median(x_sort[:-1])
r = median(x_sort[1:])
for i in range(n):
    if x[i] > x_median:
        print(l)
    else:
        print(r)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
def median(L):
    L = sorted(L)
    n = len(L)
    m = int(n/2)
    if n % 2 == 0:
        return (L[m - 1] + L[m]) / 2
    else:
        return L[(n - 1) // 2]
x_median = median(x)
l = median(sorted(x)[:-1])
r = median(sorted(x)[1:])
for i in range(n):
    if x[i] > x_median:
        print(l)
    else:
        print(r)

Submission status: Accepted

Solution code:
n=int(input())
x_list=[int(i) for i in input().split()]
x_sorted=sorted(x_list)
left=x_sorted[n//2-1]
right=x_sorted[n//2]

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

Submission status: Accepted

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

c = N // 2
x = sorted(X)
for v in X:
	if v < x[c]:
		print(x[c])
	else:
		print(x[c - 1])

Submission status: Accepted

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

x_sorted = sorted([[i, X[i]] for i in range(N)], key=lambda x: x[1])
mid = (x_sorted[N//2-1][1] + x_sorted[N//2][1]) / 2
for i in range(N):
    if X[i] >= mid:
        print(x_sorted[N//2-1][1])
    else:
        print(x_sorted[N//2][1])

Submission status: Accepted

Solution code:
from bisect import bisect_left

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

for i in range(n):
    if bisect_left(x_srt, x[i]) < n//2:
        print(x_srt[n//2])
    else:
        print(x_srt[n//2-1])

Submission status: Accepted

Solution code:

def main():
    num = int(input())
    data = list(map(int, input().split()))
    data_kari = data.copy()
    data_kari.sort()
    # print(data_kari)
    min_chuou = data_kari[(num // 2) - 1]
    max_chuou = data_kari[num // 2]

    # print(min_chuou, max_chuou)

    # print(data)

    for i in range(num):
        if data[i] <= min_chuou:
            print(max_chuou)
        elif data[i] >= max_chuou:
            print(min_chuou)






if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]
    x = f()

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

solve()

Submission status: Accepted

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

A = sorted(X)

m_r = A[N//2]
m_l = A[N//2-1]

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

Submission status: Accepted

Solution code:
n=int(input())
pos=n//2-1
arr=list(map(int,input().split()))
for i in range(n):
  arr[i]=[arr[i],i]
arr=sorted(arr,key=lambda x:x[0])
ans=[0]*n
for i in range(n):
  if i<=pos:
    ans[arr[i][1]]=arr[pos+1][0]
  else:
    ans[arr[i][1]]=arr[pos][0]
for i in range(n):
  print(ans[i])

Submission status: Accepted

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

import numpy as np

xidx = np.argsort(X)
xidx = sorted(range(len(xidx)),key = lambda k:xidx[k])
Y = X
Y.sort()
Med1 = Y[N//2]
Med2 = Y[(N-2)//2]
for i in xidx:
    
    if i < N//2:
        print(Med1)
    else:
        print(Med2)

Submission status: Accepted

Solution code:
from copy import deepcopy

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

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

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

Submission status: Accepted

Solution code:
import itertools
import copy
N = int(input())
Xs = list(map(int,input().split(" ")))
XsOrigin = copy.deepcopy(Xs)
Xs.sort()
l = int(len(Xs)/2)
left = Xs[l-1]
right =Xs[l]
for i in XsOrigin:
    if i <=left:
        print(right)
    else:
        print(left)

Submission status: Accepted

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

sorted_X = sorted(X)
left, right = sorted_X[N // 2 - 1], sorted_X[N // 2]

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

Submission status: Accepted

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

sorted_X = sorted(X)
left = sorted_X[N // 2 - 1]
right = sorted_X[N // 2]

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

Submission status: Accepted

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

import numpy as np
b = np.argsort(a)
idx = np.argsort(b)
for i in range(n):
    if idx[i] < n / 2:
        print(a[b[int(n / 2)]])
    else:
        print(a[b[int(n / 2) - 1]])

Submission status: Accepted

Solution code:
N = int(input())
x_list = list(map(int,input().split()))
sorted_list = sorted(x_list)
median_idx = N//2 -1
for x in x_list:
    if x>sorted_list[median_idx]:
        print(sorted_list[median_idx])
    else:
        print(sorted_list[median_idx+1])

Submission status: Accepted

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

L = sorted(X)
MS, ML = L[(N//2)-1], L[(N//2)]

if MS == ML:
    for _ in range(N):
        print(MS)
else:
    for i in range(N):
        if X[i] >= ML:
            print(MS)
        else:
            print(ML)

Submission status: Accepted

Solution code:
N = int(input())
xs = list(map(int, input().split()))
xs2 = sorted(xs)
M1 = xs2[len(xs)//2]
M2 = xs2[len(xs)//2 -1]
for x in xs:
    if x >= M1:
        print(M2)
    else:
        print(M1)

Submission status: Accepted

Solution code:


def read_input():
    n = int(input())
    xlist = list(map(int, input().split()))
    return n, xlist


def get_median(s, ignore):
    l = len(s)
    if ignore < l/2:
        return s[int((l+1)/2)]
    else:
        return s[int((l-1)/2)]

def submit():
    n, xlist = read_input()

    xlist = [(x, i) for i, x in enumerate(xlist)]
    xlist.sort(key=lambda x: x[0])

    pos_dic = {}
    for i, x in enumerate(xlist):
        pos_dic[x[1]] = i

    for i in range(n):
        target = pos_dic[i]
        print(get_median(xlist, target)[0])




if __name__ == '__main__':
    submit()

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
X0 = X[::]
X.sort()
num = int(N / 2 - 1)  # index は num
ans0, ans1 = X[num], X[num + 1]
for i in range(N):
    if X0[i] > ans0:
        print(ans0)
    else:
        print(ans1)

Submission status: Accepted

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

x = sorted(X)
s = x[N//2-1]
l = x[N//2]
if s == l:
    for i in range(N):
        print(s)
    exit()

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

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
sortX = sorted(X)
m1 = sortX[N // 2]
m2 = sortX[(N-2)//2]
for x in X:
    if x < m1:
        print(m1)
    else:
        print(m2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split(' ')))
Y = []
for i,j in enumerate(X):
  Y.append((i,j))
Z = sorted(Y,key=lambda x:x[1])
First_half = Z[int(N/2-1)][1]
Last_half = Z[int(N/2)][1]

for i,j in enumerate(X):
  if j <= First_half:
    print(Last_half)
  else:
    print(First_half)

Submission status: Accepted

Solution code:
N = int(input())

Xs = list(map(int,input().split()))
sort_xs = sorted(Xs)
l = sort_xs[N // 2 - 1]
r = sort_xs[N // 2]

for i in range(N):
    print(r if Xs[i] <= l else l)

Submission status: Accepted

Solution code:
n=int(input())
X=[int(i) for i in input().split()]
Y=sorted(X)
l,r=Y[n//2-1],Y[n//2]
for i in range(n):
  print(l if X[i]>=r else r)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
sx = sorted(x)

m1 = sx[len(sx) // 2 - 1]
m2 = sx[len(sx) // 2]

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

Submission status: Accepted

Solution code:
n = int(input())
x = [int(i) for i in input().split()]
y = x.copy()
y.sort()
y_e = y[n//2]
y_o = y[n//2 - 1]
for xx in x:
    if xx >= y_e:
        print(y_o)
    else:
        print(y_e)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
Y = []
for i in range(N):
  Y.append(X[i])
Y.sort()
m = (Y[N//2-1] + Y[N//2]) / 2
#print(m)
for i in range(N):
  if X[i] <= m:
    print(Y[N//2])
  else:
    print(Y[N//2-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = tuple(a)
a.sort()
A1 = a[n//2-1]
A2 = a[n//2]
med = (A1+A2)/2
for i in range(n):
    if b[i] <= med:
        print(A2)
    else:
        print(A1)

Submission status: Accepted

Solution code:
def main():
	N = int(input())
	X = list(map(int, input().split()))
	x = list(X)
	x.sort()
	mid = x[N//2]
	if N % 2 == 1:
		mid = (x[N//2]+x[N//2 + 1])/2
	for i in range(N):
		if X[i] < mid:
			if N % 2 == 0:
				print(x[N//2])
			else:
				print((x[N//2]+x[(N//2)+1])/2)
		elif X[i] == mid and N % 2 == 1:
			print((x[(N//2) - 1] + x[(N//2) + 1])/2)
		else:
			if N % 2 == 0:
				print(x[(N//2)-1])
			else:
				print((x[N//2]+x[(N//2)-1])/2)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

y = sorted(x)

median = int((x[int(n/2 - 1)] + x[int(n/2)]) / 2)

a = y[int(n/2)]
b = y[int(n/2 - 1)]

for i in range(n):

    if x[i] < a:
        print(a)
    else:
        print(b)

Submission status: Accepted

Solution code:
import statistics as sta

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

sort_X = sorted(X)
a = sta.median_low(sort_X)
b = sta.median_high(sort_X)

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
ac=a[:]
ac.sort()
al=ac[n//2-1]
ar=ac[n//2]
for i in a:
    if i<=al:print(ar)
    else:print(al)

Submission status: Accepted

Solution code:
n = int(input())


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

if n == 2:
  print(x[1])
  print(x[0])

else:
  piv = n//2

  b = x_sorted[piv]
  a = x_sorted[piv-1]
  for i in range(n):

    if x[i] < x_sorted[piv]:
      print(b)
    else:
      print(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
x = []
for i in range(N):
    x.append([X[i], i])
x.sort()
B = []

for i in range(N):
    if i < N // 2:
        B.append([x[N//2][0], x[i][1]])
    else:
        B.append([x[(N-1)//2][0], x[i][1]])

B.sort(key=lambda x: x[1])

for i in range(N):
    print(B[i][0])

Submission status: Accepted

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

Y = sorted(X)

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

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

Submission status: Accepted

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

X2 = sorted(X)

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

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

Submission status: Accepted

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

M = sorted(X)
for x in X:
    if x >= M[N//2]:
        print(M[N//2-1])
    else:
        print(M[N//2])

Submission status: Accepted

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

r=N//2
l=r-1

Xs=sorted(X)
m=(Xs[r]+Xs[l])/2

for x in X:
	print(Xs[l if x > m else r])

Submission status: Accepted

Solution code:
N = int(input())
XX = [int(i) for i in input().split()]
X = sorted(XX)
ans = {}
value = N//2 - 1
for i in range(N):
    if i <= value:
        ans[X[i]] = X[value+1]
    else:
        ans[X[i]] = X[value]

for i in XX:
    print(ans[i])

Submission status: Accepted

Solution code:
N = int(input())
XX = [int(i) for i in input().split()]
X = XX.copy()
X.sort()
ans = {}
value = N//2 - 1
for i in range(N):
    if i <= value:
        ans[X[i]] = X[value+1]
    else:
        ans[X[i]] = X[value]

for i in XX:
    print(ans[i])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys


fin = sys.stdin.readline
N = int(fin())
X_list = [int(elem) for elem in fin().split()]
sorted_indices = sorted(range(N), key=lambda i: X_list[i])
org_pos_to_sorted = {org_p: sorted_p for sorted_p, org_p in enumerate(sorted_indices)}

left_mid = X_list[sorted_indices[N // 2 - 1]]
right_mid = X_list[sorted_indices[N // 2]]
result = []
for i in range(N):
    sorted_pos = org_pos_to_sorted[i]
    if sorted_pos >= N // 2:
        result.append(left_mid)
    else:
        result.append(right_mid)

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

Submission status: Accepted

Solution code:
import bisect

def func(s):
    return []

N=int(input())
a=list(map(int,input().split()))
b=sorted(a)
p=b[N//2-1]
q=b[N//2]

for i in range(N):
    print(q if a[i]<q else p )

Submission status: Accepted

Solution code:
def calculate_median(lst):
    lst.sort()
    median_right = lst[int(len(lst)/2)]
    median_left = lst[int(len(lst)/2)-1]
    return median_right, median_left


N = int(input())
X = list(map(int, input().split()))
X_copy = X.copy()
median_right, median_left = calculate_median(X)
for i in range(N):
    if X_copy[i] >= median_right:
        print(median_left)
    elif X_copy[i] < median_right:
        print(median_right)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import bisect


def solve(N: int, X: "List[int]"):
    S = sorted(X)
    later = S[N//2-1]
    earlier = S[N//2]
    for i in range(N):
        cur = X[i]
        index = bisect.bisect_left(S, cur)
        if index >= N//2:
            print(later)
        else:
            print(earlier)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, X)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
X = tuple(map(int, input().split()))

Y = list(X)
Y.sort()

greater_median = Y[N//2]
smaller_median = Y[N//2-1]
average = (greater_median + smaller_median)/2

for x in X:
    if x <= average:
        print(greater_median)
    else:
        print(smaller_median)

Submission status: Accepted

Solution code:
import math
def MI(): return map(int, input().split())
def II(): return int(input())
def IS(): return input()
def LI(): return list(map(int, input().split()))


n = II()
x = LI()
sort_x = sorted(x)
left = sort_x[math.floor(n/2-0.1)]
right= sort_x[math.floor(n/2+0.1)]
for num in x:
    if num < (left+right)/2:
        print(right)
    else:
        print(left)

Submission status: Accepted

Solution code:
n = int(input())
s = [ int(i) for i in input().split() ]
t = sorted(s)
med = (t[n//2-1] + t[n//2])/2
# print(t)
for i in s:
    if i < med:
        print(t[n//2])
    else:
        print(t[n//2-1])

Submission status: Accepted

Solution code:
n = int(input())
X = list(map(int,input().split()))
Temp = X.copy()

Temp.sort()
temp = int((Temp[int(n/2)-1]+Temp[int(n/2)])/2)
for x in X:
    if x == Temp[int(n/2)-1]:
        print(Temp[int(n/2)])
    elif x == Temp[int(n/2)]:
        print(Temp[int(n/2)-1])
    elif x < temp:
        print(Temp[int(n/2)])
    else:
        print(Temp[int(n/2)-1])

Submission status: Accepted

Solution code:
from sys import stdin
n = int(stdin.readline().rstrip())
x = [int(_) for _ in stdin.readline().rstrip().split()]
xc = x.copy()
xc.sort()
ans = [xc[(len(xc)-1)//2], xc[len(xc)//2]]
for i in range(n):
    if x[i] < ans[1]:
        print(ans[1])
    elif x[i] >= ans[1]:
        print(ans[0])

Submission status: Accepted

Solution code:
N = int(input())
X = [int(i) for i in input().split()]
X_sorted = sorted(X)
a = [X_sorted[N//2-1], X_sorted[N//2]]
for i in range(N):
    if X[i] >= a[1]:
        print(a[0])
    else:
        print(a[1])

Submission status: Accepted

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

X2 = sorted(X)
m1 = X2[(N//2)-1]
m2 = X2[N//2]

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

Submission status: Accepted

Solution code:
import copy

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

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

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

for i in X2:
  if i > l:
    print(l)
  else:
    print(r)

Submission status: Accepted

Solution code:
N = int(input())
lst = list(map(int, input().split()))

sorted_lst = sorted(lst)
median_big = sorted_lst[N//2]
median_small = sorted_lst[(N//2)-1]
for i in lst:
    print(median_big) if i < median_big else print(median_small)

Submission status: Accepted

Solution code:
N=int(input())
X=[int(x) for x in input().split()]
Y=[[i,X[i],0] for i in range(N)]
Y.sort(key=lambda x: x[1])
B=Y[N//2][1]
for i in range(N):
  if Y[i][1]==B:
    B=Y[N//2-1][1]
  Y[i][2]=B
Y.sort(key=lambda x : x[0])
for i in range(N):
  print(Y[i][2])

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

from collections import defaultdict

N = int(input())
X = list(map(int, input().rstrip().split(' ')))
sorted_X = sorted(X)

x2med = defaultdict(lambda: -1)

med_index = (len(X) - 1) // 2
for i, x in enumerate(sorted_X):
    if i <= med_index:
        x2med[x] = sorted_X[med_index + 1]
    else:
        x2med[x] = sorted_X[med_index]
        
for i, x in enumerate(X):
    print(x2med[x])

Submission status: Accepted

Solution code:
import statistics


n = int(input())
x = list(map(int, input().split()))
m_low = statistics.median_low(x)
m_high = statistics.median_high(x)
for i in range(n):
    if x[i] > m_low:
        print(m_low)
    elif x[i] <= m_high:
        print(m_high)

Submission status: Accepted

Solution code:
from bisect import bisect_left

N = int(input())
X = list(map(int, input().split()))
S = sorted(X)
m1 = S[int(N/2 - 1)]
m2 = S[int(N/2)]
for x in X:
    if bisect_left(S, x) <= N/2 - 1:
        print(m2)
    else:
        print(m1)

Submission status: Accepted

Solution code:
import copy
N = int(input())
L = list(map(int,input().split()))
C = copy.deepcopy(L)
C.sort()
P,Q = C[N//2-1],C[N//2]
for i in range(N):
  if L[i] <= P:
    print(Q)
  else:
    print(P)

Submission status: Accepted

Solution code:
N = int(input())
Xn = list(map(int, input().split()))

sXn = sorted(Xn)
m1 = sXn[N//2-1]
m2 = sXn[N//2]
m = (m1+m2) / 2

for X in Xn:
    print(m1 if X > m else m2)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
l = X[:]

l.sort()

m = (l[N//2 - 1] + l[N//2])/2

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
X = [int(i) for i in input().split()]
a = X[:]
a.sort()
l = a[N//2-1]
r = a[N//2]
if l == r:
    for i in range(N):
        print(l)
else:
    for i in range(N):
        if X[i] <= l:
            print(r)
        elif X[i] >= r:
            print(l)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


inf = float('inf')


# globals
N = 0
X = []


def set_inputs():
    global N, X
    N = get_int()
    X = get_li()
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    # ----------MAIN----------
    ix = list(sorted(enumerate(X), key=operator.itemgetter(1)))
    l, r = ix[N // 2 - 1][1], ix[N // 2][1]
    ans = [0] * N
    for j, (i, x) in enumerate(ix):
        if j < N // 2:
            ans[i] = r
        else:
            ans[i] = l
    for a in ans:
        print(a)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


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


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return zip(*(
        [t(x) for t, x in zip(types, input().split())]
        for _ in range(n)
    ))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = [int(item) for item in input().split()]
a_s = sorted(a)

low_med = a_s[n//2 - 1]
high_med = a_s[n//2]

for item in a:
  if low_med == high_med:
    print(low_med)
  elif item <= low_med:
    print(high_med)
  elif item >= high_med:
    print(low_med)

Submission status: Accepted

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

Submission status: Accepted

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

temp = X[:]

X.sort()
mi = X[len(X)//2-1]
ma = X[len(X)//2]

for x in temp:
    if x <= mi:
        print(ma)
    else:
        print(mi)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
X.append(0)
Y = sorted(X)
#c = Y[len(X) // 2 - 1]
d = Y[len(X) // 2]
e = Y[len(X) // 2 + 1]
#print(X,c)
for i in range(N):
    #print(X[i])
    if X[i] <= d:
        print(e)
    else:
        print(d)

Submission status: Accepted

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

x = zip(x, [i for i in range(0, n)])
x = sorted(x, key=lambda k: k[0])
r = [0] * n

for i in range(0, n):
    if i < n // 2:
        r[x[i][1]] = x[n // 2][0]
    else:
        r[x[i][1]] = x[n // 2 - 1][0]

for i in r:
    print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
X = list(map(int, input().split()))
X_sorted = sorted(X)

L = X_sorted[N//2 -1]
U = X_sorted[N//2]

for x in X:
  if x<=L:
    print(U)
  else:
    print(L)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))
work = X.copy()
work.sort()
dict = {}
left = N // 2
right = left - 1
for i in range(N):
    if i < N // 2:
        dict[work[i]] = work[left]
    else:
        dict[work[i]] = work[right]
for i in range(N):
    print(str(dict[X[i]]))

Submission status: Accepted

Solution code:
def solve(string):
    n, *x = map(int, string.split())
    mid = n // 2
    l, r = sorted(x)[mid - 1:mid + 1]
    return "\n".join([str(r) if _x < r else str(l) for _x in x])


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Submission status: Accepted

Solution code:
def solve(string):
    n, *x = map(int, string.split())
    mid = n // 2
    x = [(i, _x) for i, _x in enumerate(x)]
    x = sorted(x, key=lambda x: x[1])
    ans = [[] for _ in range(n)]
    for i, _x in enumerate(x):
        ans[_x[0]] = str(x[mid][1]) if i < mid else str(x[mid - 1][1])
    return "\n".join(ans)


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Submission status: Accepted

Solution code:
def solve(string):
    n, *x = map(int, string.split())
    mid = n // 2
    x = [(i, _x) for i, _x in enumerate(x)]
    x = sorted(x, key=lambda x: x[1])
    ans = [(_x[0], x[mid][1]) if i < mid else (_x[0], x[mid - 1][1]) for i, _x in enumerate(x)]
    ans = sorted(ans, key=lambda x: x[0])
    return "\n".join([str(_x) for i, _x in ans])


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Submission status: Accepted

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N = I()
X = LI()

#  N = 200000
#  X = [i*10 for i in range(1,N+1)]

"""
まずは偶数時の中央値のidxを求める
偶数時の中央値より小さいものが抜かれたときは、そのまま、
大きいものが抜かれたときはidx-1が中央値となる
"""
#見つかったメディアンを保存
found = {}
sorted_X = sorted(X)
median = sorted_X[int(len(X)/2)]
for x in X:
    #  print('x', x)
    #  print('found', found)
    if x < median:
        if found.get('small',None):
            print(found['small'])
        else:
            print(median)
            found['small'] = median
    elif x > median:
        if not found.get('big', None):
            tmp = [i for i in sorted_X]
            tmp.remove(x)
            #奇数長になっている
            m = tmp[int(len(tmp)//2)]
            print(m)
            found['big'] = m
        else:
            print(found['big'])
    else:
        if not found.get('equal', None):
            tmp = [i for i in sorted_X]
            tmp.remove(x)
            m = tmp[int(len(tmp)//2)]
            print(m)
            found['equal'] = m
        else:
            print(found['equal'])

Submission status: Accepted

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

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

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

Submission status: Accepted

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