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:
# import copy

N = int(input())
X = list(map(int, input().split()))
# S_X = copy.copy(X)
S_X = sorted(X)
miX = S_X[N // 2 - 1]
mi1X = S_X[N // 2]
# print(S_X, X)
# print(miX, mi1X)

# print(miX, mi1X)
# print(X)
for a in X:
    if(a <= miX):
        print(mi1X)
    else:
        print(miX)

Submission status: Accepted

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

sorted_x = sorted(x)

median_1 = sorted_x[n//2-1]
median_2 = sorted_x[n//2]

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int,input().split()))
s_x = sorted(x)
med_1 = s_x[n//2-1]
med_2 = s_x[n//2]

for i in x:
    if i<med_2:
        print(med_2)
    else:
        print(med_1)

Submission status: Accepted

Solution code:
N = int(input())
xn = list(map(int,input().split()))
x0,x1 = sorted(xn)[N//2-1:N//2+1]
res = [x0 if x0 < x else x1 for x in xn]
print('\n'.join(map(str,res)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


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

    s = list(sorted(X))
    m = defaultdict(int)
    for i, x in enumerate(s):
        m[x] = i

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
  N = int(input())
  t = input().split(" ")
  a = [int(i) for i in t]
  b = sorted(a)
  sm = b[N//2-1]
  bm = b[N//2]
  
  for i in a:
    if i <= sm:
      print(bm)
    else:
      print(sm)
main()

Submission status: Accepted

Solution code:
import statistics
n = int(input())
x = [int(i) for i in input().split()]
x_sort = sorted(x)
med = statistics.median(x)
for i in x:
    if i < med:
        print(x_sort[n//2])
    else:
        print(x_sort[n//2-1])

Submission status: Accepted

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

sorted_X = sorted(X)
m1, m2 = sorted_X[N//2-1: N//2+1]

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

Submission status: Accepted

Solution code:

import numpy as np
N = int(input())

X = [int(i) for i in input().split()]

med_1up = int(np.median(X+[10e9+1]))
med = np.median(X)
med_1down = int(np.median(X+[0]))
for i in range(N):
    if X[i] > med:
        print(med_1down)
    else:
        print(med_1up)

Submission status: Accepted

Solution code:
import numpy as np

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

srtX = sorted(X)

low = srtX[int(N / 2) - 1]
high = srtX[int(N / 2)]

ans = []
for x in X:
    if x < high:
        ans.append(high)
    else:
        ans.append(low)

for a in ans:
    print(a, end=' ')

Submission status: Accepted

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output


def chkprint(*args):
    names = {id(v): k for k, v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg), '???')+' = '+repr(arg) for arg in args))

# Binary converter


def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]

# --------------------------------------------


dp = None


def main():
    N = int(input())
    X = li_input()

    sX = sorted(X)
    med = sX[len(sX) // 2]
    med_min = sX[len(sX) // 2 - 1]

    for x in X:
        if x < med:
            print(med)
        else:
            print(med_min)


main()

Submission status: Accepted

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

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

Submission status: Accepted

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

x_sorted = sorted(x)
for x_i in x:
	print((x_sorted[n//2-1], x_sorted[n//2])[x_i < x_sorted[n//2]])

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

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

med_min = Y[N//2-1]
med_max = Y[N//2]

for x in X:
    if x<= med_min:
        print(med_max)
    else:
        print(med_min)

Submission status: Accepted

Solution code:
#coding:utf-8
n = int(input())
List = list(map(int,input().split()))
sort = sorted(List)

l = sort[n // 2 - 1]
r = sort[n // 2]
for i in range(n):
    num = List[i]
    if num <= l:
        print(r)
    else:
        print(l)

Submission status: Accepted

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

Submission status: Accepted

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

X_s = sorted(X)
dict_med = {}

if N == 2 :
    print(X[1])
    print(X[0])
else :
    med_l = N // 2 - 1
    med_r = N // 2
    
    for i in range(N) :
        if i == med_l :
            dict_med[X_s[i]] = X_s[med_r]
        elif i == med_r : 
            dict_med[X_s[i]] = X_s[med_l]
        elif i < med_l :
            dict_med[X_s[i]] = X_s[med_r]
        elif i > med_r:
            dict_med[X_s[i]] = X_s[med_l]
    
    for i in X :
        print(dict_med[i])

Submission status: Accepted

Solution code:
from statistics import median_low, median_high

n = int(input())
xs = [int(x) for x in input().split()]

m1, m2 = median_low(xs), median_high(xs)

medians = (str(m2 if x < m2 else m1) for x in xs)
print('\n'.join(medians))

Submission status: Accepted

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

X_copy = X.copy()
X_copy.sort()
medi_min = X_copy[N//2-1]
medi_max = X_copy[N//2]


for x in X:
    if x<=medi_min:
        print(medi_max)
    else:
        print(medi_min)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#-*-coding:utf-8-*-

def main():
    N = int(input())
    x_list = list(map(int, input().split()))
    x_list_sort = x_list[:]
    x_list_sort.sort()
    med1 = x_list_sort[(N//2)-1]
    med2 = x_list_sort[N//2]
    for i in x_list:
        if i <= med1:
            print(med2)
        elif i >= med2:
            print(med1)
            
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

arr = map(int,raw_input().split())

arrb = arr[:]
arrb.sort()
a = n/2-1
b = n/2

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
b = sorted(x)
m1 = b[n//2-1]
m2 = b[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 = [int(x) for x in input().split()]

def main():
    sorted_list = sorted(X)
    mid = N // 2
    left_median = sorted_list[mid - 1]
    right_median = sorted_list[mid]

    for num in X:
        ans = right_median if num <= left_median else left_median
        print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
a=sorted(x)
ans={}

for i in range(n):

    if i<n//2:
        ans[a[i]]=a[n//2]
    else:
        ans[a[i]]=a[n//2-1]

for j in x:
    print(ans[j])

Submission status: Accepted

Solution code:
n=int(input())

x = list(map(int,input().split()))
y=[0]*n

for i in range(n):
    y[i]=x[i]
    
y.sort()

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:
N = int(input())
x = input().split()
X = list(map(int,x))
Xi = list(X)
Xi.sort()
Xi.reverse()


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

Submission status: Accepted

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

x_sort = sorted(x)
index = int(n/2)
num = x_sort[index]

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

Submission status: Accepted

Solution code:

def main():
    n = int(input())
    xs = [int(i) for i in input().split()]

    xx = xs[:]
    xx.sort()
    a, b = xx[n//2-1], xx[n//2]
    #print(a, b, xx)
    for x in xs:
        if x >= b:
            print(a)
        else:
            print(b)
    

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

a = tmp[int(len(tmp)/2)-1]
b = tmp[int(len(tmp)/2)]

for i in X:
    print(b if i<(a+b)/2 else a)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

tmpls = sorted(X)
low = tmpls[N//2 -1]
high = tmpls[N//2]

for i in X:
    if i > low:
        print(low)
    else:
        print(high)

Submission status: Accepted

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

tmpls = sorted(X)
low = tmpls[N//2 -1]
high = tmpls[N//2]

for i in X:
    if i > low:
        print(low)
    else:
        print(high)

Submission status: Accepted

Solution code:
from statistics import median_low, median_high

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

m1, m2 = median_low(xs), median_high(xs)

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

Submission status: Accepted

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

ys = list(sorted(xs))
m1, m2 = (ys[i] for i in (n//2 - 1, n//2))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

XX = sorted(X,key=int)

big = XX[int(N/2)]
small = XX[int(N/2)-1]

for i in X:
  if i>=big:
    print(small)
  elif i<=small:
    print(big)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
meds = list(sorted(X))[N//2-1:N//2+1] # only necessary part
for x in X: # iterate sequence, not index
    if x <= meds[0]:
        print(meds[1])
    else:
        print(meds[0])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

hoge = math.floor(N/2)

y = sorted(x)
A = y[hoge]
B = y[hoge-1]

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

sorted_x = sorted(x, reverse = True)

med_index = n // 2 -1


for l in range(n):
    if x[l] >= sorted_x[med_index]:
        print(sorted_x[med_index+1])
    elif x[l] < sorted_x[med_index]:
        print(sorted_x[med_index])

Submission status: Accepted

Solution code:
import copy
N=int(input())
X=list(map(int,input().split()))
Y=copy.deepcopy(X)
Y.sort()
kiteichiA=Y[N//2-1]
kiteichiB=Y[N//2]
for i in range(N):
    if X[i]>=kiteichiB:
        print(kiteichiA)
    elif X[i]<=kiteichiA:
        print(kiteichiB)

Submission status: Accepted

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

sortedX = X[:]
sortedX.sort()
lenX = len(X)

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
X = list(map(int,input().split(' ')))
X2 = X.copy()
X2.sort()
Xminor = X2[int(n/2)]
Xmajor = X2[int(n/2)-1]
for x in X:
    if x < Xminor:
        print(Xminor)
    else:
        print(Xmajor)

Submission status: Accepted

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

for x in X:
    if x < median:
        print(median)
    else:
        print(X_sorted[(N + 1) // 2 - 1])

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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]

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

Submission status: Accepted

Solution code:
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []    
    data = input()
    array_result.append(data.split(" "))

    flg = True

    try:
        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0])

val = (n-1) // 2

arr = list(map(int, arr_data[1]))

arr_sort = sorted(arr)

val1 = arr_sort[(n // 2)-1]
val2 = arr_sort[(n // 2)]

for v in arr:
    
    if v<=val1:
        
        print(val2)
        
    else:
        
        print(val1)

Submission status: Accepted

Solution code:
import copy

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

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

y = copy.deepcopy(x)
y.sort()
mid_s = y[n // 2 - 1]
mid_l = y[n // 2]
for a in x:
    if a < mid_l:
        print(mid_l)
    else:
        print(mid_s)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from statistics import median
N = int(input())
X = list(map(int, input().split()))

Y = X + [0]
Z = X + [10**9 + 1]

ymed = median(Y)
zmed = median(Z)

if ymed == zmed:
    for _ in range(N):
        print(ymed)
else:
    for i in X:
        if i <= ymed:
            print(zmed)
        else:
            print(ymed)

Submission status: Accepted

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

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

Submission status: Accepted

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

sorted_x = sorted(x)
m1 = sorted_x[int(n / 2) - 1]
m2 = sorted_x[int(n / 2)]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

X = sorted(X)
#2つの値しか出力されない
B = X[int(N/2-1)]
B_te = X[int(N/2)]

for i in range(N):
    if B < original_X[i]:
        print(B)
    else:
        print(B_te)

Submission status: Accepted

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

Submission status: Accepted

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

    sort_list = x[:]
    sort_list.sort()

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

b = sorted(a)
m1 = b[n // 2]
m2 = b[n // 2 - 1]

for num in a:
    if(num < m1):
        print(m1)
    else:
        print(m2)

Submission status: Accepted

Solution code:
a = input()
a = int(a)
b = input()
b= b.rstrip().split(" ")

bi =[]
for i in range(len(b)):
    bi.append(int(b[i]))
    i+=1
    
#print(bi)
bs =sorted(bi)
#print(bs)
for j in range(int(a)):
    if bi[j]>=bs[int(len(bs)/2)]:
        print(bs[int(len(bs)/2-1)])
        j+=1
    else:
        print(bs[int(len(bs)/2)])
        j+=1

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))
sX=sorted(X)
ans = []
ans.append(sX[N//2-1])
ans.append(sX[N//2])
for xi in X:
    if xi <= ans[0]:
        print(ans[1])
    else:
        print(ans[0])

Submission status: Accepted

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

y = sorted(x)

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

Submission status: Accepted

Solution code:
n = int(raw_input())
x = map(int, raw_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

Submission status: Accepted

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

s = sorted(x)
u = s[int(n/2)]
t =s[int(n/2-1)]

for i in (x):
    if i < u:
        print(u)
    else:
        print(t)

Submission status: Accepted

Solution code:
N = int(input())
X_N = list(map(int, input().split()))
tmp = sorted(X_N)
mid_r = tmp[N//2]
mid_l = tmp[N//2-1]
result = []
for i in range(N):
    if X_N[i]<=mid_l:
        result.append(mid_r)
    else:
        result.append(mid_l)
for i in range(N):
    print(result[i])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
X = [int(i) for i in input().split()]
X_med = sorted(X)[N//2-1:N//2+1]
print("\n".join(map(str, [X_med[1] if xi<=X_med[0] else X_med[0] for xi in X])))

Submission status: Accepted

Solution code:
N = int(input())
X = [int(i) for i in input().split()]
X_sorted = sorted(X)
X_med = X_sorted[N//2-1:N//2+1]
for xi in X: print(X_med[1] if xi<=X_med[0] else X_med[0])

Submission status: Accepted

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

X_med = X_sorted[N//2-1:N//2+1]
for xi in X:
  if xi <= X_med[0]: print(X_med[1])
  else: print(X_med[0])

Submission status: Accepted

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

X_sort = X_list.copy()
X_sort.sort()

mae_idx = N//2 - 1
ato_idx = N//2

mae_num = X_sort[mae_idx]
ato_num = X_sort[ato_idx]

for x in X_list:
    if x <= mae_num:
        print(ato_num)
    else:
        print(mae_num)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
data = list(map(int, input().split(' ')))
sorteddata = sorted(data)

c1 = sorteddata[N // 2]
c2 = sorteddata[N // 2 - 1]

for i in range(N):
    if (data[i] < c1):
        print(c1)
    else:
        print(c2)

Submission status: Accepted

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

Submission status: Accepted

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

S = sorted(X)
u = S[N // 2]
v = S[N // 2 - 1]

for x in X:
    if x >= u:
        print(v)
    else:
        print(u)

Submission status: Accepted

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

index_hold = np.argsort(x)
index_hold_rev = [0 for i in range(n)]
for i in range(n):
    index_hold_rev[index_hold[i]] = i
for i in range(n):
    if index_hold_rev[i] < n/2:
        print(x[index_hold[int(n/2)]])
    else:
        print(x[index_hold[int(n/2-1)]])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# kakomon toku
import math
import sys
import itertools
import numpy as np

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

y = np.argsort(x)
x = np.sort(x)
#print(y)
a=[0]*n
for i in range(n//2):
    a[y[i]] = 1 # a[]=1ならば前半にいる
#print(a)
for i in range(n):
    if a[i] == 1 :
        print(x[n//2])
    else:
        print(x[n//2-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = input()
x = map(int, raw_input().split())
y = sorted(x)
l, r = y[(n-1)/2], y[(n+1)/2]
print "\n".join([str(r) if (x[i] <= l) else str(l) for i in range(n)])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
x = list(map(int,input().split()))

y = x[:]
y.sort()

left = y[N//2-1]
right = y[N//2]
for i in x:
    if i <= left:
        print(right)
    elif i >= right:
        print(left)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())

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

x = np.array(x)
args = np.argsort(x, kind="quicksort")

mid = int(n/2)
l, r = x[args][mid-1:mid+1]

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

Submission status: Accepted

Solution code:
import copy
N = int(input())
numList = list(map(int, input().split()))
numListCopy = copy.deepcopy(numList)
numList = sorted(numList)
medIndex = int((N)/2)
med1 = numList[medIndex-1]
med2 = numList[medIndex]


for i in range(0,N):
	if numListCopy[i] <= med1:
		print(med2)
	elif med2 <= numListCopy[i]:
		print(med1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

sort_x = sorted(origin_x)

medians = [sort_x[math.floor((n-1)/2)],sort_x[math.floor((n)/2)]]

for num in origin_x:
    if num < medians[1]:
        print(medians[1])
    else:
        print(medians[0])

Submission status: Accepted

Solution code:
n = int(input())
xlist = [int(x) for x in input().split()]
sxlist = sorted(xlist)
mid = sxlist[int(n/2)]
mid2 = sxlist[int(n/2)-1]
for i in range(n):
    if xlist[i] < mid:
        print(mid)
    else:
        print(mid2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def get_values():
    return [int(a) for a in input().split()]

# PROBLEM C
N, = get_values()
Xs = get_values()

Ys = sorted(Xs)
mdx = len(Ys) // 2
x2b = {x:Ys[mdx if idx < mdx else mdx - 1] for idx, x in enumerate(Ys)}
for x in Xs:
    print(x2b[x])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
xsort = sorted(x)
x1, x2 = xsort[n//2-1], xsort[n//2]

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