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

c = sorted(b, reverse=True)

m = int(a / 2) - 1
anslist = [0] * a
for i, data in enumerate(b):
    if c[m] > data:
        anslist[i] = c[m]
    elif c[m] <= data:
        anslist[i] = c[m + 1]
        
for j in range(a):
    print(anslist[j])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy

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

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

x1 = x[N // 2 - 1]
x2 = x[N // 2]

for xx in X:
    if xx <= x1:
        print(x2)
    else:
        print(x1)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
'''
Created on 2020/08/29

@author: harurun
'''
def main():
  import copy
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N=int(pin())
  X=list(map(int,pin().split()))
  t=(N+1)//2
  Y=sorted(X)
  ans1=Y[t-1]
  ans2=Y[t]
  median=ans1+ans2
  for i in range(N):
    s=X[i]
    if s==ans1:
      print(ans2)
    elif s==ans2:
      print(ans1)
    elif  2*s<median:
      print(ans2)
    elif 2*s>median:
      print(ans1)
  return 

main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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

# この二つ以外にありえない
small, large = X_sorted[(N-1)//2], X_sorted[(N+1)//2]

for x in X:
    if x <= small:
        print(large)
    else:
        print(small)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
x_sort = sorted(x)
half_l = x_sort[(n-1)//2]
half_r = x_sort[(n)//2]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

med_low = s[n//2 - 1]
med_high = s[n//2]

for x in X:
    if x <= med_low: print(med_high)
    else: print(med_low)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    x = [int(xn) for xn in input().split()]
    x_sorted = sorted(x)
    idx_median = n // 2
    median_low = x_sorted[idx_median - 1]
    median_high = x_sorted[idx_median]
    for xn in x:
        print(median_high if xn <= median_low else median_low)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
ans=sorted(x)
ans2=ans[n//2-1]
ans1=ans[n//2]

for i in range(n):
  if x[i]>=ans[n//2]:
    print(ans2)
  else:
    print(ans1)

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,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math

#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
n = I()
X = readInts()
nya = sorted(X)
m1 = nya[n//2-1]
m2 = nya[n//2]
for x in X:
    if x <= m1:
        print(m2)
    else:
        print(m1)

Submission status: Accepted

Solution code:
N, *X = map(int, open(0).read().split())
sorted_X = sorted(X)
median_l = sorted_X[N // 2 - 1]
median_r = sorted_X[N // 2]

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

Submission status: Accepted

Solution code:
import copy
N = int(input())
X = list(map(int, input().split()))
tmp_X = copy.deepcopy(X)
tmp_X.sort()
m1 = tmp_X[N // 2]
m2 = tmp_X[N // 2 - 1]
for x in X:
    if x < m1:
        print(m1)
    else:
        print(m2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from copy import copy
n, *x = map(int, open(0).read().split())
a = []
for i, v in enumerate(x):
    a.append((v, i))
a.sort()

# a[(i - 1)/ /2] , a[i // 2]
ans = [0] * n
for i in range(n):
    if i <= (n - 1) // 2:
        ans[a[i][1]] = a[n // 2][0]
    else:
        ans[a[i][1]] = a[(n - 1) // 2][0]
for y in ans:
    print(y)

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

import copy
Y = copy.copy(X)

L = []
U = []
X.sort()
for i in range(n):
    if i < n//2:
        L.append(X[i])
    else:
        U.append(X[i])
#print(L)
#print(U)

L_ = set(L)
U_ = set(U)

ans = [0]*n
for i, y in enumerate(Y):
    if y in L_:
        ans[i] = U[0]
    else:
        ans[i] = L[-1]
print(*ans, sep='\n')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
xl = list(map(int, input().split()))
xs = xl[:]
xs.sort()
med1 = xs[n//2-1]
med2 = xs[n//2]

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inl = lambda: [int(x) for x in sys.stdin.readline().split()]
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


def solve():
    n = ini()
    x = inl()
    y = sorted(x)

    p = y[n // 2 - 1]
    q = y[n // 2]

    for i in range(n):
        if x[i] < q:
            print(q)
        else:
            print(p)


solve()

Submission status: Accepted

Solution code:
from decimal import Decimal

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

y = x.copy()

y.sort()

m1 = y[n//2]
m2 = y[n//2 - 1]
m = Decimal(m1 + m2) / Decimal(2) 
#print(m1, m2)

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import copy

def main():
	N = int(input())
	X = [int(x) for x in input().split(" ")]
	sortedX = copy.deepcopy(X)
	sortedX.sort()
	cand = [sortedX[int(N / 2) - 1], sortedX[int(N / 2)]]

	for xi in X:
		if xi <= cand[0]:
			print(cand[1])
		else:
			print(cand[0])

main()

Submission status: Accepted

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

sort = sorted(lst)
medi1 = sort[n//2-1]
medi2 = sort[n//2]
    
for i in range(n):
  if lst[i] <= medi1:
    print(medi2)
  else:
    print(medi1)

Submission status: Accepted

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

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

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

n = I()
x = RI()

a = sorted(x)
M = a[n//2]
m = a[n//2-1]

for i in range(n):
    if x[i]<=m:
        print(M)
    else:
        print(m)
exit()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import numpy as np


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

median = np.median(x)
x_sorted = sorted(x)

index = len(x)//2-1

for i in x:
    if i == median:
        print(i)
    elif i < median:
        print(x_sorted[index+1])
    else:
        print(x_sorted[index])

Submission status: Accepted

Solution code:
import sys
import math


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())


n = inint()
X = inintl()

X_sorted = sorted(X)

a, b = X_sorted[n//2-1],X_sorted[n//2]

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

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))
Y = sorted(X)
med = (Y[N//2] + Y[N//2-1])/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:
n = int(input())
x = list(map(int,input().split()))
y = sorted(x)
index = n//2

for i in range(n):
  print(y[-index] if x[i]<y[index] else y[-index-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import statistics

n = int(input())
x = list(map(int, input().split()))
xmd = statistics.median(x)
xs = sorted(x)
for i in x:
    if i < xmd:
        print(xs[n // 2])
    else:
        print(xs[n // 2 - 1])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy
N = int(input())
X = [int(x) for x in input().split()]
S = sorted(X)
m0 = numpy.median(S[:-1])
m1 = numpy.median(S[1:])

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

Submission status: Accepted

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

x_sort = sorted(x)
lenth = len(x)
low = x_sort[int(lenth/2)-1]
high = x_sort[int(lenth/2)]

for y in x:
    if y <= low:
        print(high)
    else:
        print(low)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
*X,=map(int,input().split())
s=sorted(X)

t1=s[N//2-1]
t2=s[N//2]

for x in X:
    if x<=t1:
        print(t2)
    else:
        print(t1)

Submission status: Accepted

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

x = list(enumerate(X))

x.sort(key=lambda x: x[1])
A = list(map(lambda x: x[1], x[n//2-1:n//2+1]))

for v in X:
    if v <= A[0]:
        print(A[1])
    else:
        print(A[0])

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-1])
  else:
    print(y[n//2])

Submission status: Accepted

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

res1 = x[n//2]
res2 = x[n//2 -1]

for i in range(n):
  if X[i] >= res1:
    print(res2)
  elif X[i] <= res2:
    print(res1)

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
X_sorted = sorted(X)
pre_med_index = (N // 2) - 1
pos_med_index = N // 2
import bisect

for i in range(N):
    if X[i] <= X_sorted[pre_med_index]:
        print(X_sorted[pos_med_index])
    else:
        print(X_sorted[pre_med_index])

Submission status: Accepted

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

Submission status: Accepted

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

X.sort()

right = int(N // 2)
left = right - 1

med = (X[left] + X[right]) / 2

for x in org:
    if x >= med:
        print(X[left])
    else:
        print(X[right])

Submission status: Accepted

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

a = Y[(N-1)//2]
b = Y[(N+1)//2]

for i in X:
    if i > a:
        print(a)
    else:
        print(b)

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:
    print((a, b)[i <= a])

Submission status: Accepted

Solution code:
#!/usr/bin/env python
import sys 
import copy
input = sys.stdin.readline

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

l = xx[(n-1)//2]
r = xx[n//2]
mid = (l+r)/2

for i in range(n):
    if x[i] >= mid:
        print(l)
    else:
        print(r)

Submission status: Accepted

Solution code:
import math
import statistics

n = int(input())
xL = list(map(int, input().split(" ")))

xL2 = []
for i in range(n):
    xL2.append([i, xL[i]])
xL2 = sorted(xL2, key=lambda x: x[1])

if n % 2 == 0:
    center = n // 2
    centers = [xL2[center - 1], xL2[center]]
    for i in range(n):
        if i == centers[0][0] or i == centers[1][0]:
            print(statistics.median(xL[:i] + xL[i + 1:]))
        else:
            if centers[0][1] < xL[i]:
                print(centers[0][1])
            else:
                print(centers[1][1])
else:
    center = n // 2
    centers = [xL2[center - 1], xL2[center], xL2[center + 1]]
    for i in range(n):
        if i == centers[0][0] or i == centers[1][0] or i == centers[2][0]:
            print(statistics.median(xL[:i] + xL[i + 1:]))
        else:
            if centers[0][1] < xL[i]:
                print((centers[0][1] + centers[1][1]) / 2)
            else:
                print((centers[1][1] + centers[2][1]) / 2)

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
X = list(map(int, input().split()))
Y = sorted(X)
x = np.median(X)
index = N // 2
m1 = Y[index]
m2 = Y[index - 1]

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

Submission status: Accepted

Solution code:
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    X = nl()
    X_s = sorted(X)
    mid = X_s[n // 2]
    del_mid = (X_s[:n // 2] + X_s[n // 2 + 1:])[(n - 1) // 2]
    for x in X:
        if x < mid:
            print(mid)
        elif x > mid:
            print(X_s[n // 2 - 1])
        else:
            print(del_mid)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
for i in range(n):
  x[i] = [x[i], i]
x.sort(key=lambda x:x[0])
for i in range(n):
  if i < n//2:
    x[i] += [x[n//2][0]]
  else:
    x[i] += [x[n//2-1][0]]
# x[i] = [value, init_index, b_i]
x.sort(key=lambda x:x[1])
for i in range(n):
  print(x[i][2])

Submission status: Accepted

Solution code:
n,*a=map(int,open(0).read().split())

b=sorted(a)
med=b[n//2]
medsmall=b[n//2-1]

for i in range(n):
    if med<=a[i]:
        print(medsmall)
    else:
        print(med)

Submission status: Accepted

Solution code:
import copy

n=int(input())

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

x2 = copy.copy(x)

x2.sort()

ans = [x2[n//2-1],x2[n//2]]

for xx in x:
    if xx <= ans[0]:
        print(ans[1])
    else:
        print(ans[0])

Submission status: Accepted

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n = k()
x = l()
p=sorted(x)
mid = len(p)//2
for i in x:
    a = bisect.bisect(p,i)
    if a <= mid:
        print(p[mid])
    else:
        print(p[mid-1])

Submission status: Accepted

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

Submission status: Accepted

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

nums = sorted(x)
m1 = n//2-1
m2 = n//2
for i in range(n):
  if x[i] <= nums[m1]: print(nums[m2])
  elif nums[m2] <= x[i]: print(nums[m1])

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *X = map(int, read().split())

    X = [(x, i) for i, x in enumerate(X)]

    X.sort()

    ans = [0] * N
    for i, (x, j) in enumerate(X):
        if i < N // 2:
            ans[j] = X[N // 2][0]
        else:
            ans[j] = X[N // 2 - 1][0]

    print(*ans, sep='\n')
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

y = sorted([(a, i) for i, a in enumerate(x)])
x1 = y[n // 2 - 1][0]
x2 = y[n // 2][0]

for i in range(n):
    j = y[i][1]
    x[j] = (x[j], i)

for i in range(n):
    if x[i][1] < n // 2:
        print(x2)
    else:
        print(x1)

Submission status: Accepted

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

Y = sorted(X[:])
b_median = Y[N // 2 - 1]
a_median = Y[N // 2]

for i in range(N):
  if X[i] >= a_median:
    print(b_median)
  elif X[i] <= b_median:
    print(a_median)

Submission status: Accepted

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

first_harf = Y[:int(N/2)]
second_harf = Y[int(N/2):]

for i in range(N):
    if X[i] <= first_harf[-1]:
        print(second_harf[0])
    else:
        print(first_harf[-1])

Submission status: Accepted

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

l = sorted(x)

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

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

Submission status: Accepted

Solution code:
import sys

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

sort = sorted(X)
first = sort[N//2 - 1]
second = sort[N//2]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

x=sorted(y)
c=n//2

ans1=x[n//2-1]
ans2=x[n//2]

for i in range(n):
  if y[i]>=ans2:
    print(ans1)
  else:
    print(ans2)

Submission status: Accepted

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

Submission status: Accepted

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

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])
  else:
    print(y[n//2-1])

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int,input().split()))
X2=sorted(enumerate(X),key=lambda x:x[1])
X3=sorted(enumerate(X2),key=lambda x:x[1][0])
ans=[0]*N
for i in range(N):
  if X3[i][0] < N//2:print(X2[N//2][1])
  else:print(X2[N//2-1][1])

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
import numpy as np
from numba import njit


def read():
    N = int(input().strip())
    X = np.fromstring(input().strip(), dtype=np.int32, sep=" ")
    return N, X


@njit
def solve(N, X):
    A = np.argsort(X)
    l, r = X[A[N//2-1]], X[A[N//2]]
    mid = (l + r) / 2
    for i in range(N):
        if X[i] <= mid:
            print(r)
        else:
            print(l)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
import numpy as np


def read():
    N = int(input().strip())
    X = np.fromstring(input().strip(), dtype=np.int32, sep=" ")
    return N, X


def solve(N, X):
    A = np.argsort(X)
    l, r = X[A[N//2-1]], X[A[N//2]]
    mid = (l + r) / 2
    for x in X:
        if x <= mid:
            print(r)
        else:
            print(l)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Submission status: Accepted

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# 約数生成
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

n = ir()
xx = lr()
x = sorted(xx)
min_m = x[n//2-1]
max_m = x[n//2]
for num in xx:
    if num <= x[n//2-1]:
        print(max_m)
    else:
        print(min_m)