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 find(A):
    X=[(A[i],i) for i in range(len(A))]
    X=sorted(X)
    ans=[0]*len(X)
    p1=(len(A)-1)//2
    p2=len(A)//2
    #print(p1,p2)
    for i in range(len(X)):
        a,b=X[i]
        if i<p2:
            ans[b]=X[p2][0]
        else:
            ans[b]=X[p1][0]
    return ans
input()
A=[str(x) for x in find(list(map(int,input().strip().split(" "))))]
print("\n".join(A))

Submission status: Accepted

Solution code:
N = int(input())
X = [int(i) for i in input().split()]
Y = sorted(X)
left = Y[N//2 -1]
right = Y[N//2 ]
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()))
x_ = sorted(x)
a = x_[int(len(x)/2)-1]
b = x_[int(len(x)/2)]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ARC095C - Many Medians (ABC094C)
def main():
    n = int(input())
    x = tuple(map(int, input().rstrip().split()))
    l, h = sorted(x)[n // 2 - 1 : n // 2 + 1]
    for i in x:
        print(h if i <= l else l)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ARC095C - Many Medians (ABC094C)
def main():
    n = int(input())
    x = tuple(map(int, input().rstrip().split()))
    l, h = sorted(x)[n // 2 - 1 : n // 2 + 1]
    for i in x:
        if i <= l:
            print(h)
        else:
            print(l)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ARC095C - Many Medians (ABC094C)
def main():
    n = int(input())
    x = list(map(int, input().rstrip().split()))
    l, h = sorted(x)[n // 2 - 1 : n // 2 + 1]
    for i in x:
        if i <= l:
            print(h)
        else:
            print(l)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

S = sorted(X)

med_left = S[N//2 - 1]
med_right = S[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())
li = [ int(it) for it in input().split() ]
go = [ (li[i],i) for i in range(N)]
go.sort( key= lambda x:x[0])
po = [0]*N
for i in range(N):
  if (i < N//2):
    po[go[i][1]] = (go[N//2][0])
  else:
    po[go[i][1]] = (go[N//2-1][0])
for i in range(N):
  print ( po[i] )

Submission status: Accepted

Solution code:
n,*x=map(int,open(0).read().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()))
P = []
for i in range(N):
    P.append((X[i], i))

P = sorted(P)
med = [P[N // 2 - 1][0], P[N // 2][0]]
ans = [0] * N
for i in range(N):
    if P[i][0] <= med[0]:
        ans[P[i][1]] = P[N // 2][0]
    else:
        ans[P[i][1]] = P[N // 2 - 1][0]

for i in ans:
    print(i)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

SX = [[i, X[i]] for i in range(len(X))]
SX = sorted(SX, key=lambda x:x[1])

lm = SX[N//2-1][1]
rm = SX[N//2][1]

res = [0] * N
for i in range(len(SX)):
    if i < N // 2:
        res[SX[i][0]] = rm
    else:
        res[SX[i][0]] = lm


for r in res:
    print(r)

Submission status: Accepted

Solution code:
n = int(input())
xs = list(map(int, input().split()))
ds = sorted(xs)
m = n // 2 - 1

bs = [ds[m] if xs[i] > ds[m] else ds[m+1] for i in range(n)]

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

Submission status: Accepted

Solution code:
N = int(input())
x = list(map(int, input().split()))
x_s = sorted(x)
m_l, m_r = x_s[N // 2 - 1], x_s[N // 2]
d = dict()
for i, s in enumerate(x_s):
    if i < N // 2:
        d[s] = m_r
    else:
        d[s] = m_l
for i in x:
    print(d[i])

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())
d=0
l=[]
a=sorted(enumerate(a),key=lambda x:x[1])
b=a[n//2][1]
c=a[n//2-1][1]
for(k,v)in a:
    d+=1
    if d<n//2+1:
        l.append((k,b))
    else:
        l.append((k,c))
#print(l)
for(k,v)in sorted(l,key=lambda x:x[0]):
    print(v)

Submission status: Accepted

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

Y = sorted(X)
a1 = Y[N//2 - 1]
a2 = Y[N//2]

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

Submission status: Accepted

Solution code:
from math import *

n = int(input())

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

a_sort = sorted(a)

median_right = a_sort[floor(len(a_sort) / 2)]
median_left = a_sort[floor(len(a_sort) / 2) - 1]

for i in range(len(a)):
	if a[i] > median_left:
		print(median_left)
	else:
		print(median_right)

Submission status: Accepted

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

Submission status: Accepted

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

b=sorted(a)

a1=b[(N-1)//2]
a2=b[(N-1)//2+1]

for i in a:
    if(i<=a1):
        print(a2)
    else:
        print(a1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve(N, Xs):
    sorted_Xs = sorted(Xs)
    left = sorted_Xs[N // 2 - 1]
    right = sorted_Xs[N // 2]
    ans = []
    for x in Xs:
        if x <= left:
            ans.append(right)
        else:
            ans.append(left)
    return "\n".join(str(i) for i in ans)

if __name__ == "__main__":
    N = int(input())
    Xs = list(map(int, input().split(" ")))
    print(solve(N, Xs))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    x = [int(i) for i in input().split()]
    newx = sorted(x)
    ans = dict()
    for i,xx in enumerate(newx):
        if i+1 <= n//2:
            ans[xx] = newx[n//2]
        else:
            ans[xx] = newx[n//2-1]
    for xx in x:
        print(ans[xx])

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def inpl(): return [int(i) for i in input().split()]
N = int(input())
X = inpl()
Y = sorted(X)
a = Y[N//2-1]
b = Y[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()))

use = x[::]
use.sort()

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

Submission status: Accepted

Solution code:
N = int(input())

a = list(map(int,input().split(' ')))

sorted_a = sorted(a)

for i in range(N):
    if a[i] < sorted_a[int(N/2)]:
        print(sorted_a[int(N/2)])
    else:
        print(sorted_a[int(N/2)-1])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import bisect

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

X2 = sorted(X)

for i in range(0, N):
    # idx = X2.index(X[i])
    idx = bisect.bisect_left(X2, X[i])
    if idx < N // 2:
        print(X2[N // 2])
    else:
        print(X2[N // 2 - 1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int,input().split()))
Y=X[:]
Y.sort()
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:
import copy
n=int(input())
a=list(map(int,input().split()))
b=a.copy()
a.sort()
for i in range(n):print(a[n//2 if a[n//2]>b[i]else n//2-1])

Submission status: Accepted

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

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:
#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))
b = sorted(a)
for a_i in a:
    if a_i <= b[n // 2 - 1]:
        c = b[n // 2]
    else:
        c = b[n // 2 - 1]
    print(c)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
x = [int(i) for i in input().split()]
xx = sorted(x)
mid = n//2-1

d = {}
for i in range(n):
    if i<=mid:
        d[xx[i]] = xx[mid+1]
    else:
        d[xx[i]] = xx[mid]

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

Submission status: Accepted

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

Submission status: Accepted

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

med = sorted(X_list)[median-1:median+1]
for i in range(N):
    if X_list[i] < med[1]:
        print(med[1])
    else:
        print(med[0])

Submission status: Accepted

Solution code:
from bisect import *

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

N = read()
X = reads()
sX = sorted(X)

ml = sX[N//2 - 1]
mr = sX[N//2]

for x in X:
    print(mr if x <= ml else ml)

Submission status: Accepted

Solution code:
import numpy as np

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

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

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

Submission status: Accepted

Solution code:
import numpy as np

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

sort_X = np.sort(X)
l = sort_X[int(N/2 - 1)]
r = sort_X[int(N/2)]

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

Submission status: Accepted

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

a = Y[int(N / 2 - 1)]
b = Y[int(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()))

A=X.copy()
A.sort(reverse=True)

left=A[int(N/2)-1]
right=A[int(N/2)]

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

Submission status: Accepted

Solution code:
N = int(input())
X = [int(i) for i in input().split()]
ans=[]
Y=sorted(X)
a=Y[N//2 -1]
b=Y[N//2]
for x in X:
    if x<= a:
        ans.append(b)
    else:
        ans.append(a)
print('\n'.join(map(str,ans)))

Submission status: Accepted

Solution code:
N = int(input())

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

A = sortX[(N//2)-1]
B = sortX[(N//2)]

for x in X:
    if x<B: print(B)
    else: print(A)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
import copy


# 標準入力
n = int(sys.stdin.readline().strip())
xArray = list(map(int, sys.stdin.readline().strip().split(" ")))

result = []

sortedArray = sorted(xArray)


# 中央値を算出する
for i in range(n):
    midIndex = int(n / 2) -1
    if (sortedArray[midIndex] >= xArray[i]):
        result.append(sortedArray[midIndex + 1])
    else:
        result.append(sortedArray[midIndex])


# 標準出力
print('\n'.join(map(str, result)))

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
import copy


# 標準入力
n = int(sys.stdin.readline().strip())
xArray = list(map(int, sys.stdin.readline().strip().split(" ")))

result = []

sortedArray = sorted(xArray)


# 中央値を算出する
for i in range(n):
    middle = sortedArray[int((n / 2) - 1)]
    if (middle >= xArray[i]):
        result.append(sortedArray[int(n / 2)])
    else:
        result.append(middle)


# 標準出力
print('\n'.join(map(str, result)))

Submission status: Accepted

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

Y = sorted(X)

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

Submission status: Accepted

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

Submission status: Accepted

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


Y=sorted(X)
yu=Y[N]
yd=Y[N-1]
for x in X:
	if x<=yd:
		print(yu)
	else:
		print(yd)

Submission status: Accepted

Solution code:
from numpy import median
from copy import deepcopy

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

sx = sorted(x)
newl = deepcopy(sx)
del newl[0]
maxm = median(newl)
newl = deepcopy(sx)
del newl[-1]
minm = median(newl)

med = median(x)

for i in x:
    if i > med:
        print(int(minm))
    else:
        print(int(maxm))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
A = [int(i) for i in input().split(" ")]
B=A[:]
B.sort()
for i in range(n):
    if A[i]<=B[n//2 - 1]:
        print(B[n//2])
    else:
        print(B[n//2-1])

Submission status: Accepted

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

Submission status: Accepted

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

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

for i in range(N):
  if X[i] < m:
    res = X_sorted[N // 2]
  elif X[i] >= m:
    res = X_sorted[N // 2 - 1]

  print(res)

Submission status: Accepted

Solution code:
n=int(input());*a,=map(int,input().split());b=sorted(a);l,m=b[n//2-1],b[n//2]
for x in a:print([l,m][x<m])

Submission status: Accepted

Solution code:
N = int(input())
b = [int(i) for i in input().split()]
c = sorted(b[:])
s = c[(N-1)//2]
l = c[N//2]

for i in b:
    if i > s:
       print(s)
    else:
       print(l)

Submission status: Accepted

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

Submission status: Accepted

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

x = sorted(X)
ml = x[N//2 - 1]
mr = x[N//2]

for x in X:
    if x <= ml:
        print(mr)
    else:
        print(ml)

Submission status: Accepted

Solution code:
import numpy as np
n=int(input())
x=list(map(int,input().split(' ')))
x1=x[:]
x.sort()
m1=x[int(n/2)-1]
m2=x[int(n/2)]
for i in range(n):
    now=x1[i]
    if x1[i]<=m1:
        print(m2)
    else:
        print(m1)

Submission status: Accepted

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

Submission status: Accepted

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

# Nを取得
n = int(input())

# Xiを取得
xs = list(map(int, input().split()))

# 昇順にソートしたXiを取得
xs_sorted = sorted(xs)

# Xiの個数およびその1/2の値を取得
l = len(xs_sorted)
l_mid = int(l / 2)

# iが全体の1/2より小さい時、大きい時の中間値をそれぞれ取得
xs_mid_1 = xs_sorted[l_mid - 1]
xs_mid_2 = xs_sorted[l_mid]

# 結果を出力
for x in xs:
    if x < xs_mid_2:
        print("{}".format(xs_mid_2))
    else:
        print("{}".format(xs_mid_1))

Submission status: Accepted

Solution code:
N = int(input())
N_d = int(N/2)
X1 = list(map(int,input().split()))
X = X1[:]
X1.sort()

def getMed(i):
  if i  < X1[N_d]:
    print(X1[N_d])
  else:
    print( X1[N_d -1])

for i in X:
  getMed(i)

Submission status: Accepted

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

X.sort()

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

Submission status: Accepted

Solution code:
N = int(input())

X = input().split()
x1 = [int(x) for x in X]
x2 = [int(x) for x in X]

x2.sort()
ml = x2[int((N/2)-1)]
mr = x2[int(N/2)]

for i in range(N):
    if x1[i] <=  ml:
        print("%d"%mr)
    else:
        print("%d"%ml)

Submission status: Accepted

Solution code:
import copy

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

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

largeMedian = Y[int(N / 2)]
smallMedian = Y[int(N / 2)-1]

for i in range(N):
    if X[i] <= smallMedian:
        X[i] = largeMedian
    else:
        X[i] = smallMedian

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

Submission status: Accepted

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

base = int((n + 1) // 2) - 1
median = sorted_l[base]
for i in l:
    if i <= median:
        print(sorted_l[base + 1])
    else:
        print(sorted_l[base])

Submission status: Accepted

Solution code:
n = int(input())
x = [int(a) for a in input().split()]
sorted_x = sorted(x)
for elem in x:
    if elem >= sorted_x[(len(x) + 1) // 2]:
        print(sorted_x[(len(x) + 1) // 2 - 1])
    else:
        print(sorted_x[(len(x) + 1) // 2])

Submission status: Accepted

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

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

Submission status: Accepted

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

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    a = LI()
    s = sorted(a)
    r = []
    if n % 2 == 0:
        b = s[n//2-1]
        c = s[n//2]
        for t in a:
            if t <= b:
                r.append(c)
            else:
                r.append(b)
    else:
        b = s[n//2]
        c = s[n//2-1]
        for t in a:
            if t >= b:
                r.append(c)
            else:
                r.append(b)


    return '\n'.join(map(str,r))


print(main())

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
a = sorted(range(n), key=lambda i: x[i])
l = x[a[n//2-1]]
r = x[a[n//2]]
b = [0]*n
for i, j in enumerate(a):
    if i < n//2:
        b[j] = r
    else:
        b[j] = l
for e in b:
    print(e)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Contents   : AtCoder Regular Contest 095 c問題
Author     : Kitaura Hiromi
LastUpdate : 20180414
Since      : 20180414
"""
import random
import copy

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

Submission status: Accepted

Solution code:
n = int(input())
p = list(map(int,input().split()))
q = sorted(p)
med_1 = q[n//2-1]
med_2 = q[n//2]

for i in range(n):
    if p[i] == med_1:
        print(med_2)
    elif p[i] == med_2:
        print(med_1)
    elif p[i] < med_1:
        print(med_2)
    else:
        print(med_1)

Submission status: Accepted

Solution code:
import numpy as np
N = int(raw_input())
line = np.array(map(int,raw_input().split()))

line2 = np.sort(line)
t = (float(line2[N / 2 -1]) + float(line2[N / 2])) / 2

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

Submission status: Accepted

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


n = int(input())
X = [int(x) for x in input().split()]
X_sorted = sorted(X)

med_l = X_sorted[n // 2 - 1]
med_u = X_sorted[n // 2]
med = (med_l + med_u) / 2

for x in X:
    if x < med:
        print(med_u)
    else:
        print(med_l)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(zip(map(int, input().split()), range(n)))
b = [0] * n
for i in range(n//2):
  b[i], b[n - i - 1] = (a[n//2][0], a[i][1]), (a[n//2 - 1][0], a[n - i - 1][1])
print('\n'.join(map(lambda x: str(x[0]), sorted(b, key = lambda x: x[1]))))

Submission status: Accepted

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

N = int(input())
ns = inpl()
nss = sorted(ns)
c1 = nss[int(N/2)-1]
c2 = nss[int(N/2)]
for i in range(N):
	if ns[i] <= c1:
		print(c2)
	else:
		print(c1)

Submission status: Accepted

Solution code:
import numpy as np

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

n_list2 = list(n_list1)
n_list_test = list(n_list1)


n_list_max = np.max(n_list1)
n_list_min = np.min(n_list2)

n_list1.remove(n_list_max)
n_list2.remove(n_list_min)

# print(np.max(n_list))
# np.median(n_list - )
n_list1_median = int(np.median(n_list1))
n_list2_median = int(np.median(n_list2))

for x in n_list_test:
  if n_list1_median >= x:
    print(n_list2_median)
  else:
    print(n_list1_median)

Submission status: Accepted

Solution code:
f = lambda :[int(i) for i in input().split()]
from sys import stderr
from functools import reduce
from operator import add
debug = lambda *x:stderr.write(reduce(add,repr(x))+'\n')

n = int(input())
x = f()
y = sorted(x)
med = (y[int(n/2)]+y[int(n/2)-1])/2
lmed = y[int(n/2)]
smed = y[int(n/2)-1]

for po in x:
    if po < med:
        print(lmed)
    else:
        print(smed)

Submission status: Accepted

Solution code:
import random


def mid_1(X):
    return X[(len(X)) // 2]


def mid(X):
    return X[(len(X)) // 2 - 1]


def main():
    N = int(input())

    X = list(map(int, input().split()))
    # N = 200000
    # X = [random.randint(0, 1000000000) for _ in range(N)]
    X_ = X[:]
    X_.sort()
    X__ = X_[:N // 2]
    X__ = X__[-1]

    x_1 = mid_1(X_)
    x = mid(X_)

    ans = []
    # print(X_)
    # print(X__)
    for i in range(N):
        if X[i] <= X__:
            print(x_1)
            # ans.append(x_1)
        else:
            print(x)
            # ans.append(x)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

sortedX = sorted(X)
medSmall = sortedX[N/2-1]
medLarge = sortedX[N/2]

#print medSmall, medLarge

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

Submission status: Accepted

Solution code:
import sys
from collections import Counter
import random
import numpy as np

n=int(input())
x=np.array(list(map(int,input().split())))
z=sorted(x)
cand=[z[n//2-1],z[n//2]]
#print(int(np.median(x)))
dic={}
for i in range(n):
    a=x[i]
    if(a<=cand[0]):print(cand[1])
    else:print(cand[0])

Submission status: Accepted

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

sx = np.sort(X)
for i in range(N):
    if X[i] >= sx[N//2]:
        print(sx[N//2-1])
    else:
        print(sx[N//2])

Submission status: Accepted

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

n = int(input())
xx = list([i, x] for i, x in enumerate(map(int, input().split())))
xx.sort(key=lambda x: x[1])

mid1 = xx[n // 2][1]
mid2 = xx[n // 2 - 1][1]
for i in range(n // 2):
    xx[i][1] = mid1
for i in range(n // 2, n):
    xx[i][1] = mid2

xx.sort()
print('\n'.join(str(x[1]) for x in xx))

Submission status: Accepted

Solution code:

n = int(input())
x = list(map(int, input().split()))
x_sort = x.copy()
x_sort.sort()
row = x_sort[n//2 - 1]
high = x_sort[n//2]

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

Submission status: Accepted

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

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

Submission status: Accepted

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

import numpy as np
import copy

n = int(raw_input())
x = map(int,raw_input().split())

x_min = copy.copy(x)
x_max = copy.copy(x)

x_min.remove(max(x))
x_max.remove(min(x))

med_x_min = int(np.median(x_min))
med_x_max = int(np.median(x_max))

if med_x_max == med_x_min:
    for i in range(n):
        print med_x_max
else:
    for i in range(n):
        if x[i] >= med_x_max:
            print med_x_min
        else:
            print med_x_max

Submission status: Accepted

Solution code:
#!/usr/bin/env python
import numpy as np
N = int(input())
X = np.array(list(map(int, input().split())))
idx = X.argsort()
low = idx[N//2-1]
high = idx[N//2]

res = np.zeros(N, dtype=int)
res[idx[:N//2]] = X[high]
res[idx[N//2:]] = X[low]

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

Submission status: Accepted

Solution code:
import numpy as np

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

rank = np.argsort(X)
irank = {k: v for v, k in enumerate(rank)}

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

Submission status: Accepted

Solution code:
input()
xs = list(map(int, input().split()))
sortx = sorted(xs)
l = len(xs)
t = (l+1)//2 - 1
medv = sortx[t]
if l%2 == 0:
    v1 = medv
    v2 = sortx[t+1]
    for x in xs:
        if x <= medv:
            print(v2)
        else:
            print(v1)
else:
    v1 = sortx[t-1]
    v2 = medv
    for x in xs:
        if x < medv:
            print(v2)
        else:
            print(v1)

Submission status: Accepted

Solution code:
n = int(input())
x = []
x = list(map(int,input().split(' ')))
y = []
for i in range(len(x)):
    y.append(x[i])

y.sort()

#print(x)
#print(y)

b = int(n/2)
s = int(n/2)-1

if n == 2:
    print(x[1])
    print(x[0])
else:
    for i in range(n):
        if x[i] >= y[b]:
            print(y[s])
        else:
            print(y[b])

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
Y = X.copy()
Y.sort()
if N % 2 == 1:
    Bmin = Y[N // 2 - 1]
    Bmid = Y[N // 2]
    Bmax = Y[N // 2 + 1]
    for i in X:
        if i < Bmid:
            print((Bmid + Bmax) / 2)
        elif i > Bmid:
            print((Bmid + Bmin) / 2)
        else:
            print(Bmid)
else:
    Bmin = Y[N // 2 - 1]
    Bmax = Y[N // 2]
    for i in X:
        if i <= Bmin:
            print(Bmax)
        elif i >= Bmax:
            print(Bmin)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))
Y = sorted(X)
ans1 = Y[N//2-1]#小さいほう
ans2 = Y[N//2]#大きいほう
for i in range(N):
  if X[i] <= ans1: print(ans2)
  else: print(ans1)

Submission status: Accepted

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

m1 = l[n//2 - 1]
m2 = l[n//2]
for i in range(len(l0)):
    if l0[i] < m2:
        print(m2)
    elif l0[i] > m1:
        print(m1)
    elif l0[i] == m1:
        print(m2)
    elif l0[i] == m2:
        print(m1)