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: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Contents   : AtCoder Regular Contest 095 c問題
Author     : Kitaura Hiromi
LastUpdate : 20180414
Since      : 20180414
"""
import random
import copy
def quickselect(items, item_index):

    def select(lst, l, r, index):

        # base case
        if r == l:
            return lst[l]

        # choose random pivot
        pivot_index = random.randint(l, r)

        # move pivot to beginning of list
        lst[l], lst[pivot_index] = lst[pivot_index], lst[l]

        # partition
        i = l
        for j in range(l+1, r+1):
            if lst[j] < lst[l]:
                i += 1
                lst[i], lst[j] = lst[j], lst[i]

        # move pivot to correct location
        lst[i], lst[l] = lst[l], lst[i]

        # recursively partition one side only
        if index == i:
            return lst[i]
        elif index < i:
            return select(lst, l, i-1, index)
        else:
            return select(lst, i+1, r, index)

    if items is None or len(items) < 1:
        return None

    if item_index < 0 or item_index > len(items) - 1:
        raise IndexError()

    return select(items, 0, len(items) - 1, item_index)

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

Submission status: Time Limit Exceeded

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

for i in range(N):
    #print(x[0:0])
    temp = x[0:i] + x[i+1:N]
    #print(temp)
    temp.sort()
    #print(temp)
    print(temp[int(len(temp)/2)])

Submission status: Time Limit Exceeded

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

def quickselect(items, item_index):

    def select(lst, l, r, index):

        # base case
        if r == l:
            return lst[l]

        # choose random pivot
        pivot_index = random.randint(l, r)

        # move pivot to beginning of list
        lst[l], lst[pivot_index] = lst[pivot_index], lst[l]

        # partition
        i = l
        for j in range(l+1, r+1):
            if lst[j] < lst[l]:
                i += 1
                lst[i], lst[j] = lst[j], lst[i]

        # move pivot to correct location
        lst[i], lst[l] = lst[l], lst[i]

        # recursively partition one side only
        if index == i:
            return lst[i]
        elif index < i:
            return select(lst, l, i-1, index)
        else:
            return select(lst, i+1, r, index)

    if items is None or len(items) < 1:
        return None

    if item_index < 0 or item_index > len(items) - 1:
        raise IndexError()

    return select(items, 0, len(items) - 1, item_index)

import numpy as np
N = int(input())
X = np.array(list(map(int, input().split(" "))))
for i in range(N):
    print(quickselect(np.append(X[:i], X[i+1:]), N//2-1))

Submission status: Time Limit Exceeded

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

y=[]
for i in range(N):
    y.append([x[i],i])
y.sort(key=lambda x:x[0])
z=y.copy()

for i in range(N):
    y=z.copy()
    for j in range(N):    
        if(y[j][1]==i):
            check=j
            break
    del y[j]
    print(y[int((N-1)/2)][0])

Submission status: Time Limit Exceeded

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

import numpy as np

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

for i in range(N):
    print(int(np.median(np.append(X[:i], X[i+1:]))))

Submission status: Time Limit Exceeded

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

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

sorted_X = sorted(X)
for i in range(N):
    j = sorted_X.index(X[i])
    if j < N//2:
        print(sorted_X[N//2])
    else:
        print(sorted_X[N//2-1])

Submission status: Time Limit Exceeded

Solution code:
import sys
N = int(sys.stdin.readline().rstrip()) # N個の数(# Nは偶数)
X_list = list(map(int, sys.stdin.readline().rstrip().split()))
for i in range(N):
    temp_list = X_list[:i] + X_list[i + 1:]
    temp_list.sort() # 要素を昇順にソート
    ans = temp_list[(N - 2) // 2]
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

for index, i in enumerate(lis):
    sub_lis = list(sorted(lis[0: index] + lis[index + 1: len(lis)]))
    # print(sub_lis)
    sub_ind = int((len(sub_lis) + 1) / 2) - 1
    # print(sub_ind)
    print(sub_lis[sub_ind])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


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


for i in range(N):
    y=x.copy()
    del y[i]
    print(int(np.median(y)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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


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


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

    X = list(map(int, input().split()))
    X_ = X[:]
    X_.sort()
    for i in range(N):
        if X[i] in X_[:N // 2]:
            print(mid_1(X_))
        else:
            print(mid(X_))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

n=int(input())
x=np.array(list(map(int,input().split())))
for i in range(n):
    y=np.delete(x,i)
    print(int(np.median(y)))

Submission status: Time Limit Exceeded

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

for i in range(N):
    print(sorted(X[:i] + X[i+1:])[(N-1)/2])

Submission status: Time Limit Exceeded

Solution code:
from statistics import mean, median,variance,stdev

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

for i in range(n):
    print(median(x[:i]+x[i+1:]))

Submission status: Time Limit Exceeded

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

import numpy as np
import copy

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

for i in range(n):
    x_i = copy.copy(x)
    del x_i[i]
    print int(np.median(x_i))

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import Counter
import random

n=int(input())
x=list(map(int,input().split()))
xb=x.copy()
y=sorted(x)
c=n//2-1
for i in range(n):
    x=xb.copy()
    a=x.pop(i)
    z=y.copy()
    z.remove(a)
    print(z[c])

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import Counter
import random

n=int(input())
x=list(map(int,input().split()))
z=x.copy()
c=n//2-1
for i in range(n):
    x=z.copy()
    x.pop(i)
    y=sorted(x)
    #print(y)
    print(y[c])

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
import numpy as np
N = int(input())
X = np.array(list(map(int, input().split())))
idx = np.ones(N, dtype=bool)
for i in range(N):
    idx[i] = False
    print(int(np.median(X[idx])))
    idx[i] = True

Submission status: Accepted

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

X_list_min = sorted(X_list)

for i in range(N):
    if X_list_min[N//2-1] >= X_list[i]:
        print(X_list_min[N//2])
    else:
        print(X_list_min[N//2-1])

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    B = [(b, i) for i, b in enumerate(map(int,input().split()))]
    B.sort()
    m2 = B[N//2][0]
    m1 = B[N//2-1][0]
    if m1 == m2:
        for i in range(N):
            print(m1)
        return

    ans = [0] * N
    for b, i in B:
        if b <= m1:
            ans[i] = m2
        else:
            ans[i] = m1
    print('\n'.join(map(str,ans)))
    # print(B)
# 1 2 2 2 
# 1 1 1 1 
main()

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))
newX = []
for i in range(N):
  newX.append((X[i],i))
newX.sort()
ans = [0]*N
f = N//2-1
l = N//2
for i in range(N):
  num, ind = newX[i]
  if i < l:
    ans[ind] = newX[l][0]
  else:
    ans[ind] = newX[f][0]
for j in ans:
  print(j)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
Xlist = list(map(int,input().split()))
Xcopy = Xlist.copy()
Xcopy.sort()
Xsm = Xcopy[N//2-1]
Xla = Xcopy[N//2]
if Xsm == Xla:
    for _ in range(len(Xlist)):
        print(Xsm)
else:
    for i in range(len(Xlist)):
        Tar = Xlist[i]
        if Tar <= Xsm:
            print(Xla)
        else:
            print(Xsm)

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 x in X:
    if x < r:
        print(r)
    else:
        print(l)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque, defaultdict
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N = II()
    X = LI()

    Y = sorted(X)
    n = (N + 1) // 2
    l = Y[n-1]
    r = Y[n]

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

if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from copy import deepcopy
N = int(input())
X = [int(i) for i in input().split()]
x = deepcopy(X)
X.sort()
if N%2 == 0:
    for i in x:
        if i <= X[N//2 - 1]:
            print(X[N//2])
        else:
            print(X[N//2 - 1])
else:
    for i in x:
        if i < X[N//2]:
            print((X[N//2] + X[N//2 + 1])/2)
        elif i == X[N//2 -1]:
            print((X[N//2 - 1] + X[N//2 + 1])/2)
        else:
            print((X[N//2 - 1] + X[N//2])/2)

Submission status: Accepted

Solution code:
import statistics
from bisect import bisect_left
N = int(input())
X = list(map(int,input().split()))
Y = sorted(X)
a,b = statistics.median_low(Y),statistics.median_high(Y)
for i in X:
    Z = bisect_left(Y,i)
    if Z<N//2:
        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]
M = Y[N//2]

for x in X:
  if m == M:
    print(m)
  elif x <= m:
    print(M)
  else:
    print(m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
lista = list(map(int, input().split()))
newlista = sorted(lista)

lowermedian = newlista[int(len(lista)/ 2- 1)]
highermedian = newlista[int(len(lista)/2)]

for i in range(N):
  if(lista[i] <= lowermedian):
    print(highermedian)
  else:
    print(lowermedian)

Submission status: Accepted

Solution code:
n, *lst = map(int, open(0).read().split())
a, b = sorted(lst)[n // 2 - 1:n // 2 + 1]
if a == b:
  print(*[a for _ in range(n)], sep='\n')
else:
  print(*[b if i <= a else a for i in lst], sep='\n')

Submission status: Accepted

Solution code:
n = int(input())
# h1, m1, h2, m2, k = list(map(int, input().split()))
# n, a, b = list(map(int, input().split()))
# a = list(map(int, input().split()))
# data = [list(map(int, input().split())) for i in range(n)]
# k = int(input())
t = list(map(int, input().split()))
# ab_sorted = sorted(ab, key=lambda x: x[0])
# py = [list(map(int, input().split())) for i in range(m)]
# b = list(map(int, input().split()))
t_sorted = sorted(t)
m = t_sorted[n//2-1]
m2 = t_sorted[n//2]
for i in range(n):
    if t[i] <= m:
        print(m2)
    else:
        print(m)

Submission status: Accepted

Solution code:
from statistics import median_high, median_low

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

a, b = median_low(l), median_high(l)
for i in l:
    if i <= a:
        print(b)
    else:
        print(a)

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

x1 = sorted(x)
tmp1 = n // 2
tmp2 = (n // 2) - 1
val1 = x1[tmp1]
val2 = x1[tmp2]

for i in range(len(x)):
    if x[i] < val1:
        print(val1)
    else:
        print(val2)

Submission status: Accepted

Solution code:
from copy import copy
N = int(input())
X = list(map(int,input().split()))
sortX = copy(X)
sortX.sort(reverse = True)
median1 = sortX[N // 2 - 1]
median2 = sortX[N // 2]
for i in X:
  if i >= median1: print(median2)
  else: print(median1)

Submission status: Accepted

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

X_sort=sorted(X)

med_n=X_sort[N//2-1]
med_p=X_sort[N//2]

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

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:
N=int(input())
temp=list(map(int,input().split()))
temp_s=sorted(temp)
min_median=temp_s[N//2-1]
max_median=temp_s[N//2]
if max_median==min_median:
   for i in range(N):
      print(max_median)
   exit()
for i in temp:
   if i <= min_median:
      print(max_median)
   else:
      print(min_median)

Submission status: Accepted

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

N = int(input())
X = list(map(int, input().split()))
D = {}
for i in range(N):
    D[i] = X[i]

X = sorted(X)
ans = [X[N//2-1], X[N//2]]
A = {}

cnt = 0
for i, v in sorted(D.items(), key=lambda x:x[1]):
    if cnt < N // 2:
        A[i] = ans[1]
    else:
        A[i] = ans[0]
    cnt += 1

for i, v in sorted(A.items(), key=lambda x:x[0]):
    print(v)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
 
n  = int(input())
#  = int(input())
x  = list(map(int, input().split()))
#  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

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

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

Submission status: Accepted

Solution code:
import bisect
n = int(input())
X = tuple(map(int,input().split()))
Xs = list(X)
Xs.sort()
for x in X:
    a = bisect.bisect_left(Xs,x)
    if a >= n/2:
        print(Xs[int(n/2)-1])
    else:
        print(Xs[int(n/2)])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int, input().split()))
sortX=sorted(X)
small=sortX[int(N/2)-1]
big=sortX[int(N/2)]
if small==big:
    for i in range(0,N):
        print(small)
    exit()

for i in range(0,N):
    if X[i]>small:
        print(small)
    else:
        print(big)

Submission status: Accepted

Solution code:
n = int(input())
x= list(map(int, input().split()))
sx=sorted(x)
center=sum(sx[n//2-1:n//2+1])/2
under=sx[n//2-1]
over=sx[n//2]
for i in x:
    if i>=center:
        print(under)
    else:
        print(over)

Submission status: Accepted

Solution code:
#!python3

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


def main():
    W = sorted(X)
    a = N // 2
    for i in range(N):
        if X[i] < W[a]:
            print(W[a])
        else:
            print(W[a - 1])


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
from bisect import bisect, bisect_left, bisect_right

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

sys.setrecursionlimit(10 ** 8)

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

Submission status: Accepted

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

y = []

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

y.sort()

ans = [-1 for i in range(n)]

for i in range(n // 2):
    ans[y[i][1]] = y[n // 2][0]

for i in range(n // 2, n):
    ans[y[i][1]] = y[n // 2 - 1][0]

for i in range(n):
    print(ans[i])

Submission status: Accepted

Solution code:
n, *X = map(int, open(0).read().split())
Y = sorted(X)
m = (n-1) // 2

for x in X:
    med = Y[m]
    if med >= x:
        med = Y[m+1]
    print(med)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
sa = sorted(a)
l = sa[N // 2 - 1]
r = sa[N // 2]
for i in range(N):
  if a[i] <= l: print(r)
  else: print(l)

Submission status: Accepted

Solution code:
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


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

sorted = np.msort(X)
I = np.searchsorted(sorted, X)
if N % 2 == 1:
    ans = np.zeros(N, dtype=int)
    ans[I <= N // 2] = sorted[N // 2 + 1]
    ans[I > N // 2] = sorted[N // 2]
else:
    ans = np.zeros(N, dtype=int)
    ans[I < N // 2] = sorted[N // 2]
    ans[I >= N // 2] = sorted[N // 2 - 1]
print(*ans, sep='\n')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


MOD = int(1e09) + 7
INF = int(1e15)


def calc(N):
    return sum(int(x) for x in str(N))


def main():
    # sys.stdin = open("sample.txt")
    N = Scanner.int()
    A = Scanner.map_int()
    B = sorted(A)
    m1 = B[N // 2 - 1]
    m2 = B[N // 2]

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

x2.sort()

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

for i in range(n):
    if x[i]<=ans1:
        print(ans2)
    #elif x[i]==ans2:
    #    print(ans1)
    else:
        print(ans1)###

Submission status: Accepted

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

A = sorted(X)
f = N // 2 - 1
b = f + 1
C1 = A[f]
C2 = A[b]

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


def solve(N, X):
    Y = sorted(list(zip(X, range(N))))
    n = N // 2
    d = dict()
    for i in range(N):
        m = n - (i >= n)
        d[Y[i][1]] = Y[m][0]
    for k, v in (sorted(d.items(), key=lambda x: x[0])):
        print(v)


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]"
    solve(N, X)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

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

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

main()

Submission status: Accepted

Solution code:
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 < m2:
            print(m2)
        else:
            print(m1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007




n = I()
L = LI()
left = sorted(L)[n // 2 - 1]
right = sorted(L)[n // 2]
for i in range(n):
    if L[i] <= left:
        print(right)
    else:
        print(left)

Submission status: Accepted

Solution code:

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

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

x = X[:]
x.sort()
m1 = x[N//2 - 1]
m2 = x[N//2]

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

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
sorted_X = sorted(X)
median_index = N//2
ans1 = sorted_X[median_index]
ans2 = sorted_X[median_index-1]

for x in X:
  if ans1 > x:
    print(ans1)
  else:
    print(ans2)

Submission status: Accepted

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

if sorted_x[n // 2] == sorted_x[n // 2 - 1]:
    ret = [sorted_x[n // 2]] * n
else:
    ret = []
    for i in range(n):
        if x[i] >= sorted_x[n // 2]:
            ret.append(sorted_x[n // 2 - 1])
        else:
            ret.append(sorted_x[n // 2])
for i in ret:
    print(i)

Submission status: Accepted

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

Y = sorted(X)

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

for i in X:
    if l >= i:
        print(r)
    else:
        print(l)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

X_sorted = sorted(X)
first_half_median = X_sorted[N // 2 - 1]
last_half_median = X_sorted[N // 2]

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = A.copy()
B.sort()
a = B[N//2-1]
b = B[N//2]

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

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int,input().split()))
S = X[:]
S.sort()
C1 = S[(N//2)-1]
C2 = S[N//2]
for x in X:
    if x >= C2:
        print(C1)
    else:
        print(C2)

Submission status: Accepted

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