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

ls_s = sorted(ls)
md = (ls_s[int(n/2) - 1] + ls_s[int(n/2)]) / 2

for i in range(n):
    if ls[i] <= md:
        print(ls_s[int(n/2)])
    elif ls[i] > md:
        print(ls_s[int(n/2) - 1])

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N=int(input())
X=list(map(int,input().split()))
A=sorted(X)
mid1=A[N//2-1]
mid2=A[N//2]
for i in range(N):
    if X[i]<=mid1:
        print(mid2)
    else:
        print(mid1)

Submission status: Accepted

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

m1 = xx[n//2-1]
m2 = xx[n//2]

# print(m1, m2)

for i in range(len(x)):
    if x[i] < m1:
        print(m1)
    elif x[i] >= m1:
        print(m2)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
Xs = list(map(int, input().split()))
sXs = sorted(Xs)
m1 = sXs[N//2]     # 前半のメジアン (i<=m1)
m2 = sXs[N//2 - 1] # 後半のメジアン
# print(m1,m2)
if m1 == m2:
    for i in range(N):
        print(m1)
else:
    for x in Xs:
        if x <= m2:
            print(m1)
        else:
            print(m2)

Submission status: Accepted

Solution code:
N = int(input())
X = [[-1*float("inf"),0]] + [[int(inp),i] for inp,i in zip(input().split(), range(1,N + 1))]

from operator import itemgetter

def main():
    X.sort(key = itemgetter(0))
    med = N // 2
    Ans = [-1]*(N+1)
    for XX,i in zip(X[1:],range(1,N+1)):
        index = XX[1]
        if i <= med:
            Ans[index] = X[med + 1][0]
        else:
            Ans[index] = X[med][0]
    print(*Ans[1:],sep="\n")


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

sorted_x = sorted(x)
r = sorted_x[n//2]
l = sorted_x[n//2-1]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from copy import copy
N = int(input())
X = [int(i) for i in input().split()]
X2 = copy(X)
X2.sort()
n = [X2[N//2-1], X2[N//2]]
for x in X:
    if x <= n[0]:
        print(n[1])
    else:
        print(n[0])

Submission status: Accepted

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


def solve(N: int, X: "List[int]"):
    Y = sorted(X)
    me1 = Y[N//2]
    me2 = Y[N//2-1]

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

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, X)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

for a in A:
  if a<r:
    print(r)
  else:
    print(l)

Submission status: Accepted

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

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

for a in A:
  if a<=l:
    print(r)
  else:
    print(l)

Submission status: Accepted

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

Submission status: Accepted

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

nx = sorted(x)
a = nx[n//2]
b = nx[n//2-1]

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

Submission status: Accepted

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

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

for i in range(n):
    ans = x[n//2][1] if i < n//2 else x[n//2-1][1]
    x[i].append(ans)

x.sort(key= lambda x:x[0])

for i in range(n):
    print(x[i][2])

Submission status: Accepted

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

xs=sorted(x)
a=xs[n//2]
b=xs[(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())
x = [int(i) for i in input().split()]
xs = sorted(x)
d = dict()
for i in range(n):
  if xs[i] not in d:
    d[xs[i]] = i
for i in range(n):
  print(xs[n // 2 - int(d[x[i]] >= n // 2)])

Submission status: Accepted

Solution code:
import sys

n, *x = map(int, sys.stdin.read().split())

def main():
    y = sorted(x)
    r = y[n // 2]
    l = y[n // 2 - 1]
    
    for i in range(n):
        if x[i] <= l:
            yield r
        else:
            yield l

if __name__ == '__main__':
    ans = main()
    print(*ans, sep='\n')

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Asort = sorted(A)

min_ans = Asort[n//2-1]
max_ans = Asort[n//2]

if (min_ans == max_ans):
    for a in A:
        print(min_ans)
else:
    for a in A:
        if (min_ans >= a):
            print(max_ans)
        else:
            print(min_ans)

Submission status: Accepted

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

    sortedIdx = sorted(list(range(N)), key=lambda k: X[k])

    midrIdx = N // 2
    midrVal = X[sortedIdx[midrIdx]]
    midlIdx = N // 2 - 1
    midlVal = X[sortedIdx[midlIdx]]

    ans = [-1] * N
    for i in range(N):
        if i <= midlIdx:
            ans[sortedIdx[i]] = midrVal
        else:
            ans[sortedIdx[i]] = midlVal
    
    print(*ans, sep="\n")
if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    X = LI()
    ans = [0] * N
    sorted_X = sorted([(x, i) for i, x in enumerate(X)], key=lambda x: x[0])
    l = sorted_X[N//2 - 1][0]
    r = sorted_X[N//2][0]
    for i, (x, org_ix) in enumerate(sorted_X):
        if i < N//2:
            _ans = r
        else:
            _ans = l
        ans[org_ix] = _ans
    for a in ans:
        print(a)
main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
from collections import Counter
from itertools import accumulate
n = int(input())
x_ls = [int(i) for i in sys.stdin.readline().split()]
sorted_x_ls = sorted(x_ls)
ct = Counter(x_ls)
acc = dict()
_sum = 0
for k, v in sorted(ct.items(), key=lambda x:x[0]):
    _sum += v
    acc[k] = _sum

for i, x in enumerate(x_ls):
    if acc[x] <= n // 2:
        print(sorted_x_ls[n // 2])
    else:
        print(sorted_x_ls[n // 2 - 1])

Submission status: Accepted

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

a = sorted(X)
mid = N // 2 - 1

for i in range(N):
    if X[i] <= a[mid]:
        ans = a[mid + 1]
    else:
        ans = a[mid]
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))
XY = [[i+1,X[i],0] for i in range(N)]
XY.sort(key=lambda x:x[1],reverse=True)
m2 = XY[N//2][1]
m1 = XY[N//2-1][1]
for i in range(N):
  if (i+1) <= N//2:
    XY[i][2] = m2
  else:
    XY[i][2] = m1
XY.sort(key=lambda x:x[0])
for i in range(N):
  print(XY[i][2])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC094C - Many Medians (ARC095C)
def main():
    n = int(input())
    x = list(map(int, input().split()))
    # 偶数個の数から一つ数を取り除いたものの中央値はl,hのいずれか.
    l, h = sorted(x)[n // 2 - 1 : n // 2 + 1]
    ans = [h if e <= l else l for e in x] # l以下の値を取り除いたならば中央値はh
    print("\n".join(map(str, ans)))
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())

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

Y = sorted(X)
p = Y[n // 2 - 1]
q = Y[n // 2 ]

for i in range(0, n):
	if X[i] <= p:
		print(q)
	else:
		print(p)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
X = list(map(int, input().split()))
D = []
for i, x in enumerate(X):
    D.append([x, i])
D.sort()
l = len(X)

left = D[l//2-1][0]
right = D[l//2][0]

ans = [0] * n
for i in range(n):
    idx = D[i][1]
    if i <= l//2-1:
        ans[idx] = right
    else:
        ans[idx] = left

for a in ans:
    print(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# O(N * log(Xn))
from bisect import bisect_left
import sys
readline = sys.stdin.readline
N = int(readline())
X = [int(x) for x in readline().split()]

# X = [i for i in range(2*10**5)]
# N = len(X)

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
import numpy as np
N = int(input())
X = np.array([int(x) for x in input().split()])
Y = np.sort(X)
right = N // 2
left = right - 1
right, left = Y[right], Y[left]
for i in range(N):
    if X[i] <= left:
        print(right)
    else:
        print(left)

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 // 2] if x[i] <= y[n // 2 - 1] else y[n // 2 - 1])

Submission status: Accepted

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

Submission status: Accepted

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

l=len(x)
c1=xx[l//2-1]
c2=xx[l//2]

for i in range(n):
    if x[i] > c1:
        print(c1)
    else:
        print(c2)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline

n = int(input())
x = list(map(int,input().split()))
x_vi = [(v,i) for i,v in enumerate(x)]
x_vi.sort()
medl = x_vi[n//2-1][0]
medr = x_vi[n//2][0]
ret_median = [0 for _ in range(n)]
for sort_idx,vi in enumerate(x_vi):
    if sort_idx < n//2:
        ret_median[vi[1]]=medr
    else:
        ret_median[vi[1]]=medl
for i in ret_median:
    print(i)

Submission status: Accepted

Solution code:
N = int(input())
li = list(map(int,input().split()))
lia = li[:]
lia.sort()
index1 = int(N/2)
index2 = int((N-2)/2)
ave1 = lia[index2]
ave2 = lia[index1]
for i in range(N) :
    if li[i] <= ave1 :
        print(ave2)
    else :
        print(ave1)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
sortedx = sorted(x)
mid = n // 2 - 1

for i in x:
    if i <= sortedx[mid]:
        print(sortedx[mid + 1])
    else:
        print(sortedx[mid])

Submission status: Accepted

Solution code:
#many medians
n=int(input())
B=list(map(int,input().split()))
C=B.copy()
B=sorted(B)
median1=B[n//2]
median2=B[n//2-1]
if median1==median2:
    for _ in range(n):
        print(median1)
elif median1>median2:
    for i in range(n):
        if C[i]>=median1:
            print(median2)
        else:
            print(median1)

Submission status: Accepted

Solution code:
import numpy as np

N=int(input())
X=list(map(int, input().split()))
Xs=np.array([[X[i], i] for i in range(N)])
Xs=Xs[np.argsort(Xs[:, 0]), :]
p=Xs[N//2, 0]
pi=Xs[N//2, 1]
q=Xs[N//2-1, 0]
for i in range(N):
  if X[i]<p:
    print(p)
  elif X[i]>p:
    print(q)
  else:
    if i<pi:
      print(p)
    else:
      print(q)

Submission status: Accepted

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

X2 = sorted(X)

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

for x in X:
    if x <= m_l:
        print(m_r)
    else:
        print(m_l)

Submission status: Accepted

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()
X=many_int()

sort_X=sorted(X)

med_min1 = sort_X[(len(sort_X)//2)-1]
med_plus1 = sort_X[(len(sort_X)//2)]


for i in X:
    if i >= med_plus1:
        print(med_min1)
    else:
        print(med_plus1)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding: utf-8
N = int(input())
X = list(map(int, input().split()))
sorted_X = sorted(X)
one = sorted_X[N//2]
two = sorted_X[N//2-1]
for i in range(N):
    if X[i] < one:
        print(one)
    else:
        print(two)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))
sx = sorted(X,reverse=True)
med1 = sx[int(N/2)-1]
med2 = sx[int(N/2)]
ans = []
for x in X:
    if x >= med1:
        ans.append((med2))
    else:
        ans.append((med1))
print(*ans)

Submission status: Accepted

Solution code:
import copy

import numpy as np


def main():
    N = int(input())
    X = np.array(list(map(int, input().split())))
    m = np.median(X)

    XX = copy.deepcopy(X)
    mm = np.argmin(X)
    XX = np.delete(XX, mm)
    m0 = int(np.median(XX))

    XX = copy.deepcopy(X)
    mm = np.argmax(X)
    XX = np.delete(XX, mm)
    m1 = int(np.median(XX))

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


main()

Submission status: Accepted

Solution code:
N = int(input())
X = [int(i) for i in input().split()]
X_sort = sorted(X)
for i in range(N):
    if X[i] < X_sort[N // 2]:
        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()))
x2 = sorted(x)
median_index = len(x2) // 2
median = x2[median_index]
cnt = x2.count(median_index)
for i in range(n):
    if x[i] >= median:
        print(x2[median_index - 1])
    else:
        print(x2[median_index])

Submission status: Accepted

Solution code:
import sys
import copy
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()

# print(A)
med = N//2

B = copy.deepcopy(A)
B.sort()
l_m = B[med-1]
h_m = B[med]

for a in A:
	if a > l_m:
		print(l_m)
	else:
		print(h_m)

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import statistics
N = int(input())
X = list(map(int,input().split()))
y = statistics.median(X)
yl = statistics.median_low(X)
yh = statistics.median_high(X)
for x in X:
  if x>y:
    print(yl)
  if x<=y:
    print(yh)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

mid_1 = X_sort[int(n/2) -1]
mid_2 = X_sort[int(n/2)]

for x in X:
    if x <= mid_1:
        print(mid_2)
    else:
        print(mid_1)

Submission status: Accepted

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

Submission status: Accepted

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

sx = sorted(X)
mid1 = sx[N//2-1]
mid2 = sx[N//2]

if mid1 == mid2:
    print(*[mid1]*N, sep='\n')
else:
    for i in range(N):
        if X[i] <= mid1:
            print(mid2)
        else:
            print(mid1)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
X = list(map(int, input().split()))
X_sorted = sorted(X)
L = X_sorted[N//2-1]
R = X_sorted[N//2]


for x in X:
    print(L if x >= R else R)

Submission status: Accepted

Solution code:
'''
　 ∧_,,∧    究極奥義「WAがACになーれ！！」
　（`・ω・)つ━☆・*。
　⊂　　 ノ 　　　・゜+.
　 し’´Ｊ　　*・ 
'''
import sys
input = sys.stdin.readline
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:
N = int(input())
X = list(map(int,input().split()))
Y = sorted(X)
midL = Y[N//2-1]
midH = Y[N//2]
for i in range(N):
    if X[i]<midH:
        print(midH)
    else: print(midL)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

medL=nXs[len(nXs)//2-1]
medR=nXs[len(nXs)//2]

if medL == medR:
    for i in range(N):
        print(medL)
else:
    for i in Xs:
        if i<=medL:
            print(medR)
        else:
            print(medL)

Submission status: Accepted

Solution code:
def examC():
    N = I()
    x = LI(); num = [i for i in range(N)]
    X = list(zip(x,num)); X.sort()
    ans = [0]*N
    mid0 = X[(N)//2-1][0]; mid1 = X[(N)//2][0]
    for i in range(N):
        if X[i][0]<mid1:
            ans[X[i][1]] = mid1
        else:
            ans[X[i][1]] = mid0
    for v in ans:
        print(v)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

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

Submission status: Accepted

Solution code:
import bisect
N = int(input())
lst = list(map(int, input().split()))
lst1 = sorted(lst)
x1 = lst1[N//2-1]
x2 = lst1[N//2]

for i in range(N):
    if bisect.bisect_right(lst1, lst[i]) <= N//2:
        print(x2)
    else:
        print(x1)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
X = LIST()
sorted_X = sorted(X)
kouho1 = sorted_X[N//2-1]
kouho2 = sorted_X[N//2]
for i in range(N):
	if X[i] <= kouho1:
		print(kouho2)
	else:
		print(kouho1)

Submission status: Accepted

Solution code:
n = int(input())
li = list(map(int,input().split()))
L = sorted(li)

a = L[n//2-1]
b = L[n//2]

for i in range(n):
    if li[i]<=a:
        print(b)
    elif li[i] >=b:
        print(a)

Submission status: Accepted

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

sorted_xl = sorted(xl)
front = sorted_xl[n//2 - 1]
back = sorted_xl[n//2]

for x in xl:
    if x <= front:
        print(back)
    else:
        print(front)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from statistics import median
N = int(input())
X = [int(i) for i in input().split()]
sort_X = sorted(X)
sort_X = sort_X[N//2-1:N//2+1]
for x in X:
    if sort_X[0] >= x:
        print(sort_X[1])
    else:
        print(sort_X[0])

Submission status: Accepted

Solution code:
n = int(input())
*l, = map(int, input().split())

p, q = sorted(l)[n//2-1 : n//2+1]
for _l in l:
    print(p if _l >= q else q)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
p, q = sorted(A)[N//2-1: N//2+1]
for a in A: print(p if a>=q else q)

Submission status: Accepted

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

X = []
for i, a in enumerate(A):
    X.append([a, i])

X.sort()

# Biになり得るのはX[m-1] or X[m] (m=N//2)
m = N//2
itoj = {}
for j in range(N):
    x, i = X[j]
    itoj[i] = j
for i in range(N):
    j = itoj[i]
    if j < m:
        print(X[m][0])
    else:
        print(X[m-1][0])

Submission status: Accepted

Solution code:
n=int(input())
X=list(map(int,input().split()))
L=[]
for i in range(n):
    l=[i,X[i]]
    L.append(l)
LS=sorted(L,key=lambda x:x[1])
LSM=[0]*n
for i in range(n):
    if i<n//2:
        LSM[LS[i][0]]=LS[n//2][1]
    else:
        LSM[LS[i][0]]=LS[n//2-1][1]
for i in range(n):
    print(LSM[i])

Submission status: Accepted

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

sorted_X = sorted(X)

left_med = sorted_X[N//2 -1]
right_mid = sorted_X[N//2]

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=[0]*n
    for i,x in enumerate(map(int,input().split())):
        A[i]=[x,i]
    A.sort()

    l=A[n//2-1][0]
    h=A[n//2][0]
    for i in range(n//2):
        A[i][0]=h
    for i in range(n//2):
        A[n//2+i][0]=l

    A.sort(lambda x:x[1])
    for i in range(n):
        print(A[i][0])
resolve()

Submission status: Accepted

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

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

x_sorted=sorted(x)
c = (x_sorted[n//2-1]+x_sorted[n//2])/2

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

Submission status: Accepted

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

if N==2:
    print(X[-1])
    print(X[0])
else:
    sortedX=sorted(X)
    num=N//2-1
    for x in X:
        if x<=sortedX[num]:print(sortedX[num+1])
        else:print(sortedX[num])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
import numpy as np
import statistics


n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
lin = sorted(li)
ni = lin[n//2]
iti = lin[n//2-1]

for i in range(n):
    if li[i] <= iti:
        print(ni)
    else:
        print(iti)

Submission status: Accepted

Solution code:
n = int(input())
list_x = list(map(int, input().split()))
sub_list = sorted(list_x)

a = sub_list[n // 2]
b = sub_list[n // 2 - 1]

for one_x in list_x:
  if one_x <= b:
    print(a)
  else:
    print(b)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
X = [int(x) for x in input().split()]
X_ = sorted(X, reverse=True)
mid1 = X_[N // 2 - 1]
mid2 = X_[N // 2]
for x in X:
  if x >= mid1:
    print(mid2)
  else:
    print(mid1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

afters = [0 for _ in range(N)]
after_x_dict = {}
for after, (before, x) in enumerate(sorted(list(enumerate(X)), key=lambda x:x[1])):
    afters[before] = after
    after_x_dict[after] = x

threshold = N//2 - 1
for i in range(N):
    if  afters[i] <= threshold:
        print(after_x_dict[threshold+1])
    else:
        print(after_x_dict[threshold])