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:
#                         author:  kagemeka 
#                         created: 2019-11-07 11:52:43(JST)
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator

def main():
    n, *x = (int(i) for i in sys.stdin.read().split())
    s_x = list(sorted(x))
    half = n // 2
    m_s, m_l = s_x[half - 1], s_x[half]
    for i in x:
        print(m_l if i < m_l else m_s)

if __name__ == "__main__":
    # execute only if run as a script
    main()

Submission status: Accepted

Solution code:
#                         author:  kagemeka 
#                         created: 2019-11-07 11:52:43(JST)
import sys
# import collections
# import math
# import string
import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator

def main():
    n, *x = (int(i) for i in sys.stdin.read().split())
    s_x = list(sorted(x))
    half = n // 2
    m_s, m_l = s_x[half -1], s_x[half]
    for i in x:
        b = bisect.bisect_left(s_x, i)
        print(m_l if b < half else m_s)

if __name__ == "__main__":
    # execute only if run as a script
    main()

Submission status: Accepted

Solution code:
#                         author:  kagemeka 
#                         created: 2019-11-07 11:52:43(JST)
import sys
# import collections
# import math
# import string
import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator

def main():
    n, *x = (int(i) for i in sys.stdin.read().split())
    s_x = list(sorted(x))
    m_s, m_l = s_x[n // 2 -1], s_x[n // 2]
    for i in x:
        b = bisect.bisect_left(s_x, i)
        print(m_l if b < n // 2 else m_s)

if __name__ == "__main__":
    # execute only if run as a script
    main()

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
nx=x[:]
nx.sort()
med1=nx[n//2-1]
med2=nx[n//2]
for sx in x:
    if sx > med1:
        print(med1)
    else:
        print(med2)

Submission status: Accepted

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

x_sorted = sorted(x)
l = x_sorted[n//2]
s = x_sorted[n//2-1]

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

x_sorted = sorted(x)
larger_candidate = x_sorted[n//2]
smaller_candidate = x_sorted[n//2-1]

for i in range(len(x)):
    if x[i] <= smaller_candidate:
        print(larger_candidate)
    else:
        print(smaller_candidate)

Submission status: Accepted

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

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())
list = list(map(int, input().split()))
list1 = sorted(list)
median_candidate1, median_candidate2 = list1[n//2-1], list1[n//2]
for i in list:
    if i <= median_candidate1:
        print(median_candidate2)
    else:
        print(median_candidate1)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
b = sorted(a)
cl = b[(n-1)//2]
cr = b[n//2]
for i in range(n):
    if a[i] <= cl:
        print(cr)
    elif cr <= a[i]:
        print(cl)

Submission status: Accepted

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

Dict={}

for i,Num in enumerate(A):
    Dict[i]=Num

List = sorted(Dict.items(), key=lambda x:x[1])
S=List[(N//2)-1][1]
B=List[(N//2)][1]
for i in range(N):
    if(Dict[i]<=S):
        print(B)
    else:
        print(S)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

X_sort=sorted(X)

if X_sort[N//2-1]==X_sort[N//2]:
    for n in range(N):
        print(X_sort[N//2])
else:
    if X_sort.count(X_sort[N//2-1])==1:
        for n in range(N):
            if X[n]>X_sort[N//2-1]:
                print(X_sort[N//2-1])
            else:
                print(X_sort[N//2])
    else:
        for n in range(N):
            if X[n]>X_sort[N//2-1]:
                print(X_sort[N//2-1])
            else:
                print(X_sort[N//2])

Submission status: Accepted

Solution code:
N = int(input())
X = sorted([[x,i] for i, x in enumerate(map(int,input().split()))])
med1,med2 = X[(N-1)//2][0], X[(N-1)//2+1][0]
ans = []
for idx1, x in enumerate(X):
  if idx1 <= (N-1)//2: ans.append([x[1],med2])
  else: ans.append([x[1],med1])
  #print(i)
[print(med) for i, med in sorted(ans)]

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
l1=[[l[i],i] for i in range(n)]
l1.sort() 
mi=n//2 
cand1=l1[mi][0]
ind1=l1[mi][1]
cand2=l1[mi-1][0]
ind2=l1[mi][1]
if ind1>ind2:
    ind1,ind2=ind2,ind1
    cand1,cand2=cand2,cand1
ans=[0]*n 
#print(cand1,cand2)
#print(l)
for i in range(n): 
    if l[i]<=cand2:
        print(cand1)
    else:
       # print('fshd')
        print(cand2)

Submission status: Accepted

Solution code:
import math
import copy
#import sys
#import bisect
#input = sys.stdin.readline
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return((a*b)//gcd(a,b))

def main():
    #x,y = map(int,input().split())	x=1,y=2
    #a = input().split()	a=['1','2','3',...,'n']
    #a = list(map(int,input().split()))	a=[1,2,3,4,5,...,n]
    #li = input().split('T')	FFFTFTTFF => li=['FFF', 'F', '', 'FF']
    n=int(input())
    a = list(map(int,input().split()))
    b=copy.copy(a)
    a.sort()
    for i in range(n):
        x=b[i]
        if x<=a[(n//2)-1]:
            print(a[(n//2)])
        else:
            print(a[(n//2)-1])

main()

Submission status: Accepted

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

Xlist_sorted = sorted(Xlist)
idx = (N-1) // 2
candidates = [Xlist_sorted[idx], Xlist_sorted[idx+1]]

for i in range(N):
    if Xlist[i] >= candidates[1]:
        print(candidates[0])
    else:
        print(candidates[1])

Submission status: Accepted

Solution code:
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 >= 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 u in x:
    if u<=a:
        print(b)
    else:
        print(a)

Submission status: Accepted

Solution code:
def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy

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

Y=sorted(X.copy())

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:
import copy
N = int(input())
X = list(map(int, input().split()))
L =copy.copy(X)
X.sort()
for i in L:
   if i <=X[N//2-1]:
      print(X[N//2])
   elif i >=X[N//2]:
      print(X[N//2-1])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def slove():
    import sys
    import copy
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    x = list(map(int, input().rstrip('\n').split()))
    xl = copy.deepcopy(x)
    xl.sort()
    a = xl[n // 2-1]
    b = xl[n // 2]
    for i in range(n):
        if x[i] <= a:
            print(b)
        elif b <= x[i]:
            print(a)


if __name__ == '__main__':
    slove()

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):
  print(a if x[i] > a else b)

Submission status: Accepted

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

SORTED = sorted(X)
med1 = SORTED[N//2 - 1]
med2 = SORTED[N//2]
# print(med1, med2)

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

Submission status: Accepted

Solution code:
def main():

    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//2-1])

if __name__ == '__main__':
    # print(main())
    main()

Submission status: Accepted

Solution code:
n = int(input())
k = [[int(i)] for i in input().split()]
for i in range(n):
    k[i].append(i)
k.sort()
a = k[n//2-1][0]
b = k[n//2][0]
ans = [0]*200010
for i in range(n//2):
    ans[k[i][1]] = b
for i in range(n//2,n):
    ans[k[i][1]] = a
for i in range(n):
    print(ans[i])

Submission status: Accepted

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

median_left = statistics.median_low(x)
median_right = statistics.median_high(x)

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

Submission status: Accepted

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

median_left = statistics.median_low(x)
median_right = statistics.median_high(x)

for i in range(n):
  if x[i] == median_right:
    print(median_left)
  elif x[i] == median_left:
    print(median_right)
  else:
    if x[i] < median_left:
      print(median_right)
    else:
      print(median_left)

Submission status: Accepted

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

y=sorted(x)
a = y[N//2]
b = y[N//2-1]

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

Submission status: Accepted

Solution code:
import copy

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

Submission status: Accepted

Solution code:
from operator import itemgetter
N = int(input())
X = list(map(int, input().split()))
data = []
for i in range(N):
    data.append([X[i],i])

data.sort()
k = (N//2) - 1
f = data[k][0]
s = data[k+1][0]
#print("f {}  s{}".format(f,s))
data = sorted(data, key = lambda x:x[1])
for i in range(N):
    if data[i][0] <= f:
        print(s)
    else:
        print(f)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N):
  if a[i] >= ans[0]:
    print(ans[1])
  else:
    print(ans[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

x = sorted(x_org)

mid = x[n // 2 - 1]
midr = x[n // 2]

for i in range(n) :
    if x_org[i] <= mid :
        print(midr)
    else :
        print(mid)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
import os
import copy
N = int(input())
X = list(map(int,input().split()))
XX = copy.deepcopy(X)
X.sort()
mid = X[N//2-1]
midr = X[N//2]
ans = 0
for x in XX:
    if x <= mid:
        ans = midr
    elif midr <= x:
        ans = mid
    print(ans)
    ans = 0

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

XX=sorted(X)

for item in X:
    if item<=XX[len(XX)//2-1]:
        print(XX[len(XX)//2])
    else:
        print(XX[len(XX)//2-1])

Submission status: Accepted

Solution code:
import copy

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

sort_X = copy.copy(X)
sort_X.sort()
small_median_X = sort_X[N//2 - 1]
big_median_X = sort_X[N//2]

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

Submission status: Accepted

Solution code:
N = int(input())
array = list(map(int, input().split()))
array_sorted = sorted(array)
ans = [array_sorted[(N//2)-1],array_sorted[N//2]]
for item in array:
    if item <= ans[0]:
        print(ans[1])
    else:
        print(ans[0])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

sa = copy.copy(a)
sa.sort()
L = sa[n//2 -1]
R = sa[n//2]
for i in a:
    if i <=L:
        print(sa[n//2])
    elif i>=R:
        print(sa[n//2 - 1])

Submission status: Accepted

Solution code:
#094c
import copy
N = int(input()) #N<200000=2 * 10**5
X_list = [int(e) for e in input().split()]

sort_X_list = copy.copy(X_list)
sort_X_list.sort(reverse=False)
Bi_smaller = sort_X_list[int(len(X_list)/2-1)]
Bi_bigger = sort_X_list[int(len(X_list)/2)]

for i in range(N):
    if X_list[i]>=Bi_bigger:
        print(Bi_smaller)
    else:
        print(Bi_bigger)

Submission status: Accepted

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

x2 = x.copy()
x2.sort()
tmp = x2[n // 2]
tmp2 = x2[n // 2 - 1]

for i in x:
    if i <= tmp2:
        print(tmp)

    else:
        print(tmp2)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    X = [(int(i),idx) for idx,i in enumerate(input().split())]
    Y = [(i,idx) for idx,i in enumerate(sorted(X))]
    ans1 = Y[(N//2)][0][0]
    ans2 = Y[N//2-1][0][0]
    Y.sort(key=lambda p: p[0][1])
    for y in Y:
        if y[1] <= N//2 - 1:
            print(ans1)
        else:
            print(ans2)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# AC
# 入力
n = int(input())
org_nums = list(map(int, input().split()))
# ソートは一回だけして、取り去る順番を明確にしてから１つずつ取り去り計算を行いたい
sorted_nums = sorted(org_nums) # 入力数列のソート
sorted_index = sorted(range(len(org_nums)), key=lambda k: org_nums[k]) #ソートされたリストから取り去る順番がわかる
extract_index = sorted(range(len(sorted_index)), key=lambda k: sorted_index[k]) #ソートされたリストから取り出すインデックスを取り出す順に並べる
#print(extract_index)
for i in extract_index:
    if i+1 <= n // 2:
        print(sorted_nums[n//2])
    else:
        print(sorted_nums[n//2-1])

Submission status: Accepted

Solution code:
from heapq import heappush, heappop

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

m = int(n/2)-1
x_tmp = sorted(x)

for i in range(n):
    if x[i] <= x_tmp[m]:
        print(x_tmp[m+1])
    else:
        print(x_tmp[m])

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    n=int(input())
    xx=list(map(int, input().split()))
    cxx=sorted(xx)
    m0=cxx[n//2-1]
    m1=cxx[n//2]
    for x in xx:
        if x<=m0:print(m1)
        else:print(m0)

main()

Submission status: Accepted

Solution code:
n = int(input()) # n is even
x = [int(i) for i in input().split()]
medPlus = sorted(x)[n // 2]
medMinus = sorted(x)[n // 2 - 1]
for i in range(n):
    print(str(medPlus) if x[i] <= medMinus else str(medMinus))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
b = sorted(a)
l,r = b[n//2-1],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()))
XX=[]
for i in range(N):
    XX.append([X[i],i])
XX=sorted(XX,key=lambda x:x[0])

for i in range(N):
    if i<=N//2-1:
        XX[i].append(XX[N//2][0])
    else:
        XX[i].append(XX[N//2-1][0])

XX=sorted(XX,key=lambda x:x[1])

for i in range(N):
    print(XX[i][2])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
z=sorted(x)
for i in range(n):
    if(x[i]<z[n//2]):
        print('{0}'.format(z[n//2]))
    else:
        print('{0}'.format(z[n//2-1]))

Submission status: Accepted

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

Submission status: Accepted

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

X_s = sorted(X)

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

Submission status: Accepted

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

X_s = sorted(X)

median = [X_s[N//2-1], X_s[N//2]]


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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
ls=[int(s) for s in input().split()]
ls2=sorted(ls)
m=ls2[n//2-1]
M=ls2[n//2]
for i in range(n):
  if ls[i]<=m:
    print(M)
  else:
    print(m)

Submission status: Accepted

Solution code:
import collections
n = int(input())
x = list(map(int, input().split()))
tmp = sorted(x)
xl = tmp[n // 2 - 1]
xr = tmp[n // 2]
if xl == xr:
    for i in range(n):
        print(xl)
    exit()
for i in x:
    if i > xl:
        print(xl)
    elif i < xr:
        print(xr)

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int,input().split()))
X_s=sorted(X)
ans1=X_s[N//2]
ans2=X_s[N//2-1]
for i in X:
    print(ans1*(i<=ans2) or ans2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from functools import reduce
import copy
import math
from pprint import pprint


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    nums = string_to_int(inputs[0])
    sorted_nums = sorted(nums)
    N = len(nums)
    medians = []
    median_candidate = [sorted_nums[N//2 - 1], sorted_nums[N//2]]
    for a in nums:
        if a <= median_candidate[0]:
            medians.append(median_candidate[1])
        else:
            medians.append(median_candidate[0])
    return medians


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    for r in ret:
        print(r)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
for i in range(N):
  A[i] = [A[i],i]
A.sort()
B = A
for i in range(N):
  A[i] = [A[i],i]
A = sorted(A,key = lambda x : x[0][1])
c = N//2-1
for i in range(N):
  if A[i][1]<=c:
    print(B[N//2][0][0])
  else:
    print(B[c][0][0])

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
ans = dict()
x_copy = sorted(x[:])
right = x_copy[(n//2)-1]
left = x_copy[-(n//2)]

for i in range(n):
    if i < n//2:
        ans[x_copy[i]] = left
    else:
        ans[x_copy[i]] = right

for i in x:
    print(ans[i])

Submission status: Accepted

Solution code:
n,*x=map(int, open(0).read().split());xc=sorted(x);
for i in x:print(xc[n//2-(i>(xc[n//2-1]+xc[n//2])/2)])

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
import copy
l1 = copy.copy(x)
l1.sort()
median1 = l1[int(n / 2) - 1]
median2 = l1[int(n / 2)]
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 = list(map(int, input().split()))
Xs = sorted(X)
for x in X:
    if x >= Xs[N // 2]:
        print(Xs[N // 2 - 1])
    else:
        print(Xs[N // 2])

Submission status: Accepted

Solution code:
n = int(input())
xs = list(map(int,input().split()))
xs_copy = xs.copy()
xs.sort()
a = xs[n//2-1]
b = xs[n//2]
for x in xs_copy:
  if x  <= a:
    print(b)
  elif x >= b:
    print(a)

Submission status: Accepted

Solution code:
N=int(input())
X=[int(i) for i in input().split()]
Y=sorted(X)
MidL=Y[N//2-1]#ちっちゃいほう(変化なしの場合)
MidR=Y[N//2]#でかいほう(下が減った場合)
for x in X:
	if x>=MidR:print(MidL)
	else:print(MidR)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, deque
from heapq import *
sys.setrecursionlimit(200000)
input = sys.stdin.readline

# N, M, = map(int, input().split())
N = int(input())
L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip

lc = L.copy()
L.sort()

t = int(N // 2) * -1
center = L[t]
c2 = L[t - 1]
for i in range(N):
    c = lc[i]

    if c < center:
        print(center)
    else:
        print(c2)

Submission status: Accepted

Solution code:
from bisect import bisect_left
N = int(input())
x = [int(i) for i in input().split()]
sorted_x = sorted(x)

mid = N // 2
for i in range(N) :
    if bisect_left(sorted_x, x[i]) < mid :
        print(sorted_x[N//2])
    else :
        print(sorted_x[N//2-1])

Submission status: Accepted

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

for i in range(N):
    X[i] = [X[i], i]
    
X.sort(reverse=True)
B = [0 for i in range(N)]
for i in range(N):
    if (i+1) <= N*0.5:
        B[X[i][1]] = X[N//2][0]
    else:
        B[X[i][1]] = X[N//2-1][0]
        
for i in range(N):
    print(B[i])

Submission status: Accepted

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

x_1 = x_sorted[n // 2 - 1]
x_2 = x_sorted[n // 2]

for x_ in x:
    if x_ <= x_1:
        print(x_2)
    else:
        print(x_1)

Submission status: Accepted

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

x = sorted(X)
med1, med2 = x[N//2-1], x[N//2]

print("\n".join(str(med2) if X[i] < med2 else str(med1) for i in range(N)))

Submission status: Accepted

Solution code:
import statistics

N = int(input())
x = list(map(int, input().split()))
sx = sorted(x)
tmp = statistics.median(sx)

for i in range(N):
    if x[i] <= tmp:
        print(sx[((N - 1) // 2) + 1])
    else:
        print(sx[(N - 1) // 2])

Submission status: Accepted

Solution code:
from heapq import *

N=int(input())
X=list(map(int,input().split()))
h=[]
for i in X:
    heappush(h,i)
for i in range(N//2-1):
    heappop(h)
a = heappop(h)
b = heappop(h)
for i in X:
    print(a if i >= b else b)

Submission status: Accepted

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

Submission status: Accepted

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

Y = sorted(X)

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