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_sorted = sorted(X)
X_median = (N)/2
median1 = X_sorted[int(X_median)]
median2 = X_sorted[int(X_median-1)]
for i in range(N):
    if X[i] >=median1:
        print(median2)
    else:
        print(median1)

Submission status: Accepted

Solution code:
numbers=int(input())
list_num=[int(i) for i in input().split()]
sorted_list=sorted(list_num)

median1=sorted_list[int(numbers/2)-1]
median2=sorted_list[int(numbers/2)]

for i in list_num:
    if i <= median1:
        print(median2)
    else:
        print(median1)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
sorted_x = sorted(x)
mid_left = sorted_x[n//2-1]
mid_right = sorted_x[n//2]
for i in range(n):
    mid = mid_left if x[i] >= mid_right else mid_right
    print('{}'.format(mid))

Submission status: Accepted

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

# N = 2
# X = [1, 2]

# N = 6
# X = [5, 5, 4, 4, 3, 3]

# target = int((N-1)/2)
first_m = int(N/2)
second_m = first_m - 1
X_ = sorted(X)
for i in range(N):
    if X[i] <= X_[second_m]: print(X_[first_m])
    else: print(X_[second_m])

Submission status: Accepted

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

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

Submission status: Accepted

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

for num in x:
    if num <= target:
        print(x_sorted[n // 2])
    else:
        print(x_sorted[n // 2 - 1])

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
b=a.copy()
b.sort()

m1=b[int(n/2)-1]
m2=b[int(n/2)]
mm=(m1+m2)/2
for i in a:
  if i<=mm:
    print(m2)
  else:
    print(m1)

Submission status: Accepted

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

for i in range(n):
    if x[i]<y2:
        print(y2)
    else:
        print(y1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
y = sorted(x)
x1, x2 = y[n//2-1], 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()))
y = sorted(x)
N = int(n/2)
x1, x2 = y[N-1], y[N]
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()))
N=int(n/2)
y=sorted(x)
a=y[N-1]
b=y[N]
for j in range(n):
    if x[j]<=a:
        print(b)
    else:
        print(a)

Submission status: Accepted

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

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

for i in range(N):
    if numbers[i] <= small_median:
        print(big_median)
    else:
        print(small_median)

Submission status: Accepted

Solution code:
from statistics import median

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

X_sorted = sorted(X)
X_med = median(X)
for i in range(N):
  if X[i] < X_med:
    res = X_sorted[N // 2]
  elif X_med < X[i]:
    res = X_sorted[N // 2 - 1]
  else:
    res = X[i]

  print(res)

Submission status: Accepted

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

mid = n //2
m1 = a[mid-1]
m2 = a[mid]
for i in range(n):
    if x[i] <= m1:
        ans = m2
    else:
        ans = m1
 
    print(ans)

Submission status: Accepted

Solution code:
n = int(input())
x_str = input().split()
xs = [int(c) for c in x_str]

xs_len = len(xs)
center = (xs_len - 1)//2

c_xs = xs[:]
c_xs.sort()

[print(c_xs[center+1] if x <= c_xs[center] else c_xs[center]) for x in xs]

Submission status: Accepted

Solution code:
n = int(input())
x_str = input().split()
xs = [int(c) for c in x_str]

xs_len = len(xs)
center = (xs_len - 1)//2

c_xs = xs[:]
c_xs.sort()

for x in xs:
    print(c_xs[center+1] if x <= c_xs[center] else c_xs[center])

Submission status: Accepted

Solution code:
def main():
    """
    N=2*10^5
    毎回sortは無理
    sort済みにして計算量を落とす

    元が偶数個なので中央値を考えてsortしたとき
    中央付近には2つ,sort済み値が存在する m1<=m2
    1つ除外したとき
        除外したものがm1以下: 小さい方にずれるのでm2
        除外したものがm2以上: 大きい方にずれるのでm1
    """
    N = int(input())
    *X, = 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:
            ans = m2
        else:
            ans = m1

        print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
C - Many Medians
https://beta.atcoder.jp/contests/abc094/tasks/arc095_a

"""
import sys
from sys import stdin
input = stdin.readline


def solve(N, numbers):
    tmp = numbers[:]
    tmp.sort()
    s = tmp[(N-1)//2]
    l = tmp[N//2]

    ans = []
    for n in numbers:
        if n > s:
            ans.append(s)
        else:
            ans.append(l)
    return ans


def main(args):
    N = int(input())
    numbers = [int(x) for x in input().split()]
    ans = solve(N, numbers)
    print(*ans, sep='\n')


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = a[::]
a.sort()
l, r = n // 2 - 1, n // 2

for bb in b:
    if bb <= a[l]:
        print(a[r])
    else:
        print(a[l])

Submission status: Accepted

Solution code:


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

    nums = sorted(X)
    center = len(nums)//2

    dic = {}
    for i,x in enumerate(nums):
        if x not in dic:
            dic[x] = i

    if len(nums)%2 == 0:
        is_even = True
    else:
        is_even = False

    for x in X:
        i = dic[x]
        if is_even:
            if i < center:
                print(nums[center])
            else:
                print(nums[center-1])
        else:
            print(nums[center+1])


if __name__ == '__main__':
    main()

Submission status: Accepted

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

l=[x[i] for i in range(n)]

l.sort()

small=l[n//2-1]
large=l[n//2]

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

Submission status: Accepted

Solution code:
def main():
    c = int(input()) // 2
    elem = list(map(int, input().split()))
    left, right = sorted(elem)[c - 1:c + 1]
    for val in elem:
        print((left, right)[val <= left])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    c = int(input()) // 2
    elem = list(map(int, input().split()))
    right, left = sorted(elem)[c - 1:c + 1]
    for val in elem:
        print(median(val, right, left))


def median(val, right, left):
    if val <= right:
        return left
    else:
        return right


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    c = int(input()) // 2
    elem = list(map(int, input().split()))
    right, left = sorted(elem)[c - 1:c + 1]
    for val in elem:
        print(median(val, right, left))


def median(val, right, left):
    if right == left:
        return right
    elif val <= right:
        return left
    else:
        return right


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import copy
N = int(input())
X = list(map(int,input().split()))
XX = copy.deepcopy(X)
XX.sort()
X1 = XX[(N//2)-1]
X2 = XX[N//2]
if X1 == X2:
  for i in range(N):
    print(X1)
else:
  Y = float(X1 + X2)
  Y = Y/2
  for i in range(N):
    if X[i] > Y:
      print(X1)
    else:
      print(X2)

Submission status: Accepted

Solution code:
n =  int(input())
ls = list(map(int, input().split()))
sorted_ls = ls.copy()
sorted_ls.sort()
f = sorted_ls[int(n/2)]
b = sorted_ls[int(n/2)-1]

for i in ls:
    if i < f:
        print(f)
    else:
        print(b)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
y = x[:]
y.sort()
medi1, medi2 = y[n//2-1], y[n//2]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
x = map(int, input().split())
temp = sorted(zip(x, range(n)))
ans = [None] * n
for i in range(n):
    idx = n//2
    if i >= idx:
        idx -= 1
    ans[temp[i][1]] = temp[idx][0]
for item in ans:
    print(item)

Submission status: Accepted

Solution code:
#abc094c

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

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
if __name__ == "__main__":
    n = int(input())
    x = [ (number, index) for number, index in zip(list(map(int, input().split())),range(n)) ]
    x.sort(key=lambda tmp:tmp[0])
    indexDic = { index[1]: xindex for index, xindex in zip(x,range(n)) }
    center = int(n/2)
    for tmp in range(n):
        ignoreIndex = indexDic[tmp]
        if ignoreIndex+1 <= center:
            print(x[center][0])
        else:
            print(x[center-1][0])

Submission status: Accepted

Solution code:
def medians(nums, n):
    median_left = nums[(n + 1)//2]
    median_right = nums[(n + 1)//2 - 1]
    return median_left, median_right


if __name__ == '__main__':
    n = int(input())
    nums = list(map(int, input().split()))
    median_left, median_right = medians(sorted(nums), n)
    for i in nums:
        print(median_left) if i < median_left else print(median_right)

Submission status: Accepted

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

median_idx = int(N / 2)
left_num = X_list_copy[median_idx - 1]
right_num = X_list_copy[median_idx]

for x in X_list:
    if x < right_num:
        print(right_num)
    else:
        print(left_num)

Submission status: Accepted

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

# Nを取得
n = int(input())

# Xiを取得
xs = list(map(int, input().split()))

# 昇順にソートしたXiを取得
xs_sorted = sorted(xs)

# Xiの個数およびその1/2の値を取得
l = len(xs_sorted)
l_mid = int(l / 2)

# iが全体の1/2より小さい時、大きい時の中間値をそれぞれ取得
xs_mid_1 = xs_sorted[l_mid - 1]
xs_mid_2 = xs_sorted[l_mid]

# 結果を出力
for x in xs:
    if x < xs_mid_2:
        print("{}".format(xs_mid_2))
    else:
        print("{}".format(xs_mid_1))

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))
Y = [[X[k],k] for k in range(N)]

Y.sort()

A = [0] * N
for k in range(N):
	if k >= N // 2:
		A[Y[k][1]] = Y[N//2-1][0]
	else:
		A[Y[k][1]] = Y[N//2][0]

for x in A:
	print(x)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
Y = [[X[k],k] for k in range(N)]
Y.sort()
A = [0 for k in range(N)]

for k in range(N):
    if k >= N//2:
        A[Y[k][1]] = Y[N//2-1][0]
    else:
        A[Y[k][1]] = Y[N//2][0]

for x in A:
    print(x)

Submission status: Accepted

Solution code:
import copy

n = int(input())
x = list(map(int, input().split()))
x_sort = copy.deepcopy(x)
x_sort.sort()

center_a = x_sort[int(n / 2) - 1]
center_b = x_sort[int(n / 2)]

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    X = [int(i) for i in input().split()]
    
    sorted_X = sorted(X)
    median_1 = sorted_X[int(N/2)-1]
    median_2 = sorted_X[int(N/2)]
    
    for i in range(N):
        remove_num = X[i]
        if(remove_num > median_1):
            print(median_1)
        else:
            print(median_2)
    
if __name__=="__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

sorted_x = sorted(x)
b1,b2 = sorted_x[n//2-1], sorted_x[n//2]
for item in x:
    if item <= b1:
        print(b2)
    else:
        print(b1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import numpy as np

N=int(input())

X=np.array(list(map(int,input().split())))
temp=X
temp=np.sort(temp,kind="quicksort")
med=temp[int(N/2)]
for i in range(N):
	if X[i]<med:
		print(med)
	else:
		print(temp[int(N/2)-1])

Submission status: Accepted

Solution code:
N = int(input().strip())
X = list(map(int,input().strip().split(' ')))
sorted_X = sorted(X)
med_l=sorted_X[int(N/2-1)]
med_r=sorted_X[int(N/2)]
for iX in X:
    if iX <= med_l:
        print(med_r)
    elif med_r <= iX:
        print(med_l)

Submission status: Accepted

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

min_mid = sx[int(n/2-1)]
max_mid = sx[int(n/2)]

for i in x:
    if i <= min_mid:    # 左半分から取られてる時
        print(max_mid)
    else:               # 右半分から取られてる時
        print(min_mid)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
length = int(raw_input())
li = list(map(int,raw_input().split()))
li_sort = sorted(li)
if li_sort[length/2] == li_sort[length/2-1]:
    for i in range(length):
        print li_sort[length/2]
else:
    for i in li:
        if i <= li_sort[length/2-1]:
            print li_sort[length/2]
        else:
            print li_sort[length/2-1]

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

center = (len(xs) - 1)//2

c_xs = xs[:]
c_xs.sort()

if c_xs[center] == c_xs[center+1]:
    for x in xs:
        print(c_xs[center])
else:
    for x in xs:
        if x <= c_xs[center]:
            print(c_xs[center+1])
        else:
            print(c_xs[center])

Submission status: Accepted

Solution code:

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

xs_len = len(xs)
center = (xs_len - 1)//2

c_xs = xs[:]
c_xs.sort()

for x in xs:
    print(c_xs[center+1] if x <= c_xs[center] else c_xs[center])

Submission status: Accepted

Solution code:

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

xs_len = len(xs)
center = (xs_len - 1)//2

c_xs = xs[:]
c_xs.sort()

for x in xs:
    if x <= c_xs[center]:
        print(c_xs[center+1])
    else:
        print(c_xs[center])

Submission status: Accepted

Solution code:

import numpy as np

n = int(input())
x_str = input().split()
xs = np.array([int(c) for c in x_str])

xs_len = len(xs)
center = (xs_len - 1)//2

c_xs = np.sort(xs)

for x in xs:
    if x <= c_xs[center]:
        print(c_xs[center+1])
    else:
        print(c_xs[center])

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N = int(input())
    X = list(map(int, input().split()))
    x = sorted(X[:])
    min_median = x[int(N/2-1)]
    max_median = x[int(N/2)]
    for i in range(N):
        if X[i] <= min_median:
            print(max_median)
        else:
            print(min_median)

Submission status: Accepted

Solution code:
n = int(input())
x = [int(i) for i in input().split()]
y = []
for i in range(n):
	y.append([x[i],i+1])
y.sort()
a,b = y[n//2][0],y[(n-2)//2][0]
for i in range(len(y)//2):
	y[i][0],y[i][1] = y[i][1],a
for i in range(len(y)//2,n):
	y[i][0],y[i][1] = y[i][1],b
y.sort()
for i in y:
	print(i[1])

Submission status: Accepted

Solution code:
#coding: utf-8                                    
import math                                       
                                                  
N = int(input())                                  
original_list = [int(i) for i in input().split()] 
sorted_list = sorted(original_list)               
min_midian = sorted_list[int(N / 2) - 1]          
max_midian = sorted_list[int(N / 2)]              
                                                  
for i in range(N):                                
  if min_midian >= original_list[i]:              
    print(max_midian)                             
  else:                                           
    print(min_midian)

Submission status: Accepted

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

Submission status: Accepted

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

candidates = sorted(x)[n//2-1:n//2+1]

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

Submission status: Accepted

Solution code:
def c_many_medians(N, X):
    Y = sorted(X)
    ans = []
    for xi in X:  # 数列から除く要素を選定
        # 中央値の候補はYの N//2 - 1 番目または N//2 番目
        # 除かれた要素がYの N//2 番目より小さければ中央値は N//2 番目
        # (Yにおけるxiより"右"の要素がすべて"左"に1つずれるため)
        # そうでなければ中央値は N//2 - 1 番目
        # (Yにおけるxiより右の要素が左にずれても中央値の要素番号に影響しない)
        pos = N // 2 if xi < Y[N // 2] else (N // 2) - 1
        ans.append(str(Y[pos]))
    return '\n'.join(ans)

N = int(input())
X = [int(i) for i in input().split()]
print(c_many_medians(N, X))

Submission status: Accepted

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

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

lis = sorted(a)
high_med = lis[int(n/2)]
low_med = lis[int(n/2-1)]
if high_med == low_med:
    for _ in range(n):
        print(high_med)
else:
    for v in a:
        if v < high_med:
            print(high_med)
        else:
            print(low_med)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
x = [int(i) for i in input().split()]
sortedx = sorted(x)
r = sortedx[n//2]
l = sortedx[n//2-1]

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

Submission status: Accepted

Solution code:


n = int(input())

number_list = list(map(int,input().split()))
tmp_list = sorted(number_list)


for number in number_list:
    if number < tmp_list[n//2]:
        print(tmp_list[n//2])
    else :
        print(tmp_list[n//2-1])

Submission status: Accepted

Solution code:
import bisect

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

for i in X:
    index = bisect.bisect_left(X_sorted, i)
    # print(index)
    if index <= N / 2 - 1:
        print(X_sorted[int(N / 2)])
    else:
        print(X_sorted[int(N / 2) - 1])

Submission status: Accepted

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

Submission status: Accepted

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

sort_x = X.copy()
sort_x.sort()

nn = N//2
low_ = sort_x[nn-1]
high_ = sort_x[nn]

for x in X:
	if x < high_:
		print(high_)
	else:
		print(low_)

Submission status: Accepted

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

nn=n//2
y=x[:]
x.sort()
low_median=x[nn-1]
high_median=x[nn]

[print(high_median) if y[i]<high_median  else print(low_median)  for i in range(n) ] 

"""
for i in range(n):
  if y[i]<high_median:
    print(high_median)
  else:
    print(low_median)
"""

Submission status: Accepted

Solution code:
n=int(input())
nn=n//2
x=[int(i) for i in input().split()]
y=x[:]
x.sort()
 
low_median=x[nn-1]
high_median=x[nn]
 
for i in range(n):
  if y[i]<high_median:
    print(high_median)
  else:
    print(low_median)

Submission status: Accepted

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

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    n = int(input())
    x = list(map(int, input().split()))
    sorted_x = sorted(x)

    low = sorted_x[(n // 2) - 1]
    high = sorted_x[(n // 2)]

    for i in range(n):
        if x[i] < high:
            print(high)
        else:
            print(low)

Submission status: Accepted

Solution code:
def m():
    N = int(input())
    X = [int(x) for x in input().split()]
    XX = [x for x in X]
    XX.sort()
    first = XX[N//2]
    second = XX[N//2 -1]
    for x in range(N):
        if X[x] <= second:
            print(first)
        else:
            print(second)


m()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
X = [int(i) for i in input().split()]
Y = sorted(X)
for i in range(N):
    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:
n = int(input())
x = list(map(int, input().split()))

sortedx = x[:]
sortedx.sort()

for i in range(n):
    #ix = sortedx.index(x[i])
    #print(sortedx)
    #print(ix)
    if x[i] <= sortedx[n//2-1]:
        print(sortedx[n//2])
    else:
        print(sortedx[n//2-1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

y = sorted(x)

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

Submission status: Accepted

Solution code:
from statistics import median, median_low, median_high


N = int(input())

X = input().split()
X = [ int(x) for x in X]
"""
N = 4
X = [2,4,4,3]
"""
median = median(X)
#F = copy.deepcopy(X)
"""
F = X[:]
F.sort()

median1 = int(N/2 - 1)
median2 = int(N/2) 

if median.is_integer():
    median1 = median
    median2 = median
else:
    median1 = median - 0.5
    median2 = median + 0.5
"""
median1 = median_low(X)
median2 = median_high(X)
   
for i in range(N):
    #print(F, median1, median2)
    
    if X[i] < median:
        ans = median2
    else:
        ans = median1
    print(int(ans))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import copy
N = int(input())
X = [int(x) for x in input().split()]
Y = copy.copy(X)
X.sort()  #ソートした

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

Submission status: Accepted

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

list_size = int(input())
num_list = [int(i) for i in input().split()]
# 昇順ソート
num_list2 = sorted(num_list)
# 中央値候補
center_left = num_list2[int(list_size / 2) - 1]
center_right = num_list2[int(list_size / 2)]

for i in range(list_size):
	# 除く値が左寄り(小さい)なら右、右寄り(大きい)なら左
	if num_list[i] <= center_left:
		print(center_right)
	else:
		print(center_left)

Submission status: Accepted

Solution code:
def c_many_medians(N, X):
    # 解説どおり
    Y = sorted(X)
    ans = ['' for _ in range(N)]
    pos = N // 2
    for k, xi in enumerate(X):
        if xi < Y[pos]:
            ans[k] = str(Y[pos])
        else:
            ans[k] = str(Y[pos - 1])
    return '\n'.join(ans)

N = int(input())
X = [int(i) for i in input().split()]
print(c_many_medians(N, X))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
x = [int(x) for x in input().split()]
y = sorted(x)
l = y[len(x)//2-1]
r = y[len(x)//2]

for xi in x:
    if xi < r: print(r)
    else: print(l)

Submission status: Accepted

Solution code:
n = int(input())

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

soredx = sorted(x)

migi = soredx[int(n/2-1)]
hidari = soredx[int(n/2)]

for i in range(n):
    if(migi<x[i]):
        print(migi)
    else:
        print(hidari)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy

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

m = sortedx[int((n+1)/2)]

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

Submission status: Accepted

Solution code:
N = input()
N = int(N)
A = input()
array = A.split()
ind = 0
for n in array:
    array[ind] = int(n)
    ind = ind+1

sortedarray = sorted(array)

be = sortedarray[(N//2-1)]
af = sortedarray[N//2]
for flag in array:
    if flag <= be:
        print(af)
    else: print(be)

Submission status: Accepted

Solution code:
import copy

N = int(input())
X = [int(i) for i in input().split()]
tmp = copy.deepcopy(X)

X = sorted(X)
for i in range(N):
    ans1 = X[int(len(X)/2)]
    ans2 = X[int(len(X)/2)-1]
    if tmp[i] < ans1:
        print(ans1)
    else:
        print(ans2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(raw_input())
nums = map(int, raw_input().split())
num_tmp = []
for a in nums:
    num_tmp.append(a)
nums.sort()
med_1 = nums[N/2 - 1]
med_2 = nums[N/2]
for i in range(N):
    if num_tmp[i] <= med_1:
        print(med_2)
    elif num_tmp[i] >= med_2:
        print(med_1)

Submission status: Accepted

Solution code:
def main():
    n=int(input())
    x = [int(i) for i in input().split()]
    x_t = tuple(x)
    x.sort()
    l = x[int((len(x)/2 - 1))]
    u = x[int((len(x)/2))]
    for i in range(len(x_t)):
        if (x_t[i]<=l):
            print(u)
        else:
            print(l)
            
main()

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
sX = sorted(X)
mid = N // 2 - 1

for x in X:
    if sX[mid] >= x:
        print(sX[mid + 1])
    else:
        print(sX[mid])

Submission status: Accepted

Solution code:
n = int(input())
x =[int(i) for i in input().split()]
c = n//2 - 1
y = x.copy()
y.sort()

for i in range(0,n):
    if y[c] >= x[i]:
        print(y[c+1])
    else:
        print(y[c])

Submission status: Accepted

Solution code:
import numpy as np

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

a=np.sort(X)
n=len(X)//2

an_1=a[n-1]
an=a[n]

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

Submission status: Accepted

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

for i in range(n):
    if x[i] <= m_left:
        print(m_right)
    elif x[i] >= m_right:
        print(m_left)

Submission status: Accepted

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

save = X[:]

save.sort()

midL = save[int(N / 2 - 1)]
midR = save[int(N / 2)]

for i in X:
    if i <= midL:
        print(midR)
    else:
        print(midL)

Submission status: Accepted

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

y = copy.copy(x)
x.sort()
l = len(x)
m0 = x[int(l/2 - 1)]
m1 = x[int(l/2)]


for i in y:
    if i <= m0:
        print(m1)
    else:
        print(m0)