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 collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回

mod = 10**9 + 7

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

    A = sorted(X)[n//2-1:n//2+1] # 中央値のどちらか
    #print(A)
    for x in X:
        #print(x <= A[0]) # False 0 True 1
        print(A[x <= A[0]]) # 1




if __name__ == '__main__':
  main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

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

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



if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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


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

Submission status: Accepted

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


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

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(b)
  else:
    print(a)

Submission status: Accepted

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

x2list=xlist[:]
x2list.sort()
mid_l=x2list[N//2-1]
mid_r=x2list[N//2]
#print(mid_l,mid_r)

for x in xlist:
  if x<=mid_l:
    print(mid_r)
  else:
    print(mid_l)

Submission status: Accepted

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

# print(X_sort)

middle_left = X_sort[N//2-1]
middle_right = X_sort[N//2]
# print(middle_left, middle_right)

for idx, x in enumerate(X):
    if x <= middle_left:
        print(middle_right)
    elif middle_right <= x:
        print(middle_left)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000)
def resolve():
    N = int(input())
    X = list(map(int, input().split(" ")))
    inputOrder = [{"idx": i, "value": v} for i, v in enumerate(X)]
    valueOrder = sorted(inputOrder, key=lambda x: x["value"])
    for i, v in enumerate(valueOrder):
        v["order"] = i

    for i in range(N):
        # valueOrderからiに対応するidxを持つdictを見つける
        # そのdictのorderがN/2-1より小さければ、valueOrder[N/2-1]を返す
        # 　　　　　　　　　　　　　　　大きければ、valueOrder[N/2]を返す
        o = inputOrder[i]
        if o["order"] < N//2:
            print(valueOrder[N//2]["value"])
        else:
            print(valueOrder[N//2-1]["value"])
        

    
if '__main__' == __name__:
    resolve()

Submission status: Accepted

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

Submission status: Accepted

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

    X_sorted = list(X)
    X_sorted.sort()
    middle = X_sorted[(n+1)//2]
    middle_l = X_sorted[(n+1)//2-1]
    for i in range(n):
        if middle_l==middle:
            print(middle)
        else:
            if X[i]>=middle:
                print(middle_l)
            else:
                print(middle)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

y = sorted(x)
ans = [y[n // 2 - 1], y[n // 2]]
for xi in x:
    if xi > ans[0]:
        print(ans[0])
    else:
        print(ans[1])

Submission status: Accepted

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

xs = sorted(x)
med = dict()
for i, k in enumerate(xs):
  if i < n//2:
    med[k] = xs[n//2]
  else:
    med[k] = xs[n//2 - 1]

for k in x:
  print(med[k])

Submission status: Accepted

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

m = len(l)
lsort = sorted(l)
lmedlow = lsort[int(m/2)]
lmedhigh = lsort[int(m/2)-1]

for i in range (0, m):
	if l[i] < lmedlow:
		print(lmedlow)
	else:
		print(lmedhigh)

Submission status: Accepted

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

Y = sorted(X)

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_L = list(map(int,input().split()))

a_L = list(sorted(x_L))

center_l = a_L[int(n/2)-1]
center_r = a_L[int(n/2)]

for i in x_L:
    if i <= center_l:
        print(center_r)
    elif i >= center_r:
        print(center_l)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
Y = list(enumerate(X))
Y.sort(key=lambda x:x[1])
mid = [Y[N//2-1][1], Y[N//2][1]]
ans = [-1] * N
for i, y in Y:
  if y <= mid[0]:
    ans[i] = mid[1]
  else:
    ans[i] = mid[0]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
list_A = list(map(int, input().split()))
list_S = list_A.copy()
list_S.sort()
left = list_S[n//2-1]
right = list_S[n//2]

for num in list_A:
    if num < right:
        print(right)
    if num > left:
        print(left)
    if num == right and num == left:
        print(num)

Submission status: Accepted

Solution code:
n = int(input())
xs = [int(elem) for elem in input().split()]
sorted_xs = sorted(xs)
base = sorted_xs[(n//2 - 1)]

for i in range(n):
  if xs[i] <= base:
    print(sorted_xs[n//2])
  else:
    print(base)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy
n = int(input())
x = list(map(int, input().split()))
y = copy.deepcopy(x)
y.sort()
mid_bigger = y[int(n/2)]
mid_smaller = y[int(n/2)-1]
ans = [0]*n
for i in range(0,n):
    if (x[i]<mid_bigger):
        ans[i]=mid_bigger
    elif (x[i]>mid_smaller):
        ans[i]=mid_smaller
    elif (mid_smaller == x[i]):
        ans[i] = mid_bigger
    else:
        ans[i] = mid_smaller
print(*ans, sep='\n')

Submission status: Accepted

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

cp = sorted(x, reverse=False)
for i in range(n):
    s = bisect.bisect_left(cp, x[i])
    if s + 1 <= n // 2:
        print(cp[n // 2])
    else:
        print(cp[(n // 2) - 1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

x=[]
for i in range(N):
  x.append(X[i])
x.sort()

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

Submission status: Accepted

Solution code:
import heapq
N = int(input())
A = list(map(int, input().split()))
h = []
for i, num in enumerate(A):
  heapq.heappush(h,(num, i))
sorted_h = [heapq.heappop(h) for i in range(len(h))]
B = []
for i in range(N):
  if(i < (N // 2)):
    heapq.heappush(B, (sorted_h[i][1], sorted_h[((N//2))][0]))
  else:
    heapq.heappush(B,(sorted_h[i][1], sorted_h[((N//2) - 1)][0]))
for i in range(len(B)):
  print(heapq.heappop(B)[1])

Submission status: Accepted

Solution code:

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

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

Submission status: Accepted

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np

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

x = np.array(x)

y = np.sort(x)

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

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

Submission status: Accepted

Solution code:
import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
INF = 1 << 60
sys.setrecursionlimit(10 ** 6)

#ここから書き始める
n = int(input())
x = list(map(int, input().split()))
x_sorted = sorted(x)
left = x_sorted[n // 2 - 1]
right = x_sorted[n // 2]
for i in x:
    if i <= left:
        print(right)
    else:
        print(left)

Submission status: Accepted

Solution code:
# coding: utf-8
n = int(input())

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

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

Submission status: Accepted

Solution code:
from statistics import median

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

mn = median(y[:n-1])
mx = median(y[1:])

for i in x:
  if i <= mn:
    print(mx)
  else:
    print(mn)

Submission status: Accepted

Solution code:
N = int(input())

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

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 i in range(N):
  if X[i] <= l:
    print(r)
  else:
    print(l)

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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:
import math
n = int(input())
x = list(map(int,input().split()))
sums = sum(x)
xsort = sorted(x,reverse=True)
temp = math.ceil((n-1)/2)
if n % 2 == 0:
    medi = xsort[temp]
else:
    medi = xsort[n//2]

medi2 = xsort[temp-1]

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

Submission status: Accepted

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

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[n // 2 - 1]:
        res = xs[n // 2]
    else:
        res = xs[n // 2 - 1]
    print(res)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    center = (n+1)//2
    x_s = list(map(int,input().split()))
    sorted_x_s = sorted(x_s)
    center_num = sorted_x_s[center]

    for i in x_s:
        if i < center_num:
            print(sorted_x_s[center])
        else:
            print(sorted_x_s[center-1])






if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, *xs = map(int, open(0).read().split())
sorted_xs = sorted(xs)
med1 = sorted_xs[n//2]
med2 = sorted_xs[n//2-1]

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

Submission status: Accepted

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

Submission status: Accepted

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

sorted_X=sorted(X)
med1=sorted_X[N//2-1]
med2=sorted_X[N//2]
#print(med1, med2)
for i in range(N):
    if X[i]<=med1:
        print(med2)
    elif X[i]>=med2:
        print(med1)

Submission status: Accepted

Solution code:
n=int(input())
x=[[int(x),i] for i,x in enumerate(input().split())]
ans=[0]*n
x.sort(key=lambda x: x[0])
#print(x)
for i,val in enumerate(x):
    #n-1 is odd pos=(n-1+1)//2
    pos=(n-1)//2
    if i>pos:
        ans[val[1]]=x[pos][0]
    else:
        ans[val[1]]=x[pos+1][0]
for i in ans:
    print(i)

Submission status: Accepted

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

Submission status: Accepted

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

lst2 = sorted(lst)
ans1 = lst2[n//2-1]
ans2 = lst2[n//2]

for i in lst:
    if i<=ans1:
        print(ans2)
    else:
        print(ans1)

Submission status: Accepted

Solution code:
N=int(input())
X= list(map(int,input().split()))
Y=sorted(X,reverse=True) 
#print(X)
large = Y[N//2-1]
small = Y[N//2]

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

#Y=[]
#for i in range(N):
#  Y.append((i,X[i]))
#print(Y)

Submission status: Accepted

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

arr = sorted(x)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

    c_num_list = num_list[:]

    num_list.sort()

    for i in range(n):
        tmp = num_list[n//2]
        if c_num_list[i] >= tmp:
            print(num_list[n//2-1])
        else:
            print(num_list[n//2])
        

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def resolve():
    N=int(input())
    X=list(map(int,input().split()))
    Y=sorted(X)
    l=Y[N // 2-1]
    r=Y[N//2]


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






resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
x = [int(t) for t in input().split()]
d = sorted(x)
m1 = d[n//2-1]
m2 = d[n//2]

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

Submission status: Accepted

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

l=sortx[(N//2)-1]
r=sortx[N//2]

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

Submission status: Accepted

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

for i in range(N):
    if X[i] < c:
        print(c)
    else:
        print(c2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

sort_A = sorted(A)
med_index = (n-2) // 2

for i in A:
    if i <= sort_A[med_index]:
        print(sort_A[med_index+1])
    else:
        print(sort_A[med_index])

Submission status: Accepted

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

Submission status: Accepted

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

b = sorted(a)
big = b[len(b)//2 -1]
small = b[len(b)//2]

for i in a:
    if i <= big:
        print(small)
    else:
        print(big)

Submission status: Accepted

Solution code:
import copy

def Many_Medians(n , xl):

    ans = []
    left = n // 2
    right = n // 2 - 1
    sort_xl = sorted(xl)

    for x in xl:
        if x < sort_xl[left]:
            ans.append(sort_xl[left])
        else:
            ans.append(sort_xl[right])

    return ans

def main():
    n = int(input())
    xl = list(map(int , input().split()))
    ans = Many_Medians(n, xl)
    for i in range(n):
        print(ans[i])

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

S = sorted(X)
ml = S[n//2-1]
mr = S[n//2]
for x in X:
  if x <= ml:
    print(mr)
  else:
    print(ml)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

X.sort()
Y = [0] * N
for j, (x, i) in enumerate(X):
    Y[i] = j

mid = N / 2
l = X[N // 2 - 1][0]
r = X[N // 2][0]
ans = []
for j in Y:
    if j < mid:
        ans.append(r)
    else:
        ans.append(l)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int,input().split()))
sorted_l = sorted(l)
left_med,right_med = sorted_l[int(n/2)-1], sorted_l[int(n/2)]

for i in l:
    if i <= left_med:
        print(right_med)
    
    else:
        print(left_med)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
n//=2
l=list(map(int,input().split()))
sl=sorted(l)
m,h=sl[n-1],sl[n]
print(*[h if i<=sl[n-1] else m for i in l],sep="\n")

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    X = list(map(int, input().split()))
    
    sorted_X = sorted(X)
    mid_l = sorted_X[N // 2 - 1]
    mid_r = sorted_X[N // 2]
    
    for xi in X:
        if xi <= mid_l:
            print(mid_r)
        else:
            print(mid_l)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Y = sorted(X)
c1 = Y[N//2-1]
c2 = Y[N//2]

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
aa = a[:]
sa = list(sorted(a))
upper = sa[n//2]
down = sa[(n//2)-1]
mid = n//2

for i in range(n):
  if aa[i] <= down:
    print(upper)
  else:
    print(down)

Submission status: Accepted

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

B = sorted(A)

median_a = B[n//2 - 1]
median_b = B[n//2]
# print(median_a, median_b)

for i in A:
    if i <= median_a:
        print(median_b)
    else:
        print(median_a)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#pypyは内包表記使わない
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import copy
N=int(input())
X=list(map(int,input().split()))
X2=copy.deepcopy(X)
X2.sort()
upper=X2[N//2]
downer=X2[(N-2)//2]

for i in range(N):
    if X[i]>=upper:
        print(downer)
    elif X[i]<=downer:
        print(upper)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

# 前処理
N = int(input())
points = list(map(int, input().split()))

# 中央 -1 , +1のそれぞれの値x,yを求める
s_points = sorted(points)
x = s_points[int(N/2) - 1]
y = s_points[int(N/2)]

# 二つとも同じ数aなら、N回a出力して終わり
if x == y:
    for _ in range(N): 
        print(x)
    sys.exit()

# それ以外であれば、x<= であればyを、y>= であればxを出力する
for point in points:
    if x >= point:
        print(y)
    else:
        print(x)

Submission status: Accepted

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

x_sort = sorted(x)

med1_ix = n//2-1
med2_ix = n//2

med1 = x_sort[med1_ix]
med2 = x_sort[med2_ix]

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

Submission status: Accepted

Solution code:

N = int(input())

ARR = [int(s) for s in input().split(" ")]

def calculate(n,arr):

    brr = []
    for index,ar in enumerate(arr):
        obj = {}
        obj.__setitem__("index",index)
        obj.__setitem__("value",arr[index])
        brr.append(obj)

    brr = sorted(brr,key=lambda x:x.get("value"))

    dict = {}

    for index,br in enumerate(brr):
        dict.__setitem__(br.get("index"),index)

    midIndexMin = (N - 1) // 2
    midIndexMax =  N // 2
    midIndexMinValue = brr[midIndexMin].get("value")
    midIndexMaxValue = brr[midIndexMax].get("value")

    for index,arr in enumerate(arr):
        m = dict.get(index)
        if m <= n // 2 - 1:
            print(midIndexMaxValue)
        else:
            print(midIndexMinValue)



calculate(N,ARR)

Submission status: Accepted

Solution code:
from statistics import median, median_low, median_high

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

m_l=median_low(l)
m_h=median_high(l)

for i in range(n):
    if l[i] <= m_l:
        print(m_h)
    elif l[i] >= m_h:
        print(m_l)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from copy import deepcopy

N = int(input())
X = list(map(int,input().split()))
Y = deepcopy(X)
Y.sort()
med1 = Y[N//2-1]
med2 = Y[N//2]
##print("med1:",med1,"med2",med2)
for i in range(N):
    if X[i] > med1:
        print(med1)
    else:
        print(med2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# import bisect
# from collections import Counter, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    n = int(input())
    x = list(map(int,ipti().split()))
    x_sorted = sorted(x)

    med_small = x_sorted[n//2 - 1]
    med_big = x_sorted[n//2]

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Y = sorted(X)
med_low = Y[N//2 - 1]
med_high = Y[N//2]

for x in X :
    if x <= med_low :
        print(med_high)
    else :
        print(med_low)

Submission status: Accepted

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

Submission status: Accepted

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

s = sorted(x)

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

Submission status: Accepted

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

S = sorted(X)


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

Submission status: Accepted

Solution code:
import copy
n=int(input())

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

t2 = copy.copy(t1)

t2.sort()

for i in t1:
    if i <= t2[(n//2)-1]:
        print(t2[(n//2)])
    else:
        print(t2[(n//2)-1])

Submission status: Accepted

Solution code:
n = int(input())
x = [int(i) for i in input().split()]
x_ = x.copy()
x_.sort()
b1, b2 = x_[n//2-1], x_[n//2]
for xi in x:
    if xi <= b1: print(b2)
    else: print(b1)

Submission status: Accepted

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

y=sorted(x)

xn=y[n//2-1]
xnp=y[n//2]

for i in range(n):
    if x[i]>xn:
        print(xn)
    else:
        print(xnp)