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:
N = int(input())
X = list(map(int,input().split()))
X = [[X[i],i] for i in range(N)]
#print(N,X)

X.sort()
medind = (N-2)//2 
med = X[medind][0]
res = [0]*N

for i in range(N):
    if i <= medind:
        res[X[i][1]] = X[medind+1][0]
    else:
        res[X[i][1]] = med
#print(res)

for i in range(N):
    print(res[i])

Submission status: Accepted

Solution code:
N = int(input())
arr = []
for x in list(map(int,input().split())):
    arr.append(x)
sort_arr = sorted(arr)
mid1 = sort_arr[N//2-1]
mid2 = sort_arr[N//2]

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

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 x <= l:
        print(r)
    else:
        print(l)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

# Xをソート(Xsort)
# 除く数字が中央より左の場合、答えは中央右(r)の数字
# 逆も然り
Xsort=sorted(X)
l=(N-1)//2
r=l+1
th=Xsort[l]
for i in range(N):
    if X[i]<=th:
        ans=Xsort[r]
    else:
        ans=Xsort[l]
    print(ans)

Submission status: Accepted

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

medi1 = X_sort[int(N/2) - 1]
medi2 = X_sort[int(N/2)]

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

Submission status: Accepted

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

# _sum = sum(X)
buff_x = X.copy()


X.sort()
mm = X[N//2-1]
mx = X[N//2]
for i in range(N):
    if buff_x[i] < mx:
        print(mx)
    else:
        print(mm)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#ABC94 C

from copy import deepcopy
from operator import itemgetter
n = int(input())
x = list(map(int,input().split()))
y = sorted(x)
c1 = y[n//2-1]
c2 = y[n//2]
for i in x:
    if i < c2:
        print(c2)
    elif i >= c2:
        print(c1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import numpy as np
import statistics
from statistics import mean, median,variance,stdev
import math

def main():
	N = int(input())
	A = input().split(" ")
	A = [int(s) for s in A]
	
	tmp = copy.deepcopy(A)
	tmp.sort()
	
	m1_p = (len(tmp) / 2) - 1
	m1 = tmp[int(m1_p)]
	m2_p = (len(tmp) / 2)
	m2 = tmp[int(m2_p)]
	
	ans = []
	for i, val in enumerate(A):
		if val <= m1:
			ans.append(m2)
		else:
			ans.append(m1)
			
	for i in ans:
		print(i)
			
	
if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
indexedA = []
for i in range(0, N):
	indexedA.append([i, A[i]])
indexedA.sort(key = lambda v: v[1])
m1 = indexedA[N//2-1][1]
m2 = indexedA[N//2][1]
anslist = []
for i in range(0, N):
	if i < N//2:
		anslist.append([indexedA[i][0], m2])
	else:
		anslist.append([indexedA[i][0], m1])
anslist.sort(key = lambda v: v[0])
for i in range(0, N):
	print(anslist[i][1])

Submission status: Accepted

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

Submission status: Accepted

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

y = sorted(x)

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

Submission status: Accepted

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

Submission status: Accepted

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

sm = SX[N//2-1]
bi = SX[N//2]

for x in X:
    if x <= sm:
        print(bi)
    else:
        print(sm)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

N = int(input())
X = [int(_) for _ in input().split()]
tmp = sorted(X)

one = N // 2 - 1
two = N // 2

for x in X:
    if x <= tmp[one]:
        print(tmp[two])
    else:
        print(tmp[one])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import reduce
import math
import copy
def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input())
    X = list(int(_) for _ in input().split())
    X_tmp = copy.deepcopy(X)
    X_tmp.sort()
    X_avg = (X_tmp[(N//2)-1] + X_tmp[(N//2)])/2
    for i in range(N):
        if X[i] > X_avg:
            print(X_tmp[(N//2)-1])
        else:
            print(X_tmp[(N//2)])
            
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

middle = int(n/2) - 1
next_middle = middle + 1

for i in range(n):
  if x[i] <= sort_x[middle]:
    print(sort_x[next_middle])
  elif x[i] >= sort_x[next_middle]:
    print(sort_x[middle])

Submission status: Accepted

Solution code:
# ARC095C - Many Medians (ABC094C)
def main():
    n = int(input())
    x = list(map(int, input().rstrip().split()))
    sort_x = sorted(x)
    l, h = sort_x[n // 2 - 1], sort_x[n // 2]
    for i in x:
        if i <= l:
            print(h)
        else:
            print(l)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

temp = sorted(X)

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

for i, x in enumerate(X):
    if x <= l:
        print(r)
    else:
        print(l)

Submission status: Accepted

Solution code:
n = int(input())
lst_x = list(map(int, input().split()))
lst = lst_x[:]
lst.sort()
b1 = lst[n//2 - 1]
b2 = lst[n//2]


for x in lst_x:
    print(b2 if x <= b1 else b1)

Submission status: Accepted

Solution code:
n = int(input())
lst_x = list(map(int, input().split()))
lst = lst_x[:]
lst.sort()
b1 = lst[n//2 - 1]
b2 = lst[n//2]


for x in lst_x:
    if x <= b1:
        ans = b2
    else:
        ans = b1
    print(ans)

Submission status: Accepted

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

Y = sorted(X)

a = Y[N//2-1]
b = Y[N//2]

ans = []

for x in X :
    if x <= a :
        ans.append(b)
    else :
        ans.append(a)

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

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int,input().split()))
X2=sorted(X)
x=X2[N//2-1]
y=X2[N//2]

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

Submission status: Accepted

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

Submission status: Accepted

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

Xs = sorted(X)

a = Xs[N//2 - 1]
b = Xs[N//2]

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

Submission status: Accepted

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

Y=sorted(X)

a1=Y[N//2-1]
a2=Y[N//2]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

N = int(input())

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

X_c = X.copy()

X_c.sort()

#print (X_c)
#print (N//2)


bh = X_c[(N//2)-1]
fr = X_c[N//2]

#print (bh)
#print (fr)


for i in X:

    if i < fr:
        print (fr)
    else:
        print (bh)

Submission status: Accepted

Solution code:
import bisect
n=int(input())
x=list(map(int,input().split()))
y=[]
for i in range(n):
    y.append(x[i])

x.sort()

for i in range(n):
    if bisect.bisect_left(x,y[i])+1 <= len(x)/2:
        print(x[int(len(x)/2)])
    else:
        print(x[int(len(x)/2)-1])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
l=len(x)
xs=sorted(x)
m=xs[l//2-1]
M=xs[l//2]
for i in range(l):
  print(m if x[i]>m else M)

Submission status: Accepted

Solution code:
N = int(input())
X = [[int(x), i] for i,x in enumerate(input().split())]
M = sorted(X)
median = N // 2
for i in range(N):
    X[M[i][1]][1] = i
for i in range(N):
    print(M[median][0] if X[i][1] < median else M[median-1][0])

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int,input().split()))
X_sorted=sorted(X)
Med1=X_sorted[int(N/2)-1]
Med2=X_sorted[int(N/2)]

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

Submission status: Accepted

Solution code:
N = int(input())
X = [int(i) for i in input().split()]
X_sorted = sorted(X)
a = X_sorted[len(X_sorted)//2]
b = X_sorted[len(X_sorted)//2-1]
for i in X:
  if i <= b:
    print(a)
  elif i >= a:
    print(b)

Submission status: Accepted

Solution code:
import copy


if __name__ == '__main__':
    N = int(input())
    X_list = list(map(int, input().split()))
    tmp_X_list = copy.deepcopy(X_list)
    tmp_X_list = sorted(tmp_X_list)
    med_minus1 = tmp_X_list[N//2-1]
    med_plus1 = tmp_X_list[N//2]

    answer = -1
    for i in range(0, N):
        if X_list[i] <= med_minus1:
            answer = med_plus1
        elif X_list[i] >= med_plus1:
            answer = med_minus1

        print(answer)

Submission status: Accepted

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

s = sorted(x)
h = n // 2

for i in x:
    if i < s[h]:
        print(s[h])
    else:
        print(s[h-1])

Submission status: Accepted

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

y = range(n)

z = [[x[i],y[i],0] for i in range(n)]

z.sort(key = lambda t:t[0])
for i in range(n):
    if i < int(n/2):
        z[i][2] = z[int(n/2)][0]
    else:
        z[i][2] = z[int(n/2)-1][0]
z.sort(key = lambda t:t[1])
for i in range(n):
    print(z[i][2])

Submission status: Accepted

Solution code:
N = int(input())
s = input().split()
X = []
for i in range(N):
    X.append(int(s[i]))
sortedX = sorted(X)

mid = int((len(X))/2)
#print(sortedX)
#print(mid)
#print(sortedX[mid])
for i in range(N):
   # print(X[i])
    if X[i] < sortedX[mid]:
        print(sortedX[mid])
        #print("small")
    else:
        print(sortedX[mid-1])
        #print("big")

Submission status: Accepted

Solution code:
N = int(input())
a = sorted(map(lambda x, y: [int(y), x], range(1, N+1), input().split()))
 
m = N // 2
am = a[m][0]
amp = a[m-1][0]

a = sorted(zip(a, range(N)), key=lambda x:x[0][1])
for _, i in a:
  print(am if i < m else amp)

Submission status: Accepted

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

X_sort = sorted(X)
median_min = X_sort[N//2-1]
median_max = X_sort[N//2]

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

Submission status: Accepted

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

y = sorted(x)
med1 = y[n//2-1]
med2 = y[n//2]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))
Xn = sorted(X)
X1 = Xn[:-1]
X2 = Xn[1::]
m1 =  X1[N//2-1]
m2 =  X2[N//2-1]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

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

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  _l=sorted(l)

  if n%2==0:
    a=_l[n//2-1]
    b=_l[n//2]

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

main()

Submission status: Accepted

Solution code:

def solve(X):
    N = len(X)
    #print("X=", X)
    A = sorted([(x, i) for i, x in enumerate(X)])
    #print("A=", A)
    R = sorted([(i, x, rank) for rank, (x, i) in enumerate(A)])
    #print("R=", R)
    #   t
    # 0 1 2 3
    #   x o x
    # x   o x
    # x o   x
    # x o x  
    t = N // 2 - 1
    for i, x, rank in R:
        if rank <= t:
            print(A[t+1][0])
        else:
            print(A[t+0][0])

#solve([0,10,20,30])
N = int(input())
X = [int(x) for x in input().split()]
solve(X)

Submission status: Accepted

Solution code:
n = int(input())

arr = list(map(int, input().split()))
sorted_arr = sorted(arr)

median_big = sorted_arr[n // 2]
median_small = sorted_arr[n // 2 - 1]

for a in arr:
    if a >= median_big:
        print(median_small)
    else:
        print(median_big)

Submission status: Accepted

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


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

Submission status: Accepted

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

sort_x = sorted(x, reverse = True)

middle = int(N / 2)
for i in x:
    if i <= sort_x[middle]:
        print(sort_x[middle - 1])
    else:
        print(sort_x[middle])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import fractions
import copy
#以下てんぷら
def j(q):
    if q==1: print("Yes")
    elif q == 0:print("No")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def printrow(a):
    for i in a:
        print(i)
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


n = ip()                                     #入力整数1つ
#r,x,y= (int(i) for i in input().split())       #入力整数横2つ以上
a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#a.pop(0)は10^5あるときTLEしやすい!注意!
#これを消すとなぜかWAになる呪い
b = sorted(a)
leftmed = b[n//2-1]
rightmed = b[n//2]
for i in range(n):
    if a[i] >= rightmed:
        print(leftmed)
    else:
        print(rightmed)

Submission status: Accepted

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

Submission status: Accepted

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

for i in X:
    if i>Y[(N-2)//2]:
        print(Y[(N-2)//2])
    else:
        print(Y[N//2])

Submission status: Accepted

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


def solve(N: int, X: "List[int]"):
    XS =  copy.deepcopy(X)
    XS.sort()

    mi = (len(XS)+1)//2

    for x in X:
        if x < XS[mi]:
            print(XS[mi])
        else:
            print(XS[max(mi-1,0)])

    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())
num_list = [ int(v) for v in input().split() ]
num_list2 = sorted(num_list)



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

if a == b:
	for i in range(n):
		print(a)
else:
	for i in num_list:
		if i < b:
			print(b)
		else:
			print(a)

Submission status: Accepted

Solution code:
N = int(raw_input())
X = map(int, raw_input().split())
indexX = []
for i in range(0, N):
	indexX.append([i, X[i]])
indexX.sort(key=lambda val:val[1])
medlist = []
for i in range(0, N):
	if i < N/2: medlist.append([indexX[i][0], indexX[N/2][1]])
	else: medlist.append([indexX[i][0], indexX[N/2-1][1]])
medlist.sort(key=lambda val:val[0])
for i in range(0, N):
	print medlist[i][1]

Submission status: Accepted

Solution code:

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

Submission status: Accepted

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

high,low = Xs[N//2], Xs[N//2 - 1]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, *X = map(int, open(0).read().split())
mid_l = sorted(X)[(N + 1) // 2 - 1]
mid_r = sorted(X)[(N + 1) // 2]
print(*[mid_l if v > mid_l else mid_r for v in X], sep='\n')

Submission status: Accepted

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

Submission status: Accepted

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

a = sorted(lst)
center_m = a[N//2 - 1]
center_p = a[N//2]

#print (center_m, center_p)

for i in lst:
    if i <= center_m:
        print (center_p)
    else:
        print (center_m)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


def solve(N: int, X: "List[int]"):
    x = sorted(X)
    l = x[N // 2 - 1]
    r = x[N // 2]
    for a in X:
        if a <= l:
            print(r)
        else:
            print(l)
    return


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 = list(map(int,input().split()))
XL = sorted(X)
for i in range(N):
    if X[i] <= XL[N//2-1]:
        print(XL[(N+1)//2])
    else:
        print(XL[(N-1)//2])

Submission status: Accepted

Solution code:
from copy import deepcopy
N=int(input())
a=list(map(int,input().split()))
b=deepcopy(a)
b.sort()
B1=b[N//2-1]
B2=b[N//2]
for i in a:
    if i<=B1:
        print(B2)
    else:
        print(B1)

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
sl=sorted(l)
def bin_srch(x):
	
	low=0
	high=n-1
	mid=n//2
	while sl[mid]!=x:
		if sl[mid]>x:
			high=mid-1
		else:
			low=mid+1
		mid=(low+high)//2
	return mid
m1,m2=sl[n//2-1],sl[n//2]
for i in l:
	pos=bin_srch(i)
	print(m1 if pos>=n//2 else m2)

Submission status: Accepted

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

sorted_x = sorted(X)
low_mid = sorted_x[N//2-1]
high_mid = sorted_x[N//2]

for x in X:
    if x < high_mid:
        print(high_mid)
    else:
        print(low_mid)

Submission status: Accepted

Solution code:
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


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


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


class UnionFind:

    def __init__(self, n):
        self.parent = [i for i in range(n)]

    def root(self, i):
        if self.parent[i] == i:
            return i
        self.parent[i] = self.root(self.parent[i])
        return self.parent[i]

    def unite(self, i, j):
        rooti = self.root(i)
        rootj = self.root(j)
        if rooti == rootj:
            return
        if rooti < rootj:
            self.parent[rootj] = rooti
        else:
            self.parent[rooti] = rootj

    def same(self, i, j):
        return self.root(i) == self.root(j)


###############################################################################


def main():
    n = intin()
    xlist = intina()

    xxlist = sorted(xlist)
    lxx = len(xxlist)
    c1 = xxlist[lxx//2-1]
    c2 = xxlist[lxx//2]

    for x in xlist:
        if x <= c1:
            print(c2)
        else:
            print(c1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int, input().split()))
X2=sorted(X)
medi_candi=[X2[N//2-1],X2[N//2]]

for i in X:
    if i <= medi_candi[0]:
        print(medi_candi[1])
    elif i >= medi_candi[1]:
        print(medi_candi[0])

Submission status: Accepted

Solution code:
#ABC094-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
X=IL()
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])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *


readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n = readi()
p = readl()
pp = []
for i in range(n):
    pp.append((p[i], i))
t = n // 2
pp.sort()
q = defaultdict(int)
for i in range(n):
    if t > i:
        q[pp[i][1]] = pp[t][0]
    else:
        q[pp[i][1]] = pp[t - 1][0]
for i in range(n):
    print(q[i])