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:
#!/usr/bin/env python3

import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n = ii()
    L = lmi()
    sorted_l = sorted(L)
    left_pivot = sorted_l[n//2 - 1]
    right_pivot = sorted_l[n//2]

    if left_pivot == right_pivot:
        for _ in range(n):
            print(left_pivot)
    else:
        for elm in L:
            print(right_pivot) if elm <= left_pivot else print(left_pivot)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np
import copy

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

max_value = max(X)
min_value = min(X)

tmp_list = copy.deepcopy(X)
tmp_list.sort()
all_med = tmp_list[int((len(tmp_list)+1) / 2) - 1]

tmp_list.remove(max_value)
min_med = tmp_list[int((len(tmp_list)+1) / 2) - 1]

tmp_list = copy.deepcopy(X)
tmp_list.remove(min_value)
tmp_list.sort()
max_med = tmp_list[int((len(tmp_list)+1) / 2) - 1]

for i in range(N):
    if X[i] <= all_med:
        print(int(max_med))
    else:
        print(int(min_med))

Submission status: Accepted

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

m = a[int(n/2)-1]
M = a[int(n/2)]
median = (m+M)/2

for i in s:
    if i > median:
        print(m)
    else:
        print(M)

Submission status: Accepted

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

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  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

#####MakeDivisors######
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)
  return divisors

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n = n//a
    count += 1
  if a**count == n:
    return count
  else:
    return count+1

#############
# Main Code #
#############

N = I()
X = IL()

Y = X[:]
Y.sort()

A,B = Y[N//2-1],Y[N//2],

for x in X:
  if x > A:
    P(A)
  else:
    P(B)

Submission status: Accepted

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

for i in range(n):
    if a[i]>(l+s)/2:
        print(s)
    else:
        print(l)

Submission status: Accepted

Solution code:
n = int(input())
x_list = [int(x) for x in input().split()]
temp_list = sorted(x_list)
temp = n // 2
l = temp_list[temp - 1]
r = temp_list[temp]
for x in x_list:
    print(r if x <= l else l)

Submission status: Accepted

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

x = sorted(X)
ans_1 = x[N // 2 - 1]
ans_2 = x[N // 2]

ans = []
for i in range(N):
    if X[i] <= ans_1:
        ans.append(ans_2)
    else:
        ans.append(ans_1)

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

Submission status: Accepted

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

for i in range(n):
    if xsort[n//2] > x[i]:
        print(xsort[n//2])
    else:
        print(xsort[n//2-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# AtCoder
N = int(input())
X = list(map(int, input().split()))
Y = sorted(X)
m1 = Y[N//2]
m2 = Y[N//2-1]

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

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int,input().split()))
B = sorted(A)
med = B[n//2-1:n//2+1]

for a in A:
  if a  <= med[0]:
    print(med[1])
  else:
    print(med[0])

Submission status: Accepted

Solution code:
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N = int(input())
X = list(map(int,input().split()))
 
l  = sorted(X)[N//2-1]
r = sorted(X)[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()))

sort_x = sorted(x)

for i in range(n):
    if x[i]<=sort_x[n//2-1]:
        print(sort_x[n//2])
    else:
        print(sort_x[n//2-1])

Submission status: Accepted

Solution code:
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,cos,radians,sqrt
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
lis=LI()
u=sorted(lis)
medl=u[n//2-1]
medu=u[n//2]
for i in range(n):
    if lis[i]>=medu:
        ans=medl
        print(ans)
    elif lis[i]<=medl:
        ans=medu
        print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    assert N % 2 == 0
    X = list(map(int, input().split(' ')))
    Y = X.copy()
    Y.sort()
    left, right = Y[N//2-1], Y[N//2]
    for x in X:
        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()))
x_sorted = sorted(x)

cs = x_sorted[n // 2 - 1]
cb = x_sorted[n // 2]

for i, v in enumerate(x):
    if v <= cs:
        print(cb)
    else:
        print(cs)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    x = list(map(int,input().split()))
    s = sorted(x)
    m1 = s[n//2-1]
    m2 = s[n//2]

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

sort_x = sorted(x)

b1 = sort_x[n//2]
b2 = sort_x[n//2-1]

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import collections
import numpy as np
import sys
import copy
N=int(input())
#W,H,X,Y=map(int,input().split())
A=list(map(int,input().split()))
B=sorted(A)
s=B[N//2-1]
b=B[N//2]
for i in range(N):
    if A[i]<=s:
        print(b)
    else:
        print(s)

Submission status: Accepted

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

xs=sorted(x)
xm1 = xs[n//2-1]
xp1 = xs[n//2]
for i in x:
    if i <= xm1:
        print(xp1)
    else:
        print(xm1)

Submission status: Accepted

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

lst = sorted(x)
small_med = lst[n // 2 - 1]
big_med = lst[n // 2]

for num in x:
    if num > small_med:
        print(small_med)
    else:
        print(big_med)

Submission status: Accepted

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
X = iil()
r = sorted(X)
smed = r[n//2-1]
lmed = r[n//2]

for i in X:
    if i <= smed:
        print(lmed)
    else:
        print(smed)

Submission status: Accepted

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

Y = sorted(X)
Y1 = Y[N//2]
Y2 = Y[N//2 - 1]

for x in X:
    if x < Y1:
        print(Y1)
    else:
        print(Y2)

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
X = np.array(list(map(int, input().split())))
s = np.sort(X)
m1 = s[N//2-1]
m2 = s[N//2]
for x in X:
    if x <= m1:
        print(m2)
    else:
        print(m1)

Submission status: Accepted

Solution code:
def resolve():
	n = int(input())
	seq = list(map(int, input().split()))
	s_seq = sorted(seq)
	med = s_seq[(n+1)//2]
	for i in range(n):
		if seq[i] >= med:
			print(s_seq[(n+1)//2-1])
		else:
			print(med)
resolve()

Submission status: Accepted

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

Submission status: Accepted

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

x_s = sorted(x)

lst = [x_s[(n-1)//2], x_s[n//2]]

for i in x:
    print(lst[0] if i >= lst[1] else lst[1])

Submission status: Accepted

Solution code:
N = int(input())
numbers_r = tuple(map(int, input().split(' ')))
numbers_s = sorted(numbers_r)

med_high = numbers_s[N // 2]
med_low = numbers_s[N // 2 - 1]

for number in numbers_r:
    if number <= med_low:
        print(med_high)
    else:
        print(med_low)

Submission status: Accepted

Solution code:
N = int(input())
numbers_r = tuple(map(int, input().split(' ')))
numbers_s = sorted(numbers_r)

med_high = numbers_s[N // 2]
med_low = numbers_s[N // 2 - 1]

for number in numbers_r:
    if number == med_low:
        print(med_high)
    elif number == med_high:
        print(med_low)
    elif number < med_low:
        print(med_high)
    elif number > med_high:
        print(med_low)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc094/tasks/arc095_a
from copy import deepcopy
n = int(input())
nums = [int(i) for i in input().split()]
c = deepcopy(nums)
c.sort()
left = c[n // 2 - 1]
right = c[n // 2]

for num in nums:
    if num <= left:
        print(right)
    else:
        print(left)

Submission status: Accepted

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

for i in range(n):
    nums.append([x[i], i])

nums.sort()

for i in range(n):
    nums[i].append(i)
right = nums[n // 2][0]
left = nums[n // 2 - 1][0]
nums.sort(key=lambda x: x[1])

for i in range(n):
    if nums[i][2] < n // 2:
        print(right)
    else:
        print(left)

Submission status: Accepted

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

x_ = sorted(X)
m0 = x_[N // 2 - 1]
m1 = x_[N // 2]

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

Submission status: Accepted

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

XX = sorted(X)
before = XX[N//2 -1]
after = XX[N//2]

for i in X:
    if i <= before:
        print(after)
    else:
        print(before)

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
X = list(map(int, input().split()))
Xs = sorted(X)
c1 = np.median(Xs[1:]).astype(int)
c2 = np.median(Xs[:-1]).astype(int)

for i in range(N):
    if X[i] < c1:
        print(c1)
    else:
        print(c2)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
import copy
import numpy as np
n = int(input())
x = np.array(list(map(int, sys.stdin.readline().split())))
y = sorted(x)
for i in x:
    if y[n//2] > i:
        print(y[n//2])
    else:
        print(y[n//2-1])

Submission status: Accepted

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

Submission status: Accepted

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

sX = sorted(X)
small_median = sX[N//2-1]
large_median = sX[N//2]

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

Submission status: Accepted

Solution code:
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()))
memo = sorted(x)
dx = memo[n // 2]
for xx in x:
    print(memo[n // 2 - 1] if dx <= xx else dx)

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
x_ = sorted(x)
c = x_[n//2 - 1]
c_ = x_[n//2]

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

Submission status: Accepted

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

Submission status: Accepted

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

half = N // 2

Y_n21 = half
Y_n20 = half - 1

for x in X:
    if x < Y[Y_n21]:
        print(Y[Y_n21])
    else:
        print(Y[Y_n20])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon May 11 16:14:32 2020

@author: shinba
"""


n = int(input())

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

A = sorted(X)

a = A[n//2-1]
b = A[n//2]
med = (a+b)/2

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

Submission status: Accepted

Solution code:
import copy
N = int(input())
numbers = [int(i) for i in input().split()]
copy_num = sorted(copy.deepcopy(numbers))

mid = N // 2
mid_num = copy_num[mid]

for i in range(N):
    if numbers[i] >= mid_num:
        print(copy_num[mid-1])
    else :
        print(mid_num)

Submission status: Accepted

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

xs = sorted(X)
median1 = xs[N//2-1]
median2 = xs[N//2]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


def solve_iter(N: int, X: "List[int]"):
    Y = sorted(X)
    m = sum(Y[N//2-1:N//2+1]) / 2
    for x in X:
        if x < m:
            yield Y[N//2]
        else:
            yield Y[N//2-1]


def solve(N: int, X: "List[int]"):
    if N == 2:
        return X[::-1]
    return list(solve_iter(N, X))

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(*solve(N, X), sep='\n')

def test():
    import doctest
    doctest.testmod()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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

    A, B = sorted(X)[N // 2 - 1: N // 2 + 1]
    ans = [B if x <= A else A for x in X]
    print(*ans, sep="\n")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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

    A, B = sorted(X)[N // 2 - 1: N // 2 + 1]
    for x in X:
        if x <= A:
            print(B)
        else:
            print(A)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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

    Y = sorted(X)
    A, B = Y[N // 2 - 1: N // 2 + 1]
    for x in X:
        if x <= A:
            print(B)
        else:
            print(A)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n, *x = map(int, open(0).read().split())
    y = sorted(x)
    a, b = y[n // 2 - 1], y[n // 2]
    ans = ""
    f = lambda i: str(b) if i <= a else str(a)
    *c, = map(f, x)
    ans = '\n'.join(c)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    n, *x = map(int, open(0).read().split())
    y = sorted(x)
    a, b = y[n // 2 - 1], y[n // 2]
    ans = ""
    for i in x:
        if i <= a:
            ans += str(b) + "\n"
        else:
            ans += str(a) + "\n"

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    n, *x = map(int, open(0).read().split())
    y = sorted(x)
    a, b = y[n // 2 - 1], y[n // 2]
    d = dict()
    for i, j in enumerate(y, 1):
        if i <= n // 2:
            d[j] = b
        else:
            d[j] = a

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7



def main():
    N = int(readline())
    X = list(map(int, readline().split()))
    sort_X = sorted(X)
    if N%2==0:
        med_l = sort_X[N//2-1]
        med_r = sort_X[N//2]
        for i in range(N):
            if X[i]<=med_l:
                print(med_r)
            else:
                print(med_l)
    else:
        l = sort_X[N//2-1]
        m = sort_X[N//2]
        r = sort_X[N//2+1]
        for i in range(N):
            if X[i]<=l:
                print((m+r)/2)
            elif X[i]==m:
                print((l+r)/2)
            else:
                print((l+m)/2)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

check = li.copy()
check.sort()
low = check[n//2 -1]
high = check[n//2]

for i in li:
    if i <= low:
        print(high)
    else:
        print(low)

Submission status: Accepted

Solution code:
n = int(input())
x = [int(i) for i in input().split()]
sx = sorted(x, reverse=True)
med1, med2 = sx[n//2 - 1], sx[n//2]
for xi in x:
    print(med1 if xi <= (med1 + med2) / 2 else med2)

Submission status: Accepted

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

sortx = sorted(X)
bef = sortx[N//2-1]
aft = sortx[N//2]
for i in X:
    if(i <= bef):
        print(aft)
    else:
        print(bef)
        # print(aft if i <= bef else bef)

Submission status: Accepted

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

sortx = sorted(X)
bef = sortx[N//2-1]
aft = sortx[N//2]
for i in X:
        print(aft if i <= bef else bef)

Submission status: Accepted

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

sort_x = sorted(x)
l = sort_x[n//2 - 1]
r = sort_x[n//2]

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

Submission status: Accepted

Solution code:
N,*X = map(int,open(0).read().split())
chu = N//2 - 1
nums = sorted(X,reverse=True)
num, num_right = nums[chu], nums[chu + 1]
for x in X:
    print(num if x < num else num_right)

Submission status: Accepted

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

for i in x:
  if i<xx[n//2]:
    print(xx[n//2])
  else:
    print(xx[n//2-1])

Submission status: Accepted

Solution code:
import sys
import bisect
input = sys.stdin.readline
 
 
def readstr():
    return input().strip()
 
 
def readint():
    return int(input())
 
 
def readnums():
    return map(int, input().split())
 
 
def readstrs():
    return input().split()
 
 
def main():
    N = readint()
    X = list(readnums())
    xs = sorted(X)
    for i in X:
        d = bisect.bisect_left(xs, i)
        if d >= N // 2:
            print(xs[N // 2 - 1])
        else:
            print(xs[N // 2])
 
 
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    *a, = map(int, input().split())

    *b, = sorted(a)

    h = N // 2
    L = b[h - 1]
    R = b[h]

    for x in a:
        if x <= L:
            print(R)
        else:
            print(L)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

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

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 range(N):
    if X[i]<=left:
        print(right)
    else:
        print(left)

Submission status: Accepted

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

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