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:
def main():
    n=int(input())
    x=list(map(int,input().split()))
    y=sorted(x)
    c1,c2=y[n//2-1],y[n//2]
    if c1==c2:
        for i in range(n):
            print(c1)
    else:
        for i in range(n):
            if x[i]<=c1:
                print(c2)
            else:
                print(c1)

if __name__=="__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

middleIdx = n//2
s1 = sorted(x)[middleIdx-1]
s2 = sorted(x)[middleIdx]

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

Submission status: Accepted

Solution code:
def main():
    #from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #r = input()
    #n = int(input())
    #a, b = map(int, input().split())
    #s, y = input().split()
    #a = input().split()
    #a = [int(input()) for i in range(n)]
    #a = list(map(int, input().split()))
    #a = [list(map(int, input().split())) for i in range(n)]
    #a = [int(s) - 1 for s in input().split()]
    #l=[int(input()) for _ in range(int(input()))]
    #res = 0
    n = int(input())
    x = list(map(int, input().split()))
    x2 = sorted(x)
    med1 = x2[n//2-1]
    med2 = x2[n//2]
    for i in x:
        if i <= med1:
            print(med2)
        else:
            print(med1)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(N):
    if X[i] > left:
        print(left)
    else:
        print(right)

Submission status: Accepted

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

Y = sorted(X)

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

Submission status: Accepted

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


Y = sorted(X)
a, b = Y[n // 2 - 1], 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()))
X_sort = sorted(X)
xm1 = X_sort[n//2-1]
xm2 = X_sort[n//2]
xm = (xm1+xm2)/2
for i in range(n):
    if X[i]<xm:
        print(xm2)
    else:
        print(xm1)

Submission status: Accepted

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

Submission status: Accepted

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

mid_n = len(a)//2
right = a[mid_n]
left = a[mid_n-1]

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

Submission status: Accepted

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

X_sort = sorted(X)

mid_r = X_sort[N//2]
mid_l = X_sort[N//2-1]

for i in range(N):
    if X[i] <= 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)
mid_l = X_sort[N // 2 - 1]
mid_r = X_sort[N // 2]

for i in range(N):

    if (X[i] <= mid_l):
        ans = mid_r
    
    else:
        ans = mid_l
    
    print(ans)

Submission status: Accepted

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

for i in range(N):
    if X[i] < Y[l]:
        print(Y[l])
    else:
        print(Y[l- 1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from copy import deepcopy
import bisect
n = int(input())
dat = list(map(int, input().split()))
odat = deepcopy(dat)
dat.sort()
x1 = dat[len(dat) // 2 - 1]
x2 = dat[len(dat) // 2]
for i in range(n):
    c = odat[i]
    j = bisect.bisect_left(dat, c)
    if j < len(dat) // 2:
        print(x2)
    else:
        print(x1)

Submission status: Accepted

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

for i in X:
    print(X_mid[i <= X_mid[0]])  # Falseなら1、Trueなら0

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
nums=list(map(int,input().split()))
nums=list(enumerate(nums))
nums.sort(key=lambda x:x[1])

med=[0]*n
for i in range(n):
    ind=nums[i][0]
    if i<n//2:
        med[ind]=nums[n//2][1]
    else:
        med[ind]=nums[n//2-1][1]
print(*med,sep='\n')

Submission status: Accepted

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

Submission status: Accepted

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

X_sorted = sorted(X)
if N >= 4:
  bigger = X_sorted[N//2]
  smaller = X_sorted[N//2-1]

  for _ in X:
    if _ >= bigger:
      ans = smaller
    else:
      ans = bigger
    print(ans)

else:
  for n in range(2):
    if n == 0:
      print(X[1])
    else:
      print(X[0])

Submission status: Accepted

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

sorted_x = sorted(x)
smaller = sorted_x[n//2 - 1]
bigger = sorted_x[n//2]

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

Submission status: Accepted

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

import copy
x=copy.deepcopy(X)
x.sort()
A=x[N//2-1]
B=x[N//2]

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

Submission status: Accepted

Solution code:
import itertools
import statistics
#n = int(input())
#n, d = list(input().split())
N = int(input())
X = list(map(int, input().split()))
sortedX = sorted(X)
mid_min = sortedX[N//2-1]
mid_max = sortedX[N//2]

for i in X:
    if i <= mid_min:
        print(mid_max)
    else:
        print(mid_min)

Submission status: Accepted

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

if m == n:
    for i in range(k):
        print(m)
        
else:
    for i in a:
        if i <= m:
            print(n)
        else:
            print(m)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
X = np.array(input().split(), dtype=np.int64)
argsort = X.argsort()
argsort_argsort = argsort.argsort()
X_sorted = X[argsort]
m1, m2 = N // 2 - 1, N // 2
print("\n".join(str(X_sorted[m2]) if idx <= m1 else str(X_sorted[m1]) for idx in argsort_argsort))

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
X = np.array(input().split(), dtype=np.int64)
argsort = X.argsort()
argsort_argsort = argsort.argsort()
X_sorted = X[argsort]
m1, m2 = N // 2 - 1, N // 2
for idx in argsort_argsort:
    if idx <= m1:
        print(X_sorted[m2])
    else:
        print(X_sorted[m1])

Submission status: Accepted

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

indexes = [i for i in range(N)]
sorted_indexes = sorted(indexes, key=lambda i: X[i])

for i in range(N):

    if X[i] <= X[sorted_indexes[int(N / 2)-1]]:
        print(X[sorted_indexes[int(N / 2)]])
    else:
        print(X[sorted_indexes[int(N / 2)-1]])

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
x.insert(0,0) #x[0]に0を挿入
sorted_x = sorted(x[:])

l,r=sorted_x[n//2],sorted_x[n//2+1]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int,input().split()))
S=sorted(X)
l=S[int((N/2)-1)]
r=S[int(N/2)]
d=(l+r)/2
for i in range(N):
    if(X[i]>d):
        print(l)
    elif(X[i]<d):
        print(r)
    else:
        print(X[i])

Submission status: Accepted

Solution code:
n = int(input())
x = [int(_) for _ in input().split()]
xx = sorted(x)
mid_min = xx[n//2-1]
mid_max = xx[n//2]
for i in x:
    if i <= mid_min:
        print(mid_max)
    else:
        print(mid_min)

Submission status: Accepted

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

if n>2:
    for i in range(n):
        if x[i] < x1[mid]:print(x1[mid])
        else:print(x1[mid-1])
else:
    for i in range(n):
        x2=x.copy()
        x2.pop(i)
        print(x2[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
import math
import sys
from collections import Counter
from fractions import gcd
from functools import reduce

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

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))
B=sorted(A)
hanbun=n//2
left_B=B[hanbun-1]
right_B=B[hanbun]
for a in A:
    if a <= left_B:
        print(right_B)
    else:
        print(left_B)

Submission status: Accepted

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

Submission status: Accepted

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

y_list = x_list.copy()
y_list.sort()

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

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

Submission status: Accepted

Solution code:
import copy

N=int(input())
X1=list(map(int,input().split()))
X=copy.deepcopy(X1)
X.sort()
ma=X[N//2-1]
mb=X[N//2]


for i in range(N):
    if X1[i]<=ma:
        print(mb)
    else:
        print(ma)

Submission status: Accepted

Solution code:
input()
x=list(map(int,input().split()))
z=sorted(x)[(len(x))//2-1:]
for c in x:print(z[c<=z[0]])

Submission status: Accepted

Solution code:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
index = []
for i, v in enumerate(x):
    index.append((i, v))
index.sort(key=lambda x: x[1])
ans = [0] * n
for i, w in enumerate(index):
    if i <= n//2 - 1:
        ans[w[0]] = index[n//2][1]
    else:
        ans[w[0]] = index[n//2 - 1][1]

print("\n".join(map(str, ans)))

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
x1 = []
for i, xi in enumerate(x):
    x1.append([i, xi])

x_sort = sorted(x1, key=lambda x: x[1])
t = int(n / 2)
lxt = []
for i in range(n):
    if i < t:
        x[x_sort[i][0]] = x_sort[t][1]
    else:
        x[x_sort[i][0]] = x_sort[t - 1][1]

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
x = list(map(int,input().split()))
a = sorted(x)
for j in x:
    if j <= a[n//2-1]: print(a[n//2])
    else: print(a[n//2-1])

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    numbers = list(map(int, input().split(" ")))
    sorted_numbers = sorted(numbers)
    medians = [sorted_numbers[N // 2], sorted_numbers[N // 2 - 1]]
    for number in numbers:
        if number <= medians[1]:
            print(medians[0])
        else:
            print(medians[1])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
x=[int(i) for i in input().split()]
xx=sorted(x)
a=xx[n//2-1]
b=xx[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()))
Y = sorted(X)
m = Y[(N // 2) - 1]
M = Y[N // 2]
for x in X:
  if m >= x:
    print(M)
  elif M <= x:
    print(m)

Submission status: Accepted

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

Submission status: Accepted

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

A_sort=sorted(A[:])
A_median_1=A_sort[N//2]
A_median_2=A_sort[N//2-1]

ans=0
for a in A:
    if a<A_median_1:
        ans=A_median_1
    else:
        ans=A_median_2
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split())) # list()
xsorted = sorted(x)
mannaka=n//2
median_a = xsorted[mannaka-1]#3
median_b = xsorted[mannaka]#4
'''
print(x)
print(xsorted)
print(mannaka)
print(median_a)
print(median_b)
'''
for i in range(n):
    if(x[i]<=median_a):
        print(median_b)
    else:
        print(median_a)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
Xlist = list(map(int, input().split()))
X_sort = sorted(Xlist)
left_med = X_sort[N//2-1]
right_med = X_sort[N//2]
for i in range(N):
    if Xlist[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()))
X_copy = copy.copy(X)
X_copy.sort()

left = X_copy[len(X)//2-1]
right = X_copy[len(X)//2]

# print(X_copy, left, right)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, *X = map(int, open(0).read().split())
Y = [(i, x) for (i, x) in enumerate(X)]
Y = sorted(Y, key=lambda x:x[1])
ans = []
for i in range(N//2):
  ans.append((Y[i][0], Y[N//2][1]))
for i in range(N//2, N):
  ans.append((Y[i][0], Y[N//2-1][1]))
ans = sorted(ans)
for a in ans:
  print(a[1])

Submission status: Accepted

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

Submission status: Accepted

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

B = []
l = N // 2
r = (N//2)+1
Y = copy.copy(X)
Y.sort()
chu = Y[N//2-1]
tyu = Y[N//2]

for i in range(N):
    if X[i]<=chu:
        B.append(tyu)
    else:
        B.append(chu)

for i in range(len(B)):
    print(B[i])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
x = list(map(int,input().split()))
a = sorted(x)
base = a[n//2]
for i in range(n):
    #if x[i] > a[n//2-1] or (x[i] == a[n//2-1] and a.count(x[i]) > 1): print(a[n//2-1])
    if x[i] > a[n//2-1]: print(a[n//2-1])
    else: print(a[n//2])

Submission status: Accepted

Solution code:
import statistics
n = int(input())
a = list(map(int, input().split()))
median_low = statistics.median_low(a)
median_high = statistics.median_high(a)
for i in range(n):
    if median_high > a[i]:
        print(median_high)
    elif median_low < a[i]:
        print(median_low)
    elif median_high == a[i]:
        print(a[i])
    else:
        print(a[i-1])

Submission status: Accepted

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

Median_1_i=N//2-1
Median_2_i=N//2

X_=X[:]
X_.sort(reverse=True)
Median_1=X_[Median_1_i]
Median_2=X_[Median_2_i]

for x in X:
    if x<Median_1:
        print(Median_1)
    else:
        print(Median_2)

Submission status: Accepted

Solution code:
N = int(input())
lst = [int(x) for x in input().split()]
tmp = sorted(lst)
a = tmp[(N // 2 - 1)]
b = tmp[N // 2]

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

Submission status: Accepted

Solution code:
import copy

a = int(input())
l = list(map(int, input().split()))
l2 = sorted(copy.deepcopy(l))

#print(l2)

for i in l:
  if i < l2[a//2]:
    print(l2[a//2])
  else:
    print(l2[a//2 - 1])

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
xx=[]
for i in range(n):
    xx.append([x[i],i,""])
xx2=sorted(xx)
for i in range(n):
    if i<=(n//2-1):
        xx2[i][2]="l"
    else:
        xx2[i][2]="r"
l_num,r_num=xx2[n//2-1][0],xx2[n//2][0]
xx3=sorted(xx2,key=lambda x:x[1]) #最初の順番に戻す
for i in range(n):
    if xx3[i][2]=="l":
        print(r_num)
    else:
        print(l_num)

Submission status: Accepted

Solution code:
def solve(n, X):
    l, r = sorted(X)[n // 2 - 1:n // 2 + 1]
    return [r if x <= l else l for x in X]

_n = int(input())
_X = list(map(int, input().split()))
print(*solve(_n, _X), sep='\n')

Submission status: Accepted

Solution code:
from copy import deepcopy

n = int(input().strip())
x = list(map(int, input().split()))
y = deepcopy(x)
y.sort()
m1 = y[n // 2 - 1]
m2 = y[(n // 2)]

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

Submission status: Accepted

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

Submission status: Accepted

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

y = sorted(x)

median1 = y[n // 2 - 1]
median2 = y[n // 2]

# print(y, median1, median2)

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

Submission status: Accepted

Solution code:
n = int(input())
x = tuple(map(int,input().split()))
x_sort = sorted(x,reverse=True)
x_median = x_sort[n//2-1]
x_median2 = x_sort[n//2]
for i in range(n):
    print(x_median2 if x[i] > x_median2 else x_median)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy

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

xx= sorted(x)
L_x = xx[n//2 - 1]
R_x = xx[n//2]

for arr in x:
  print(L_x if R_x <= arr else R_x)

Submission status: Accepted

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


main()

Submission status: Accepted

Solution code:
def main():
    N, *X = map(int, open(0).read().split())
    l, r = sorted(X)[N // 2 - 1:N // 2 + 1]
    print("\n".join(map(str, [r if x <= l else l for x in X])))
    return


main()

Submission status: Accepted

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


main()

Submission status: Accepted

Solution code:
def main():
    N, *X = map(int, open(0).read().split())
    l, r = sorted(X)[N // 2 - 1:N // 2 + 1]
    print("\n".join(map(str, [r if x < r else l for x in X])))
    return


main()

Submission status: Accepted

Solution code:
def main():
    N, *X = map(int, open(0).read().split())
    l, r = sorted(X)[N // 2 - 1:N // 2 + 1]
    print("\n".join([str(r) if x < r else str(l) for x in X]))
    return


main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC094c
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n = int(input())
x = list(map(int, input().split()))
for i in range(n):
    x[i] = (x[i], i)
x.sort()

ans = [-1]*n

ind = n//2
for i in range(n):
    if i <= n//2-1:
        ans[x[i][1]] = x[n//2][0]
    else:
        ans[x[i][1]] = x[n//2-1][0]
print(*ans, sep='\n')

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
nums = [int(i) for i in input().split()]
sorted_nums = sorted(nums)
median_idx = n // 2
low = sorted_nums[median_idx-1]
high = sorted_nums[median_idx]
tmp = (low + high) / 2

for num in nums:
    if num < tmp:
        print(high)
    else:
        print(low)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    X = [int(x) for x in input().split()]

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



if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N):
    if X[i] <= med_options[0]:
        print(med_options[1])
    elif med_options[1] <= X[i]:
        print(med_options[0])

Submission status: Accepted

Solution code:
from operator import itemgetter
N = int(input())
X = list(map(int,input().split()))
X_ = sorted(enumerate(X),key=itemgetter(1))
lesser_med = X_[(N//2)-1]
greater_med = X_[N//2]
for x in X:
    if x <= lesser_med[1]:
        print(greater_med[1])
    else:
        print(lesser_med[1])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# 中央値となりうる候補は2種類しか無い。
# 消した数がA[N/2]～A[N-1]にある場合, mid = A[N/2-1](left)
# 消した数がA[0]～A[N/2 - 1]にある場合, mid = A[N/2](right)
N = int(input())
A = list(map(int, input().split()))

B = sorted(A)
L = B[N//2-1]
R = B[N//2]

for a in A:
  print(L if a >= R else R)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

li = sorted(a)
memo = li[n//2-1]

for i in range(n):
    if a[i] > memo:
        print(li[(n//2)-1]) 
    else:
        print(li[(n//2)])

Submission status: Accepted

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

ans_list = [l2[(n//2)-1],l2[n//2]]

for i in l:
    if i > ans_list[0]:
        print(ans_list[0])
    else:
        print(ans_list[1])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import copy
n = int(input())
lst1 = list(map(int,input().split()))
lst2 = []
c = copy.deepcopy(lst1)

c.sort()

Kth = c[n//2] #上の方

med_low = Kth
med_high = c[n//2-1]

for i in range(n):
    if lst1[i] < Kth:
        print(med_low)
    else:
        print(med_high)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
X=list(map(int,input().split()))

X2=sorted(X)

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

Submission status: Accepted

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