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()))
y =[]
for i in range(n):
    y.append([x[i],i])
y.sort(key = lambda x:x[0])
ans1 =y[n//2][0]
ans2 =y[n//2-1][0]
#print(ans1,ans2)
for i in x:
    if i <=ans2:
        print(ans1)
    else:
        print(ans2)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    xs = list(map(int, input().split()))
    i_m = n // 2 - 1
    ys = sorted((x, i) for i, x in enumerate(xs))
    for x in xs:
        if x <= ys[i_m][0]:
            print(ys[i_m + 1][0])
        else:
            print(ys[i_m][0])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
X = [int(i) for i in input().split()]
X2 = sorted(X)
mapper = {}

for i in range(N//2) :
    if (X2[i] in mapper) :
        continue
    mapper[X2[i]] = X2[len(X2)//2]

for i in range(N//2,N) :
    if (X2[i] in mapper) :
        continue
    mapper[X2[i]] = X2[(len(X2)//2) - 1]

for x in X :
    print(mapper[x])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
x = list(map(int, input().split()))
xx = sorted(x)
med1,med2 = xx[N//2-1], xx[N//2]

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

Submission status: Accepted

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

tmp = l.copy()
tmp.sort()

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

for item in l:
    if item <= left:
        print(right)
    else:
        print(left)

Submission status: Accepted

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

    a = copy.deepcopy(x)
    a.sort()
    a1 = a[(n-1)//2]
    a2 = a[(n+1)//2]

    for i in range(0,n):
        if x[i]<=a1:
            print(a2)
        else:
            print(a1)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

if n == 2:
    print(x[1])
    print(x[0])
else:
    y = sorted(x)
    m1 = y[int(n/2)-1]
    m2 = y[int(n/2)]
    if m1 == m2:
        for _ in range(n):
            print(m1)
    else:
        for i in range(n):
            if x[i] <= m1:
                print(m2)
            elif x[i] >= m2:
                print(m1)

Submission status: Accepted

Solution code:
import copy
n = int(input())
xarray = list(map(int,input().split()))
newArray = copy.copy(xarray)
newArray.sort()

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


for item in xarray:
    if item<=left:  #ここで if newArray.index(item)<=n//2-1 としたらTLEだったのでindexメソッド自体が結構時間かかるものなのかもしれない
        print(right)
    else:
        print(left)

Submission status: Accepted

Solution code:
n = int(input())
xarray = list(map(int,input().split()))
newArray = xarray[:]
newArray.sort()

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


for item in xarray:
    if item<=left:
        print(right)
    else:
        print(left)

Submission status: Accepted

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

X.sort()
left = X[N // 2 - 1]
right = X[N // 2]

if left == right:
    for i in range(N):
        print(left)
    exit()

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

Submission status: Accepted

Solution code:
# encoding: utf-8
N = int(input())
X = list(map(int, input().split()))

X_sort = sorted(X)
m = X_sort[N // 2]

for i, Xi in enumerate(X):
    if N % 2:
        if Xi <= m: print(X_sort[N // 2 + 1])
        else: print(m)
    else:
        if Xi >= m: print(X_sort[N // 2 - 1])
        else: print(m)

Submission status: Accepted

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

Submission status: Accepted

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

tarr = list(arr)

tarr.sort()

num1 = tarr[len(tarr) // 2 - 1]
num2 = tarr[len(tarr) // 2]

for i in range(n):
    if arr[i] < num2:
        print(num2)
    else:
        print(num1)

Submission status: Accepted

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

x_sorted = sorted(x)

med = (x_sorted[int(n/2)-1] + x_sorted[int(n/2)])/2

for i in range(n):
    if x[i]<med:
        print(x_sorted[int(n/2)])
    else:
        print(x_sorted[int(n/2)-1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

meds = x_sort[n//2-1:n//2+1]

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

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
X_sort = X.copy()
X_sort.sort()
s = N // 2
median = (X_sort[s - 1] + X_sort[s]) / 2

for x in X:
    if x < median:
        print(X_sort[s])
    else:
        print(X_sort[s-1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

X = [{'idx': i, 'ord': -1, 'val': int(x)} for i, x in enumerate(input().split())]

order = sorted(X, key=lambda x: x['val'])

for i in range(N):
    X[order[i]['idx']]['ord'] = i

for x in X:
    if (x['ord'] < N / 2):
        bi = N // 2
    else:
        bi = (N - 2) // 2
    print(order[bi]['val'])

Submission status: Accepted

Solution code:
iN = int(input())
aX = [int(_) for _ in input().split()]
aXs = sorted(aX)

iMu  = iN//2
iMd  = iN//2 -1

iMuV = aXs[iMu]
iMdV = aXs[iMd]

if iMuV == iMdV:
    print("\n".join([str(iMuV)]*iN))
else:
    print("\n".join(map(str,map(lambda x: iMuV if x < iMuV else iMdV ,aX))))

Submission status: Accepted

Solution code:
iN = int(input())
aX = [int(_) for _ in input().split()]

aXs = sorted(enumerate(aX),key=lambda x:x[1])

iMu  = iN//2
iMd  = iN//2 -1

iMuV = aXs[iMu][1]
iMdV = aXs[iMd][1]

if iMuV == iMdV:
    print("\n".join([str(iMuV)]*iN))
else:
    print("\n".join(map(str,map(lambda x: iMuV if aX[x] < iMuV else iMdV ,range(iN)))))

Submission status: Accepted

Solution code:
iN = int(input())
aX = [int(_) for _ in input().split()]

aXs = sorted(enumerate(aX),key=lambda x:x[1])

iMu  = iN//2
iMd  = iN//2 -1

iMuV = aXs[iMu][1]
iMdV = aXs[iMd][1]

if iMuV == iMdV:
    print("\n".join([str(iMuV)]*iN))
else:
    print("\n".join(map(str,(map(lambda x: iMuV if aX[x] < iMuV else iMdV ,range(iN))))))

Submission status: Accepted

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

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

Submission status: Accepted

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

X2 = sorted(X)
r = X2[N // 2 ]
l = X2[N // 2 -1]

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

Submission status: Accepted

Solution code:
import bisect

N = int(input())
X = [int(_) for _ in input().split()]

X2 = sorted(X)
r = X2[N // 2 ]
l = X2[N // 2 -1]

for i in range(N):
    if bisect.bisect_left(X2, X[i]) < N // 2:
        print(r)
    else:
        print(l)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np
N= int(input())
a = list(map(int, input().split(' ')))
sort_a = sorted(a)
small = sort_a[N//2-1]
big = sort_a[N//2]
for aa in a:
    if aa < big:
        print(big)
    else:
        print(small)

Submission status: Accepted

Solution code:
N = int(raw_input())
X_list = map(int, raw_input().split())

sorted_x = sorted(X_list)

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

for x in X_list:
    if x < big:
        print big
    else:
        print small

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
idx = range(N)
Y = [ [ idx[i], X[i]] for i in range(N) ]
Z = sorted(Y , key=lambda x: x[1])
ans = []
for i,j in enumerate(Z):
    idx_tmp = Z[i][0]
    if i < int(N/2):
        median = Z[int(N/2)][1]
    else:
        median = Z[int(N/2)-1][1]
    ans.append([idx_tmp,median])
ans = sorted(ans, key=lambda x:x[0])
for i in ans:
    print(i[1])

Submission status: Accepted

Solution code:
N = int(input())
X = [int(x) for x in input().split()]
_X = sorted([x for x in X])
x1 = _X[N // 2 - 1]
x2 = _X[N // 2]
for x in X:
  print(x2 if x <= x1 else x1)

Submission status: Accepted

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

XS = sorted(X)

r = len(X) // 2
l = r - 1

lv = XS[l]
for n in X:
    print(XS[r if n <= lv else l])

Submission status: Accepted

Solution code:
N = int(input())
X = [int(x) for x in input().split()]
_X = [x for x in X]
_X.sort()
x1 = _X[N // 2 - 1]
x2 = _X[N // 2]
for x in X:
  print(x2 if x <= x1 else x1)

Submission status: Accepted

Solution code:
import copy
import statistics
n = int(input())
x = [int(y) for y in input().split()]
z = copy.deepcopy(x)
z.sort()
t = (z[int(n / 2) - 1] + z[int(n / 2)]) / 2

for i in range(n):
  if x[i] < t:
    print(z[int(n / 2)])
  else:
    print(z[int(n / 2) - 1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

    th = y[n // 2]
    for a in x:
        if a < th:
            print(y[n // 2])
        else:
            print(y[n // 2 - 1])

main()

Submission status: Accepted

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

Submission status: Accepted

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

x2 = x.copy()
x2.sort()
c1 = x2[n // 2 - 1]
c2 = x2[n // 2]
for i in x:
    if(c1 >= i):
        print(c2)
    else:
        print(c1)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

sx = list(sorted(X))
m1 = sx[N//2 - 1]
m2 = sx[N//2]

ans = []
for a in X:
    if a >= m2:
        ans.append(m1)
    else:
        ans.append(m2)
print(*ans, sep='\n')

Submission status: Accepted

Solution code:
# coding:utf-8

import sys


input = sys.stdin.readline


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


N = int(input())
X = inpl()
A = sorted(X)
mid = A[N//2]

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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
x = list(li())

med1 = sorted(x)[n//2 - 1]
med2 = sorted(x)[n//2]

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
X = np.array(list(map(int, input().split())), dtype=int)
idx = np.argsort(X)
Xs = np.sort(X)
ans = [None for _ in range(N)]
for i in range(N // 2):
    ans[idx[i]] = Xs[N // 2]
for i in range(N // 2, N):
    ans[idx[i]] = Xs[N // 2 - 1]
for i in range(N):
    print(ans[i])

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
X = np.array(list(map(int, input().split())), dtype=int)
idx = np.argsort(X)
Xs = X[idx]
ans = [None for _ in range(N)]
for i in range(N // 2):
    ans[idx[i]] = Xs[N // 2]
for i in range(N // 2, N):
    ans[idx[i]] = Xs[N // 2 - 1]
for i in range(N):
    print(ans[i])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
x = [int(_) for _ in 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 statistics


n = int(input())
x = [int(_) for _ in input().split()]
m1 = statistics.median_low(x)
m2 = statistics.median_high(x)
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(" ")))
Y = copy.deepcopy(X)
Y.sort()
B = (Y[N//2]+Y[N//2-1])/2

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
xn = list(map(int, input().split()))
xn_sorted = sorted(xn)
val_a = xn_sorted[(len(xn_sorted))//2 - 1]
val_b = xn_sorted[(len(xn_sorted))//2]

for xi in xn:
    if xi <= val_a:
        print(val_b)
    else:
        print(val_a)

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

x_sorted = sorted(x)
meds = x_sorted[n//2-1:n//2+1]
for i in range(n):
    if x[i] <= meds[0]:
        print(meds[1])
    elif x[i] >= meds[1]:
        print(meds[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

N=int(raw_input())

X = map(int,raw_input().split())

Y=np.sort(X)

m1=Y[N/2-1]
m2=Y[N/2]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))
X_sort = sorted(X)
N_half = int(N/2)
median_large = X_sort[N_half]
median_small = X_sort[N_half-1]
if median_large == median_small:
    for _ in range(N):
        print(median_large)
else:
    for i in range(N):
        if X[i] <= median_small:
            print(median_large)
        elif X[i] >= median_large:
            print(median_small)

Submission status: Accepted

Solution code:
n=int(input())
x=[int(i) for i in input().split()]
if n==2:
    for i in x[::-1]:
        print(i)
    exit()

d={}
y=sorted(x)
#for a,i in enumerate(x):
#    d[a]=i
#x.sort()
ans={}
for a,i in enumerate(y):
    if a<n//2:
        if i not in ans:
            ans[i]=y[n//2]
    elif a>=n//2:
        if i not in ans:
            ans[i]=y[n//2-1]
            #ans[i]=10000
for i in x:
    print(ans[i])
#chk=x[n//2]
#for i in range(n):
    #if i<chk: print(x[min(n-1,n//2+1)])
    #else: print(x[max(0,n//2)])
#    if i<chk: print(x[min(n-1,n//2+1)])
#    else: print(x[max(0,n//2)])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding:utf-8

INF = float('inf')


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


N = int(input())
X = inpl()
Y = sorted(X[:])
median_l = Y[N // 2 - 1]
median_r = Y[N // 2]

for x in X:
    if x <= median_l:
        print(median_r)
    else:
        print(median_l)

Submission status: Accepted

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

Submission status: Accepted

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

x_sorted = sorted(x)

mL = (n - 1) // 2
mR = mL + 1

anss = []
for i in range(n):
    if x[i] <= x_sorted[mL]:
        anss.append(x_sorted[mR])
    else:
        anss.append(x_sorted[mL])
for ans in anss:
    print(ans)

Submission status: Accepted

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

N = int(Input())
X = list(map(int, Input().split()))
l = (N-1) // 2

X_idx = [idx for idx, _ in sorted(enumerate(X), key=lambda x: x[1])]
med_r = X[X_idx[N//2]]
med_l = X[X_idx[(N//2)-1]]
for x in X:
    if x < med_r:
        print(med_r)
    else:
        print(med_l)

Submission status: Accepted

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

X_sort = sorted([[i,v] for i,v in enumerate(X)], reverse=True, key=lambda x: x[1
])
ans = [0] * N
for i in range(N):
    ans[X_sort[i][0]] = X_sort[(N//2)-(i>=(N//2))][1]
        
for a in ans:
    print(a)

Submission status: Accepted

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

X_sort = sorted([[i,v] for i,v in enumerate(X)], reverse=True, key=lambda x: x[1
])
ans = [0] * N
for i in range(N):
    if i<(N//2):
        ans[X_sort[i][0]] = X_sort[N//2][1]
    else:
        ans[X_sort[i][0]] = X_sort[(N//2)-1][1]
        
for a in ans:
    print(a)

Submission status: Accepted

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

X_sort = sorted([[i,v] for i,v in enumerate(X)], reverse=True, key=lambda x: x[1
])
ans = [0] * N
ansA = X_sort[(N//2)-1][1]
ansB = X_sort[N//2][1]
for i in range(N):
    if i<(N//2):
        ans[X_sort[i][0]] = ansB
    else:
        ans[X_sort[i][0]] = ansA
        
for a in ans:
    print(a)

Submission status: Accepted

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

xx = [(X[i], i) for i in range(N)]
xx.sort()

ans = [0 for i in range(N)]

for i in range(N):
    x, idx = xx[i]
    if i < N // 2:
        ans[idx] = xx[N // 2][0]
    else:
        ans[idx] = xx[N // 2 - 1][0]

for i in range(N):
    print(ans[i])

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

dic = {}
arr = []
for x in list(map(int,input().split())):
    arr.append(x)
sort_arr = sorted(arr)
mid1 = sort_arr[N//2-1]
mid2 = sort_arr[N//2]

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

Submission status: Accepted

Solution code:
import copy

N = int(input())
L = list(map(int,input().split()))
A = copy.deepcopy(L)
A.sort()
for i in range(N):
  if (L[i] <= A[(N//2)-1]):
    print(A[N//2])
  else:
    print(A[(N//2)-1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

c=int(n/2)
a=x[c]
b=x[c-1]

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

Submission status: Accepted

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

def solver():
    # mr.zehnpaard
    from statistics import median_low, median_high

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

    m1, m2 = median_low(xs), median_high(xs)

    medians = (str(m2 if x < m2 else m1) for x in xs)
    print('\n'.join(medians))

def main():
    from statistics import median_low, median_high

    N = int(input())
    Xs = list(map(int, input().split()))
    m_low, m_high = median_low(Xs), median_high(Xs)

    for x in Xs:
        ans = m_high if x <= m_low else m_low
        print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# coding: utf-8

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

Y = sorted(X)

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

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N = inp()
xx = inpl()
xx_sort = sorted(xx)
half1 = xx_sort[N//2-1]
half2 = xx_sort[N//2]

for i in range(N):
	if xx[i] <= half1:
		print(half2)
	else:
		print(half1)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A1 = []
for nums in A:
  A1.append(nums)
A.sort()
m1 = A[N//2-1]
m2 = A[N//2]
if m1 != m2:
  for nums in A1:
    if nums <= m1:
      print(m2)
    else:
      print(m1)

else:
  for nums in A1:
    print(m1)

Submission status: Accepted

Solution code:
N = int(raw_input())
X = map(int, raw_input().split())
memo = []
for i in range(0, N):
	memo.append(X[i])
memo.sort()
twomed = [memo[N/2-1], memo[N/2]]

for i in range(0, N):
	if X[i] <= twomed[0]: print twomed[1]
	else: print twomed[0]

Submission status: Accepted

Solution code:
import statistics

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

high = statistics.median_high(x)
low = statistics.median_low(x)

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

Submission status: Accepted

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

Y = sorted(X)
L = Y[int(N/2 - 1)]
R = Y[int(N/2)]

for i in range(N):
    if X[i] > L:
        print(L)
    else:
        print(R)

Submission status: Accepted

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

for i in range(N):
    if Xcopy[i] <= left:
        print(right)
    elif Xcopy[i] >= right:
        print(left)

Submission status: Accepted

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

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

Y[int(N/2)]


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main18():
    num = int(input(""));
    buf = input("");
    bufs = buf.split();
    hai = [];
    for i in range(len(bufs)):
        hai.append(int(bufs[i]));
    manhidari = int(num/2);
    manmigi = manhidari + 1;
    kari = hai[:];
    kari.sort();
    hidarin = kari[manhidari-1];
    migin = kari[manmigi-1];

    for i in range(len(hai)):
        if hai[i] >hidarin:
            print(hidarin);
        else:
            print(migin);

if __name__ == '__main__':
    main18()

Submission status: Accepted

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

for i in range(N) :
    if Y[i] >= bigger :
        print(smaller)
    else :
        print(bigger)

Submission status: Accepted

Solution code:
N = int(input())
x_list = [i for i in list(map(int, input().split()))]
tmp = x_list.copy()
x_list.sort()
big = x_list[len(x_list)//2]
small = x_list[len(x_list)//2-1]

for x in tmp:
    if x >= big:
        print(small)
    else:
        print(big)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
x_tmp = input().split()
x = [[0 for j in range(3)] for i in range(n)]
for i in range(n):
    x[i][0] = int(x_tmp[i])
    x[i][1] = i
x = sorted(x, key=lambda y: y[0])
mid = n//2
for i in range(n):
    if i <= mid-1:
        x[i][2] = x[mid][0]
    else:
        x[i][2] = x[mid-1][0]
x = sorted(x, key=lambda y: y[1])
for i in range(n):
    print(x[i][2])

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
#N / 2 or N / 2 + 1番目
center1 = sorted(X)[int(N / 2) - 1]
center2 = sorted(X)[int(N / 2)]
for i in range(N):
    if X[i] > center1:
        print(center1)
    else:
        print(center2)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np

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

A = np.sort(X)
m1 = A[ N // 2 - 1]
m2 = A[ N // 2]
ans = []
for i in range(N):
    if X[i] < m2:
        print(m2)
    else:
        print(m1)

Submission status: Accepted

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

Xs = sorted(X)

a, b = Xs[int(N/2-1)], Xs[int(N/2)]

for x in X:
  if x <= a:
    print(b)
  elif x >= b:
    print(a)

Submission status: Accepted

Solution code:

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

Xs = sorted(X)
m1 = Xs[int(N/2)-1]
m2 = Xs[int(N/2)]

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