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:
#-*-coding:utf-8-*-

def main():
    numbers=[]
    n = int(input())
    numbers=list(map(int,input().split()))
    sort_numbers=sorted(numbers)
# left/right算出はsorted arrayで
    left=sort_numbers[n//2-1]
    right=sort_numbers[n//2]
# loopは元の配列で
    for i in numbers:
        if i > left:
            print(left)
        else:
            print(right)

if __name__=="__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
#a,b=map(int,input().split())
xl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
l2d=[]
for i in range(n):
    l2d.append([i,xl[i]])

xlsort=sorted(xl)
v1=xlsort[n//2-1]
v2=xlsort[n//2]

l2d.sort(key=lambda x: x[1])
dic={}
for i in range(n):
    dic[l2d[i][0]]=i
thre=n//2
for i in range(n):
    if dic[i]<thre:
        print(v2)
    else:
        print(v1)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    N = int(input().strip())
    X_list = [int(i) for i in input().strip().split()]
    sorted_x = sorted(X_list)

    left = sorted_x[(N // 2)-1]
    right = sorted_x[N // 2]
    for x in X_list:
        if x <= left:
            print(right)
        else:
            print(left)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from statistics import median
from operator import itemgetter
N = int(input())
x = list(map(int, input().split()))
x_ = sorted(x)
m0 = median(x_[1:])
m1 = median(x_[:-1])
for i in x:
    if m1 >= i:
        print(m0)
    else:
        print(m1)

Submission status: Accepted

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

Y = X[::]
Y.sort()

m = n // 2
median = (Y[m] + Y[m - 1]) / 2

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

Submission status: Accepted

Solution code:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

if n%2==0:
    heikin=(tmp[n//2]+tmp[n//2-1])/2
    for i in range(n):
        if heikin<x[i]:
            print(tmp[n//2-1])
        else:
            print(tmp[n//2])

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
order = {}
for idx, x in enumerate(X):
    order[idx] = x

X.sort()
m = N // 2
l = X[m - 1]
r = X[m]

for idx in range(N):
    x = order[idx]
    if x <= l:
        print(r)
    else:
        print(l)

Submission status: Accepted

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

for x in X:
  if x<=mae:
    print(ato)
  elif x>=ato:
    print(mae)

Submission status: Accepted

Solution code:
import copy

n = int(input())
l = list(map(int,input().split()))
p1 = n//2
p2 = n//2-1
ans = copy.copy(l)
ans.sort()

for i in l:
    if i >= ans[p1]:
        print(ans[p2])
    else:
        print(ans[p1])

Submission status: Accepted

Solution code:
N = int(input())
x_list = list(map(int, input().split()))
sorted_x = sorted(x_list)

medi = N//2
l = sorted_x[medi-1]
r = sorted_x[medi]
for x in x_list:
    if x < r:
        print(r)
    else:
        print(l)

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int,input().split()))
B = A.copy()
A.sort()

ans_ato = A[n//2]
ans_mae = A[n//2-1]

for b in B:
    if b < ans_ato:
        print(ans_ato)
    else:
        print(ans_mae)

Submission status: Accepted

Solution code:
import bisect

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

Ss = sorted(Xs)

for i in range(N):
  j = bisect.bisect_left(Ss, Xs[i])
  if j < N//2:
    print(Ss[N//2])
  else:
    print(Ss[N//2-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n=ni()
x=nl()

sx = sorted(x)[::-1]

c = n//2

for i in range(n):
  if x[i] > sx[c]:
    print(sx[c])
  else:
    print(sx[c-1])

Submission status: Accepted

Solution code:
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = lr()
sorted_A = sorted(A)
mid = N // 2 - 1
left = sorted_A[mid]
right = sorted_A[mid+1]
answer = [left if a > left else right for a in A]
print('\n'.join(map(str, answer)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

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

Y = [(i, x) for i, x in enu(X)]
sY = sorted(Y, key=lambda x: x[1])
ssY = [(i,) + y for i, y in enu(sY)]
sssY = sorted(ssY, key=lambda x: x[1])
# print(Y)
# print(sY)
# print(ssY)
# print(sssY)

for i in range(N):
    tup = sssY[i]
    sor_ind, ini_ind, val = tup
    # print(tup)
    if sor_ind < N//2:
        print(sY[N//2][1])
    else:
        print(sY[N//2-1][1])

Submission status: Accepted

Solution code:
n = int(input())
x_l = list(map(int,input().split()))
s_x_l = sorted(x_l)

med_idx = n//2
med_l = s_x_l[med_idx-1]
med_r = s_x_l[med_idx]

for i in range(n):
    if  x_l[i] <= med_l:
        print(med_r)
    else:
        print(med_l)

Submission status: Accepted

Solution code:
n = int(input())

argList = list(map(int, input().split()))
argList2 = argList.copy()
argList2.sort()

med_before = argList2[int(len(argList2)/2)-2]
med = argList2[int(len(argList2)/2)-1]
med_after = argList2[int(len(argList2)/2)]

for a in argList:
    if( a <= med):
        print(med_after)
    else:
        print(med)

Submission status: Accepted

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

ls = sorted(l)
k = (ls[n//2-1] + ls[n//2])/2

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

Submission status: Accepted

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

def main():
    N = int(input())
    X = list(mi())
    Y = sorted(X)
    for i in range(N):
        if X[i] <= Y[N//2-1]:
            print(Y[N//2])
        else:
            print(Y[N//2-1])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
X = list(map(int, input().split()))
c = Counter(X)
Xsort = sorted(X)

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

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
nx = [X[i] for i in range(N)]
nx.sort()
ans2 = (nx[N//2])
ans3 = (nx[N//2-1])

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(n):
    if x[i] < l[1]:
        print(l[1])
    else:
        print(l[0])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
med1, med2 = sorted(x)[n // 2 - 1 : n // 2 + 1]
ans = [med2 if i <= med1 else med1 for i in x]
print('\n'.join(map(str, ans)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    X = list(map(int, input().split()))
    for i in range(n):
        x = X[i]
        X[i] = [i, x]
    X_s = sorted(X, key=lambda x: x[1])

    res = [0] * n
    for i in range(n):
        idx, _ = X_s[i]
        if i < n // 2:
            res[idx] = X_s[n // 2][1]
        else:
            res[idx] = X_s[n // 2 - 1][1]

    print(*res, sep="\n")


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

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

sortedX = sorted(X)

l = sortedX[n // 2 - 1]
r = sortedX[n // 2]

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

Submission status: Accepted

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

B = sorted(A)
X = B[N//2-1]
Y = B[N//2]

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

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
from collections import defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
X = readInts()
nya = sorted(X)
m1 = nya[n//2-1];m2 = nya[n//2]
# このどちらか
# 適当に取り出して、そいつが中央値1以下ならm2,
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()))
y=sorted(x[:])
l=y[n//2-1]
r=y[n//2]
for xx in x:
  print(l if xx>=r else r)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import *

N = int(input())
X = list(map(int, input().split()))
l = [(i, X[i]) for i in range(N)]
l.sort(key=lambda t: t[1])
ans = [-1]*N

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

for ans_i in ans:
    print(ans_i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    X = [int(x) for x in input().split()]
    Xsub = sorted(X)
    midl, midr = Xsub[(N - 1) // 2], Xsub[N // 2]
    ans = [0] * N
    for i, x in enumerate(X):
        if x <= midl: ans[i] = midr
        else: ans[i] = midl
    print(*ans, sep="\n")

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
from bisect import *

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 range(n):
  inx=bisect_right(x_s,x[i])
  if inx<=n//2:
    print(ans1)
  else:
    print(ans2)

Submission status: Accepted

Solution code:
n = int(input())
x = list(enumerate(map(int, input().split())))
x.sort(key=lambda x:x[1])
ans = [""]*n
for i in range(n):
  if (n+1)//2 >= i+1: ans[x[i][0]] = x[(n+1)//2][1]
  else: ans[x[i][0]] = x[(n+1)//2-1][1]

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

Submission status: Accepted

Solution code:
n = int(input())
X = list(map(int,input().split()))
h = int(n/2)
Xs = sorted(X)
m1 = Xs[h-1]
m2 = Xs[h]

for i in range(n):
  if X[i] <= m1:
    print(m2)
  else:
    print(m1)

Submission status: Accepted

Solution code:
N = int(input())
x = list(input().split())
num = [int(x[i]) for i in range(N)]
num_sorted = sorted(num)
min_center = num_sorted[N // 2 - 1]
max_center = num_sorted[N // 2]

for i in range(N):
    if num[i] <= min_center:
        print(max_center)
    else:
        print(min_center)

Submission status: Accepted

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

a = int(N/2)
b = a-1

aa = xs[a]
bb= xs[b]

A = aa
B = bb


for i in X:
  if i >= A:
    print(B)
  else:
    print(A)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read

n,*x = list(map(int, read().split()))
x_sort = sorted(x)

mean_left = x_sort[n//2-1]
mean_right = x_sort[n//2]


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
x = [int(i) for i in input().split()]
sx = sorted(x)
s1, s2 = sx[n//2-1], sx[n//2]
m = (s1 + s2) / 2
for i in x:
    if m > i: print(s2)
    else: print(s1)

Submission status: Accepted

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect

if __name__ == "__main__":
    n = int(input())
    x = list(map(int,input().split()))
    y = x[:]
    y.sort()
    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)
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:
def main():
    N = int(input())
    X = [int(a) for a in input().split()]
    Xs = sorted(X)

    for i in range(len(X)):
        if  Xs[len(Xs)//2] > X[i]:
            print(Xs[len(Xs)//2])
        else:
            print(Xs[len(Xs)//2 - 1])

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

mid = N // 2 - 1
l = sX[mid]
r = sX[mid+1]
for i in range(N):
    if X[i] <= l:
        print(r)
    else:
        print(l)

Submission status: Accepted

Solution code:
n = int(input())
xs = [(i, int(v)) for i, v in enumerate(input().split())]

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

a = tmp[n // 2 - 1][1]
b = tmp[n // 2][1]

ans = [0]*n

for i,v in tmp[:n//2]:
    ans[i] = b
    
for i, v in tmp[n//2:]:
    ans[i] = a

for i in ans:
    print(i)

Submission status: Accepted

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

Submission status: Accepted

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

for xi in x:
    if xi < ml:
        print(ml)
    else:
        print(ms)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy
n = int(input())
X = [0]+[int(i) for i in input().split()]
Copy = copy.deepcopy(X)

X.sort()
index_right = int(n/2+1)
index_left = index_right-1
key_r = X[index_right]
key_l = X[index_left]

for i in range(1,n+1):
    if Copy[i] <= key_l:
        print(key_r)
    else:
        print(key_l)

Submission status: Accepted

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

arr=np.sort(np.array(l))
med=np.median(arr)

med_max=int(np.median(np.delete(arr,0)))
med_min=int(np.median(np.delete(arr,n-1)))


p=(n+1)//2
for i in range(n):
    if l[i]<=arr[p-1]:
        print(med_max)
    else:
        print(med_min)

Submission status: Accepted

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

arr=np.sort(np.array(l))
med=np.median(arr)

med_max=int(np.median(np.delete(arr,0)))
med_min=int(np.median(np.delete(arr,n-1)))

if n%2==1:
    p=(n-1)//2
    med_midmin=int(np.median(np.delete(arr,p+1)))
    med_mid=int(np.median(np.delete(arr,p)))
    med_midmax=int(np.median(np.delete(arr,p-1)))

    for i in range(n):
        if l[i]<arr[p-1]:
            print(med_max)
        elif l[i]==arr[p-1]:
            print(med_midmax)
        elif l[i]==arr[p]:
            print(med_mid)
        elif l[i]==arr[p+1]:
            print(med_midmin)
        else:
            print(med_min)

if n%2==0:
    p=(n+1)//2
    med_midmin=int(np.median(np.delete(arr,p)))
    med_midmax=int(np.median(np.delete(arr,p-1)))
    for i in range(n):
        if l[i]<arr[p-1]:
            print(med_max)
        elif l[i]==arr[p-1]:
            print(med_midmax)
        elif l[i]==arr[p]:
            print(med_midmin)
        else:
            print(med_min)

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())
A = list(map(int,input().split()))

sA = sorted(A)
l = sA[N//2 - 1]
r = sA[N//2]

median = defaultdict(int)
m = N // 2 - 1
for i,a in enumerate(sA):
  if i <= m and not median[a]:
    median[a] = sA[m+1]
  elif m < i and not median[a]:
    median[a] = sA[m]

ans = []
for a in A:
  ans.append(median[a])
  
print("\n".join(map(str,ans)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
X = tuple(map(int, input().split()))
Xs = sorted(X)

ml = Xs[n//2-1]
mr = Xs[n//2]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy
N = int(input())
X = [int(i) for i in input().split()]
Y = copy.deepcopy(X)
Y = sorted(Y, key= lambda x: -x)

c = int(N/2)

for i in range(N):
    a = X[i]
    if a >= Y[c-1]:
        print(Y[c])
    else:
        print(Y[c-1])

Submission status: Accepted

Solution code:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
# import math
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)


n=l()[0]
X=l()
A=sorted(X)
d={}
z=n//2
for i in range(n):
    if(A[i] in d):
        continue
    if(i<z):
        d[A[i]]=A[z]
    else:
        d[A[i]]=A[z-1]
for i in range(n):
    print(d[X[i]])

Submission status: Accepted

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

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

S = sorted(X)
mM = S[N // 2 - 1]
lM = S[N // 2]

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

Submission status: Accepted

Solution code:
N = int(input())
sorted_X = sorted([(v, i) for i, v in enumerate(map(int, input().split()))])
med_former = sorted_X[N // 2][0]
med_latter = sorted_X[N // 2 - 1][0]
ans = [-1] * N
for j, (v, i) in enumerate(sorted_X):
    if j < N // 2:
        ans[i] = med_former
    else:
        ans[i] = med_latter
print("\n".join(map(str, ans)))

Submission status: Accepted

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N = I()
X = LI()
sort_X = sorted(X)
ans1,ans2 = sort_X[(N-1)//2],sort_X[N//2]
for x in X:
    if x>=ans2:
        print(ans1)
    else:
        print(ans2)

Submission status: Accepted

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

y = sorted(x)

from bisect import bisect_left
border=n//2-1

if n==2:
    print(x[1])
    print(x[0])
    exit(0)


for i in range(n):
    index = bisect_left(y,x[i])

    if index<=border:
        print(y[border+1])
    else:
        print(y[border])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    inlis = list(map(int, input().split()))
    inlis_sort = sorted(inlis)

    low = inlis_sort[int(n/2)-1]
    high = inlis_sort[int(n/2)]
    ave = (low + high) / 2

    for i in inlis:
        if i >= ave:
            print(low)
        else:
            print(high)

    
    

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

N = INT()
X = LIST()
Y = []

for i, x in enumerate(X):
	Y.append([i, x])
Y.sort(key = lambda x: x[1])
#print(Y)
M1 = Y[N//2][1]
M2 = Y[N//2-1][1]
#print(M1, M2)
for i in range(N):
	if i >= N//2:
		Y[i][1] = M2
	else:
		Y[i][1] = M1
#print(Y)
Y.sort(key = lambda x: x[0])
#print(Y)
print(*[x[1] for x in Y], sep="\n")

Submission status: Accepted

Solution code:
n = int(input())

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

y = sorted(x)

for i in x:
    if y[(n+1)//2-1] >= i:
        print(y[(n+1)//2])
    else:
        print(y[(n+1)//2-1])

Submission status: Accepted

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

Y=copy.copy(X)
Y.sort()
center = N//2
right = Y[center]
left = Y[center-1]
center_line = (right+left)/2

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

Submission status: Accepted

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

sl = sorted(l)
a, b = sl[n // 2 - 1], sl[n // 2]
for i in l:
    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)

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

Submission status: Accepted

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

import numpy as np
ary = np.array(x)
ranks = ary.argsort()
rank_dict = {index:rank for rank,index in enumerate(ranks, start=1)}

MID=n//2
upper = x[ranks[MID]]
lower = x[ranks[MID-1]]
for i in range(n):
    rank = rank_dict[i]
    if rank <= MID:
        print(upper)
    else:
        print(lower)

Submission status: Accepted

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

Submission status: Accepted

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

x_sort = sorted(x)
ans_1 = x_sort[int(n / 2)-1]
ans_2 = x_sort[int(n / 2)]

for xi in x:
    if xi <= ans_1:
        print(ans_2)
    else:
        print(ans_1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys


def input(): return sys.stdin.readline().strip()


def resolve():
    n = int(input())
    l = list(map(int, input().split()))
    lsort = sorted(l)
    left = lsort[n // 2 - 1]
    right = lsort[n // 2]
    for i in l:
        if i <= left:
            print(right)
        else:
            print(left)
resolve()

Submission status: Accepted

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

def resolve():
    n=int(input())
    l=list(map(int,input().split()))
    l2=sorted(l)
    x=l2[n//2-1]
    y=l2[n//2]
    if x==y:
        for i in range(n):
            print(x)
    else:
        setx=set(l2[:n//2])
        sety=set(l2[n//2:])
        for i in l:
            if i in setx:
                print(y)
            else:
                print(x)
resolve()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A_copy = A.copy()
n = N//2
A.sort()
avg = (A[n]+A[n-1])/2
for i in A_copy:
    if i < avg:
        print(A[n])
    else:
        print(A[n-1])

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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