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()))

Xsorted=sorted(X)

ans1=Xsorted[(N-1)//2]
ans2=Xsorted[(N-1)//2+1]

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

Submission status: Accepted

Solution code:
import collections

N=int(input())

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

B_dict=collections.Counter(X)
B=sorted(B_dict.items())

cnt=0
for i in range(len(B)):
    cnt+=B[i][1]
    if cnt==N//2:
        ans1=B[i][0]
        ans2=B[i+1][0]
        break
    elif cnt>=N//2+1:
        ans1=B[i][0]
        ans2=B[i][0]
        break


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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

X2 = sorted(XList)
a1 = X2[N//2-1]
a2 = X2[N//2]
# a1 < b < b2 なる数は存在しない

for b in XList:
    if b <= a1:
        print(a2)
    elif b >=a2:
        print(a1)
    else:
        print('ERROR')

Submission status: Accepted

Solution code:
import copy

N=int(input())
X=list(map(int,input().split()))
Y=copy.deepcopy(X)
X.sort()
x1,x2=X[N//2-1],X[N//2]

for i in Y:
  print(x1 if i>=x2 else x2)

Submission status: Accepted

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

xs = sorted(x)
med_left = xs[n//2-1]
med_right = xs[n//2]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

XX = list(tuple(X))
XX.sort()
X_medium_1 = XX[(N//2)-1]
X_medium_2 = XX[N//2]

for n in range(N):
  if X[n] <= X_medium_1:
    print(X_medium_2)
  else: # X[n] >= X_medium_2:
    print(X_medium_1)

Submission status: Accepted

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

sorted_A = sorted(A)

left_med = sorted_A[(N-1)//2]
right_med = sorted_A[(N+1)//2]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC094 C - Many Medians
n = int(input())
x = list(map(int,input().split()))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC094C - Many Medians (ARC095C)
def main():
    N, *X = map(int, open(0).read().split())
    l, h = sorted(X)[N // 2 - 1 : N // 2 + 1]
    ans = [h if i <= l else l for i in X]
    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ABC094C - Many Medians (ARC095C)
def main():
    N, *X = map(int, open(0).read().split())
    l, h = sorted(X)[N // 2 - 1 : N // 2 + 1]
    ans = [h if i <= l else l for i in X]
    print(*ans, sep="\n")


if __name__ == "__main__":
    main()

Submission status: Accepted

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

def main():
    N = int(input())
    X = list(map(int, input().split()))
    Y = X.copy()
    Y.sort()
    m1 = Y[N//2-1]
    m2 = Y[N//2]
    for x in X:
        if x <= m1:
            print(m2)
        elif x >= m2:
            print(m1)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
Y = sorted(X)
m1 = Y[N//2 - 1] #小さい方の中央値候補
m2 = Y[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()))
sorted_x = sorted(x)

lmid = sorted_x[n // 2 - 1]
rmid = sorted_x[n // 2]

for xi in x:
    if xi <= lmid:
        print(rmid)
    else:
        print(lmid)

Submission status: Accepted

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

ans = []

for a in x:
  if a >= i2:
    ans.append(i1)
  else:
    ans.append(i2)
    
print(*ans, sep='\n')

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
n=int(input())
x=list(map(int,input().split()))
y=sorted(x)
mid1=y[(n//2)-1]
mid2=y[n//2]
if mid1==mid2:
  for j in range(n):
    print(mid1)
  sys.exit()
for i in range(n):
  if x[i]<mid1:
    print(mid2)
  if x[i]==mid1 and x.count(mid1)>2:
    print(mid1)
  if x[i]==mid1 and x.count(mid1)<3:
    print(mid2)
  if x[i]==mid2 and x.count(mid2)>2:
    print(mid2)
  if x[i]==mid2 and x.count(mid2)<3:
    print(mid1)
  if x[i]>mid2:
    print(mid1)

Submission status: Accepted

Solution code:
# C - Many Medians
import copy
N = int(input())
X = list(map(int, input().split()))
X2 = []

X2 = copy.copy(X)
X2.sort(reverse=True)
Xm_1 = X2[N//2]
Xm_2 = X2[(N//2)-1]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:


def main():


   X = int(input())
   oriList = list(map(int,input().split()))
   lis = sorted(list(oriList))

   if len(lis)%2==0:
      mid = lis[len(lis)//2-1]
      nextmid = lis[len(lis)//2]
   else:
      mid = lis[(len(lis)+1)//2-1]
      nextmid = lis[(len(lis)+1)//2]
   


   for i in oriList:
      if i <= mid:
         print(nextmid)
      else:
         print(mid)


   





if __name__== "__main__":
    main()

Submission status: Accepted

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

import copy

cp = copy.deepcopy(x)
cp.sort()
x_l = cp[n//2 - 1]
x_r = cp[n//2]

for ele in x:
    if ele <= x_l:
        print(x_r)
    else:
        print(x_l)

Submission status: Accepted

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

left=b[int(n/2)-1]
right=b[int(n/2)]
for i in a:
    pos=bisect.bisect_left(b, i)+1
    if 2*pos<=n:
        print(right)
    else:
        print(left)

Submission status: Accepted

Solution code:
N=int(input())
X=[int(x) for x in input().split()]
XX=sorted(X)
L=XX[N//2-1]
R=XX[N//2]
for x in X:
  print(L if x>=R else R)

Submission status: Accepted

Solution code:
def get_medians(nums):
    s = sorted(nums)
    mid = len(s) // 2
    return (s[mid - 1], s[mid])

input()
nums = [int(tok) for tok in input().split()]

medians = get_medians(nums)
for num in nums:
    if num <= medians[0]:
        print(medians[1])
    else:
        print(medians[0])

Submission status: Accepted

Solution code:

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

mid_1 = sort_x[n//2-1]
mid_2 = sort_x[n//2]

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

Submission status: Accepted

Solution code:
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

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

def index_sort(A):
    x = []
    for i,a in enumerate(A):
        x.append((a,i))
    return sorted(x, key=lambda x: x[0])

N = I()
X = III()

y = index_sort(X)
order = [0]*N
for i in range(N):
    order[y[i][1]] = i

for i in range(N):
    if order[i]<=(N-1)//2:
        print(y[(N+1)//2][0])
    else:
        print(y[(N-1)//2][0])

Submission status: Accepted

Solution code:
import sys

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

X_sort = sorted(X)

ans_1 = X_sort[N//2-1]
ans_2 = X_sort[N//2]

if ans_1 == ans_2:
	for _ in range(N):
		print(ans_1)
	sys.exit()

for i in range(N):
	if X[i] < ans_2:
		print(ans_2)
	elif X[i] > ans_1:
		print(ans_1)

Submission status: Accepted

Solution code:
from math import ceil
N = int(input())

x = list(map(int,input().split()))
x_sort = sorted(x)
length = len(x)
median = (x_sort[ceil(length/2-1)]+x_sort[ceil(length/2)])/2

for i in range(length):
    if x[i] <= median:
        print(x_sort[ceil(length/2)])
    else:
        print(x_sort[ceil(length/2-1)])

Submission status: Accepted

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

for x in X:
	if x < median_upper:
		print(median_upper)
	elif x > median_lower:
		print(median_lower)
	else:
		print(median_lower)

Submission status: Accepted

Solution code:
import sys
from statistics import *
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
xxx = na()
r = median_high(xxx)
l = median_low(xxx)
for i in range(n):
    if xxx[i] <= l:
        print(r)
    elif xxx[i] >= r:
        print(l)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    x = list(map(int, input().split()))
    x = sorted([(x[i], i) for i in range(N)])
    ans = [0] * N
    for i in range(N//2):
        ans[x[i][1]] = x[N//2][0]
    for i in range(N//2, N):
        ans[x[i][1]] = x[N//2 - 1][0]
    for i in range(N):
        print(ans[i])

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from statistics import median_high, median_low
n = int(input())
x = list(map(int, input().split()))
h = median_high(x)
l = median_low(x)
for i in x : print(h if h>i else l)

Submission status: Accepted

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

def solve(N: int, X: "List[int]"):
    y = sorted(X)
    b = y[int(N/2)-1]
    a = y[int(N/2)]

    for i in X:
        if(i <= b):
            print(a)
        else:
            print(b)

    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, X)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

M_small = sorted(X)[N // 2 - 1]
M_large = sorted(X)[N // 2]

for xi in X:
    if xi <= M_small:
        print(M_large)
    else:
        print(M_small)

Submission status: Accepted

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

n1, n2 = xsort[n//2-1], xsort[n//2]

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc094/tasks/arc095_a
# C - Many Medians
import copy

n = int(input().split()[0])
x_list = list(map(int, input().split()))
sorted_x_list = sorted(x_list)
mean_index = int((n + 1)/ 2) - 1
mean_list = []

a = sorted_x_list[mean_index]
b = sorted_x_list[mean_index + 1]
for x in x_list:
    if x <= a:
        mean_list.append(str(b))
    else:
        mean_list.append(str(a))

ans = '\n'.join(mean_list)
print(ans)

Submission status: Accepted

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

x_med_l = x_sorted[n//2 - 1]
x_med_r = x_sorted[n//2]

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import copy

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

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

first = (N // 2) - 1
second = N // 2

for i in X:
    if i <= Y[first]:
        print(Y[second])
    else:
        print(Y[first])

Submission status: Accepted

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

Submission status: Accepted

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

for x in X:
    if x < CR:
        print(CR)
    else:
        print(CL)

Submission status: Accepted

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

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:
import statistics

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

y = sorted(x)
med = statistics.median(x)
med_1 = y[int((n-2)/2)]
med_2 = y[int(n/2)]

for i in range(n):
    if x[i] < med:
        print(med_2)
    elif x[i] >= med:
        print(med_1)

Submission status: Accepted

Solution code:
"""
中央値

2 4 4 3
2 3 4 4
真ん中の2つの値を取り出す
⇨
"""

N = int(input())
Xs = list(map(int, input().split()))
X_sort = sorted(Xs)
M1 = X_sort[N//2-1]
M2 = X_sort[N//2]
# print(X_sort,M1,M2)

for x in Xs:
    if x <= M1:
        print(M2)
    else:
        print(M1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy

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

x1 = copy.deepcopy(x)

x1.sort()

mae = x1[(n//2)-1]
ato = x1[(n//2)]

for i in range(len(x)):
    if x[i] > mae:
        print(mae)
    else:
        print(ato)

Submission status: Accepted

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

Submission status: Accepted

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

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

sorted_lst = sorted(lst)
idx = (N-1) // 2
low = sorted_lst[idx]
high = sorted_lst[idx+1]
for i in range(N):
  if lst[i] <= low:
    print(high)
  else:
    print(low)

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int, input().split()))
m = sorted(l)

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

Submission status: Accepted

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

if N==2:
    print(A[1])
    print(A[0])
    exit(0)

for i in range(N):
    B.append(A[i])

B.sort()

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

Submission status: Accepted

Solution code:
n = int(input())
xs = list(map(int, input().split()))
 
ys = list(sorted(xs))
m1 = ys[n//2 - 1]
m2 = ys[n//2]
 
medians = [m2 if x < m2 else m1 for x in xs]
print('\n'.join(map(str, medians)))

Submission status: Accepted

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

    sort_X = sorted(X)
    X1 = sort_X[N//2]
    X2 = sort_X[(N//2) - 1]

    for x in X:
        if x <= X2:
            print(X1)
        else:
            print(X2)
main()

Submission status: Accepted

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

nX  = sorted(X)
l = N-1

med_1 = nX[(l+1)//2] 
med_2 = nX[(l+1)//2-1]

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

Submission status: Accepted

Solution code:
n = int(input())
x = [int(i) for i in input().split()]
s = sorted(x)
l = s[len(s) // 2 - 1]
r = s[len(s) // 2]
print(*[r if i <= l else l for i in x], sep='\n')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict

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

B = sorted(A)
index = defaultdict(lambda: -1)
for i, b in enumerate(B):
    index[b] = i

for i in range(N):
    if index[A[i]] < N // 2:
        print(B[N // 2])
    else:
        print(B[N // 2 - 1])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
data = [int(x) for x in stdin.readline().rstrip().split()]

d1 = sorted(data)[(N//2)-1]
d2 = sorted(data)[(N//2)]

for i in data:
    if i <= d1:
        print(d2)
    else:
        print(d1)

Submission status: Accepted

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

Xs = sorted(X)
med_d = Xs[N // 2 - 1]
med_u = Xs[N // 2]

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

Submission status: Accepted

Solution code:
n = int(input())
ls = [x for x in map(int, input().split(' '))]
dam = sorted(ls.copy())

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

Submission status: Accepted

Solution code:
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
X = list(map(int, sys.stdin.readline().split()))
X2 = list(sorted(X))
x1 = X2[N // 2 - 1]
x2 = X2[N // 2]


for x in X:
    if x <= x1:
        print(x2)
    else:
        print(x1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 2019/08/08
from bisect import bisect_left,bisect_right

n=int(input())
x=list(map(int,input().split()))
xx=sorted(x)
mid=n//2

ans=[]
for i in range(n):
    if bisect_left(xx,x[i])<mid:
        ans.append(xx[mid])
    else:
        ans.append(xx[mid-1])
print(*ans,sep='\n')

Submission status: Accepted

Solution code:
# 2019/08/08

from bisect import bisect_left,bisect_right

n=int(input())
x=list(map(int,input().split()))
xx=sorted(x)
mid=n//2

for i in range(n):
    if bisect_left(xx,x[i])<mid:
        print(xx[mid])
    else:
        print(xx[mid-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

n = getint()
xs = getints()
ys = list(sorted(xs))

mid1 = ys[n//2-1]
mid2 = ys[n//2]

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

Submission status: Accepted

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

leftB = A[N//2 - 1]
rightB = A[N//2]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
lst = [int(i) for i in input().split()]
lst_sort = sorted(lst)
med = (lst_sort[n//2] + lst_sort[n//2-1])/2

for i in range(n):
    if lst[i] < med:
        print(lst_sort[n//2])
    else:
        print(lst_sort[n//2-1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
li = list(map(int, input().split()))
mid_id = (len(li)//2)
temp = li.copy()
temp.sort()
mid1 = temp[mid_id-1]
mid2 = temp[mid_id]
for i in li:
    if i <= mid1:
        print(mid2)
    else:
        print(mid1)

Submission status: Accepted

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

x1=sorted(x)

ans1=x1[n//2-1]
ans2=x1[n//2]

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

Submission status: Accepted

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

Submission status: Accepted

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

mylist = sorted(X)
for i in range(N):
	ans = mylist[N//2-1]
	if X[i] > ans:
		print(ans)
	else:
		print(mylist[N//2])

Submission status: Accepted

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

Submission status: Accepted

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

li1 = sorted(li)
p = li1[n//2]
q = li1[n//2-1]

for i in li:
    if i <= q:
        print(p)
    else:
        print(q)

Submission status: Accepted

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

B = A.copy()

B.sort()

for num in A:
  if B[N//2] > num:
    print(B[N//2])
  else:
    print(B[N//2-1])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
sorted_X = sorted(X)
sorted_indices = sorted(range(len(X)), key=lambda k: X[k])
median_index = N // 2 - 1
ans = []
for i, x in enumerate(sorted_X):
    if i <= median_index:
        ans.append((sorted_indices[i], sorted_X[median_index + 1]))
    elif median_index < i:
        ans.append((sorted_indices[i], sorted_X[median_index]))
ans = sorted(ans, key=lambda x: x[0])
for x in ans:
    print(x[1])

Submission status: Accepted

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