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:
import copy

N = int(input())

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

center = N // 2 - 1

for i in range(N):
    B = copy.deepcopy(X)

    del B[i]

    B.sort(reverse=True)

    print(B[center])

Submission status: Time Limit Exceeded

Solution code:
from statistics import median
import copy

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

for i in range(n):
    new_x = copy.copy(x)
    del new_x[i]
    #new_x.sort()
    print(median(new_x))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    Xi = [(i, int(x)) for i, x in enumerate(stdin.readline().rstrip().split())]
    Xi = sorted(Xi, key=lambda x:x[1], reverse=True)
    for i in range(N):
        xi = [x[1] for x in Xi if x[0] != i]
        print(xi[(N - 1)// 2])


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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


for x in range(len(X)):
    tmp = X.copy()
    tmp.pop(x)
    tmp.sort()
    print(tmp[ (len(tmp))//2 ] )

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
X = list(map(int, input().split()))
m = N//2 - 1

for i in range(N):
    x = X.copy()
    x.pop(i)
    print(sorted(x)[m])

Submission status: Time Limit Exceeded

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

for i in range(len(x)):
    tmp_list = x.copy()
    tmp_list.pop(i)
    tmp_list.sort()
    print(tmp_list[int(n/2-1)])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
x = list(map(int, input().split()))
for i in range(n):
    y = x[:]
    y.pop(i)
    y.sort()
    print(y[n//2-1])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
x = list(map(int, input().split()))
for i in range(n):
    y = x[:]
    y.pop(i)
    y = list(sorted(y))
    s = n // 2
    print(y[-s])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

X_ = deepcopy(X)
for i in range(N):
    X = deepcopy(X_)
    X.pop(i)
    X.sort()
    print(X[int(N/2)-1])

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
List=list(map(int,input().split()))
lastindex=N//2
AList=List[:]
List.sort()
for index in range(N):
    BList=List[:]
    BList.remove(AList[index])
    print(BList[N//2-1])

Submission status: Time Limit Exceeded

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

for i in range(N):
    Y = X[:]
    Y.pop(i)
    Y.sort()
    print(Y[int((N-1)/2)])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
x = list(map(int, input().split()))
t = sorted(x)
for i in range(n):
    j = t.index(x[i])
    s = t[:j] + t[j + 1:]
    print(s[n // 2 - 1])

Submission status: Time Limit Exceeded

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

ind = int(len(x)/2) - 1
for i in range(n):
    xx = sorted(x[:i] + x[(i+1):])
    print(xx[ind])

Submission status: Time Limit Exceeded

Solution code:
from statistics import median


N = int(input())
X = list(map(int, input().split()))
for i in range(N):
    x = X[:]
    del x[i]
    print(median(x))

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    X = [int(i) for i in input().split()]
    
    for i in range(N):
        remove_X = X[:i]+ X[i+1:]
        
        sorted_remove_X = sorted(remove_X)
        print(sorted_remove_X[int((N-1)/2)])
    
if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

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

def median(x):
    x = sorted(x)

    return(x[(len(x) + 1) // 2 - 1])

for i in range(n):
    a = x.pop(i)
    print(median(x))
    x.insert(i, a)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
X = list(map(int, input().split()))
temp = 0
for i in range(N):
    temp = X[i]
    X[i] = 0
    print(sorted(X)[int(N/2)])
    X[i] = temp

Submission status: Time Limit Exceeded

Solution code:
from statistics import median
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:
N=int(input())
List=list(map(int,input().split()))
lastindex=N//2
for index in range(N):
    AList=List[:]
    AList.pop(index)
    AList.sort()
    print(AList[N//2-1])

Submission status: Time Limit Exceeded

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

for i in range(n):
    new_x = copy.copy(x)
    del new_x[i]
    new_x.sort()
    print(new_x[n//2-1])

Submission status: Time Limit Exceeded

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

for i in range(N):
    X_list = list(map(int, INPUT.split()))
    del X_list[i]
    print(sorted(X_list)[int(N / 2 - 1)])

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.pop(i)
    print(int(np.median(x)))
    x.insert(i, y)

Submission status: Time Limit Exceeded

Solution code:
import sys
if __name__ == "__main__":
    N = int(input())
    X = list(map(int, (input().split(' '))))
    for i in range(N):
        buf = list(X)
        buf.pop(i)
        buf = sorted(buf)
        print(buf[int(N/2)-1])

Submission status: Time Limit Exceeded

Solution code:

import copy

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

def medianIndex(l, i):
    l.pop(i-1)
    num = len(l)
    l.sort()
    m = int((num - 1) / 2)
    print(l[m])
    

for i in range(1,n+1):
    temp = copy.copy(x)
    medianIndex(temp, i)

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):
    print(int(np.median(X[:i]+X[i+1:])))

Submission status: Time Limit Exceeded

Solution code:
def b(nums):
	nums.sort()
	if len(nums)%2==0:
		return (nums[len(nums)/2-1]+nums[len(nums)/2])/2
	else:
		return nums[len(nums)//2]
if __name__ == '__main__':
	n = int(input())
	nums = list(map(int, input().split(" ")))
	for i in range(n):
		print(b(nums[0:i] + nums[i+1::]))

Submission status: Time Limit Exceeded

Solution code:
import re
import doctest


class IO_for_Contest(object):
    @staticmethod
    def my_input():
        # return raw_input()
        return input()

    @staticmethod
    def read_from_input():
        return IO_for_Contest.read_n_int(1)

    @staticmethod
    def read_line():
        return IO_for_Contest.my_input().strip()

    @staticmethod
    def read_int():
        return int(IO_for_Contest.my_input().strip())

    @staticmethod
    def read_n_int(n):
        return list(map(
                    int,
                    re.split('\s+', IO_for_Contest.my_input().strip())))[: n]


def median_without(x, e):
    y = []
    y.extend(x)
    y.remove(e)
    index = len(x) // 2 - 1
    return sorted(y)[index]


def solve():
    [n] = IO_for_Contest.read_from_input()
    x = IO_for_Contest.read_n_int(n)
    y = sorted(x)
    for e in x:
        print(median_without(y, e))

if __name__ == '__main__':
    # doctest.testmod()
    solve()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
x = [i for i in map(int ,input().split())]
mid = (N-1) // 2
for i in range(N):
    tmp = x[:]
    tmp.remove(x[i])
    tmp.sort()
    print(tmp[mid])

Submission status: Time Limit Exceeded

Solution code:
# coding=utf-8


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

X_list2 = X_list[:]
X_list2.sort()

for element in X_list:
    if X_list2.index(element) < (N-1)/2:
        print(X_list2[N//2])
    else:
        print(X_list2[(N//2 -1)])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from copy import deepcopy

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

def median(x, i):
    y = deepcopy(x)
    y.pop(i)
    y = sorted(y)

    return(y[(len(y) + 1) // 2 - 1])

for i in range(n):
    print(median(x, i))

Submission status: Time Limit Exceeded

Solution code:
import copy

N=int(input())
X=list(map(int,input().split(" ")))
for i in range(N):
  Y=copy.deepcopy(X)
  Y.pop(i)
  Y.sort()
  print(Y[(N-1)//2])

Submission status: Time Limit Exceeded

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

for i in range(N):
    tmp = X[:i] + X[i + 1:]
    tmp.sort()
    print(tmp[N // 2 - 1])

Submission status: Time Limit Exceeded

Solution code:
def abc094C():
    n = int(input())
    x = input().split()
    x = list(map(int, x))
    for i in range(n):
        y = x.copy()
        del y[i]
        y.sort()
        print(y[int(n / 2)-1])


abc094C()

Submission status: Time Limit Exceeded

Solution code:
import math
n = int(input())
lis = list(map(int,input().split()))

num = int((n-2)/2)
for i in range(n):
	li = lis
	a = li.pop(i)
	lislis = li
	print(sorted(lislis)[int((n-2)/2)])
	li.insert(i,a)

Submission status: Time Limit Exceeded

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

for i in range(N):
    tmp = X.copy()
    tmp.pop(i)
    tmp.sort()
    print(tmp[int((N-1)/2)])

Submission status: Time Limit Exceeded

Solution code:
n = input()
x = map(int, raw_input().split())
for i in xrange(n):
    x2 = x[:i]+x[i+1:]
    print sorted(x2)[(n/2)-1]

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
X = tuple(int(x) for x in input().split())
length = len(X)
for x in range(length):
 print(sorted(X[:x]+X[x+1:])[length//2-1])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
x = list(map(int,input().split()))
import numpy as np
import copy
np.median(x)
for i in range(n):
    x_c = copy.copy(x)
    x_c.pop(i)
    print("{}".format(int(np.median(x_c))))

Submission status: Time Limit Exceeded

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

for i in range(N):
    temp=X[:i]+X[i+1:]
    temp.sort()
    print(temp[N//2-1])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
X = list(map(int,input().split()))
B = [0]*(N-1)
mid = int(N/2)-1
for i in range(N):
    B = X[:i]+X[i+1:]
    B.sort()
    print(B[mid])

Submission status: Time Limit Exceeded

Solution code:
from statistics import median

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

for i in range(N):
    Xx = [X[k] for k in range(N) if k != i]
    print(median(Xx))

Submission status: Time Limit Exceeded

Solution code:
import re
import doctest


class IO_for_Contest(object):
    @staticmethod
    def my_input():
        # return raw_input()
        return input()

    @staticmethod
    def read_from_input():
        return IO_for_Contest.read_n_int(1)

    @staticmethod
    def read_line():
        return IO_for_Contest.my_input().strip()

    @staticmethod
    def read_int():
        return int(IO_for_Contest.my_input().strip())

    @staticmethod
    def read_n_int(n):
        return list(map(
                    int,
                    re.split('\s+', IO_for_Contest.my_input().strip())))[: n]


def median_without(x, e):
    y = []
    y.extend(x)
    y.remove(e)
    index = len(x) // 2 - 1
    return sorted(y)[index]


def solve():
    [n] = IO_for_Contest.read_from_input()
    x = IO_for_Contest.read_n_int(n)
    for e in x:
        print(median_without(x, e))

if __name__ == '__main__':
    # doctest.testmod()
    solve()

Submission status: Time Limit Exceeded

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

Submission status: Accepted

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

p,q=A[N//2-1:N//2+1]

for i in List:
  print(p if i>=q else q)

Submission status: Accepted

Solution code:
import bisect
n=int(input())
X=list(map(int,input().split()))
sortX = sorted(X)
ansl = sortX[n//2-1]
ansu = sortX[n//2]
for x in X:
  if bisect.bisect(sortX,x) > n//2:
    print(ansl)
  else:
    print(ansu)

Submission status: Accepted

Solution code:
import statistics
n = int(input())
X = list(map(int, input().split()))
X_ = sorted(X)
med = X_[n//2-1]
med_2 = X_[n//2]
for i in range(n):
    if X[i]>med:
        print(med)
    else:
        print(med_2)

Submission status: Accepted

Solution code:
# import itertools
# import math
# from functools import reduce
# import sys
# sys.setrecursionlimit(500*500)
# import numpy as np
# import heapq
# from collections import deque
import copy

N = int(input())
# S = input()
# n, *a = map(int, open(0))
# N, M = map(int, input().split())
X = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)

# 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

#def make_divisors(n):
#    lower_divisors , upper_divisors = [], []
#    i = 1
#    while i*i <= n:
#        if n % i == 0:
#            lower_divisors.append(i)
#            if i != n // i:
#                upper_divisors.append(n//i)
#        i += 1
#    return lower_divisors + upper_divisors[::-1]

# def gcd_list(numbers):
#     return reduce(math.gcd, numbers)

# if gcd_list(A) > 1:
#     print("not coprime")
#     exit()

# 高速素因数分解準備
#MAXN = 10**6+10
#sieve = [i for i in range(MAXN+1)]
#p = 2
#while p*p <= MAXN:
#    if sieve[p] == p:
#        for q in range(2*p, MAXN+1, p):
#            if sieve[q] == q:
#                sieve[q] = p
#    p += 1

X = [[i, x] for i, x in enumerate(X)]
X = sorted(X, reverse=False, key=lambda x:x[1])
X_ranked = copy.copy(X)
X = [[l[0], i, l[1]] for i, l in enumerate(X)]
X = sorted(X, reverse=False, key=lambda x:x[0])

med = len(X) // 2

for l in X:
    if l[1] < med:
        print(X_ranked[med][1])
    else:
        print(X_ranked[med - 1][1])

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
xl = [int(x) for x in input().split()]

xlsorted = np.sort(xl)
m1 = xlsorted[int(N/2)-1]
m2 = xlsorted[int(N/2)]

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

Submission status: Accepted

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

sxs = sorted(XS)
a1 = sxs[N//2-1]
a2 = sxs[N//2]

for i in range(N):
  x = XS[i]
  if x <= a1:
    print(a2)
  else:
    print(a1)

Submission status: Accepted

Solution code:
N = int(input())
N_List = list(map(int,input().split()))
N_List_Sorted = sorted(N_List)
B = N_List_Sorted[N//2]
A = N_List_Sorted[N//2 - 1]

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

Submission status: Accepted

Solution code:
# import sys
# input = sys.stdin.readline
import collections
import itertools


def main():
    n = int(input())
    x = input_list()
    sx = list(sorted(x))
    h = n//2
    a1 = sx[h-1]
    a2 = sx[h]
    for v in x:
        if v <= a1:
            print(a2)
        else:
            print(a1)


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


def input_list_str():
    return list(map(str, input().split()))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

left=x1[n//2-1]
right=x1[n//2]

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

Submission status: Accepted

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

def main():
    n = int(input())
    x = list(map(int, input().split()))
    ans = [0] * n
    x_sort = sorted(x)
    a = x_sort[1:n]
    a_med = a[n // 2 - 1]
    b = x_sort[0:n - 1]
    b_med = b[n // 2 - 1]
    for i in range(n):
        if x[i] < a_med:
            ans[i] = a_med
        else:
            ans[i] = b_med

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

tmp.sort()
a = tmp[int(N/2)-1]
b = tmp[int(N/2)]
for i in range(N):
    if(X_list[i] <= a):
        print(b)
    else:
        print(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 22 14:57:09 2020

@author: liang
"""

N = int(input())
X = [int(x) for x in input().split()]
Y = X.copy()
Y.sort()
upper = Y[N//2]
lower = Y[N//2-1]

for i in range(N):
    if X[i] < upper:
        print(upper)
    else:
        print(lower)

Submission status: Accepted

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

Submission status: Accepted

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

sorted_x = sorted(X)

l, r = sorted_x[n//2-1], sorted_x[n//2]

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

Submission status: Accepted

Solution code:
import bisect

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

sorted_x = sorted(X)

l, r = sorted_x[n//2], sorted_x[n//2-1]

for x in X:
    if bisect.bisect_left(sorted_x, x) < n // 2:
        print(l)
    else:
        print(r)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int,input().split()))
y = x.copy()
y.sort()
z = set(x)
t1 = y[n//2-1]
t2 = y[n//2]
idx = dict([])
idx[y[0]] = 0
l = y[0]
cnt = 0
for i in y:
    if i == l:
        cnt += 1
        continue
    else:
        idx[i] = cnt
        l = i
        cnt += 1

for i in x:
    t = idx[i]
    if t<n//2:
        print(t2)
    else:
        print(t1)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import copy

n = int(input())

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

XX = copy.deepcopy(X)
XX.sort()
high = XX[n//2]
low = XX[n//2-1]

for i in range(n):
    if high == low:
        print(high)
        continue
    if X[i] < high:
        print(high)
    else:
        print(low)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

def main(n,x):
    y = sorted(x)
    a,b = y[(n-1)//2],y[(n-1)//2+1]
    for i in x:
        if i>a:
            print(a)
        else:
            print(b)

if __name__=="__main__":
    n,x = getval()
    main(n,x)

Submission status: Accepted

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    import statistics
    n = i_input()
    l = i_list()
    ml = min(l)
    Ml = max(l)
    ol = statistics.median(l)

    L = l.copy()

    L.remove(ml)
    pol = statistics.median(L)
    L.append(ml)

    L.remove(Ml)
    mol = statistics.median(L)
    L.append(Ml)

    ans = []

    for i in l:
        if i >= ol:
            ans.append(mol)
        else:
            ans.append(pol)

    for i in ans:
        print(i)



if __name__=="__main__":
    main()

Submission status: Accepted

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

m1=Y[N//2-1]
m2=Y[N//2]

medians = [m2 if x < m2 else m1 for x in X]
print('\n'.join(map(str,medians)))

Submission status: Accepted

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

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

for x in xx:
  if x <= a:
    print(b)
  elif x >= b:
    print(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
x=list(map(int,input().split()))
sort_dict={}
count=0
from collections import deque

_x = deque()
for i in sorted(enumerate(x), key=lambda x:x[1]):
    sort_dict[i[0]]=count#昔のインデックスi[0]=count(新しいインデックス)
    _x.append(i[1])#並び替えの要素を追加
    count+=1
_x=list(_x)

cut=N//2-1

for i in range(N):
    #抜く数字はx[i].x[i]の_xにおけるインデックスが分かれば、答えは出る
    #i:ソート前のインデックス
    #sorted_dict[i]:ソートあとインデックス=
    sort_idx=sort_dict[i]
    if sort_idx<=cut:
        print(_x[cut+1])
    else:
        print(_x[cut])

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:
import sys


# \n
def input():
    return sys.stdin.readline().rstrip()


def main():
    N=int(input())
    A=list(map(int,input().split()))
    AS =sorted(A)
    right = AS[N//2]
    left = AS[N//2 -1]
    for a in A:
        if a<=left:
            print(right)
        else:
            print(left)




if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x):
        self.setdefault(x,0)
        self[x] += 1

N,X = ilint()
L = [(i,X[i]) for i in range(N)]
L.sort(key=lambda x:x[1])
B1,B2 = L[N//2-1][1],L[N//2][1]
ans = [B1]*N
for i in range(N//2):
    ans[L[i][0]] = B2
lprint(ans)

Submission status: Accepted

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

    median1 = x_sorted_lst[n // 2 - 1]
    median2 = x_sorted_lst[n // 2]

    if median1 == median2:
        lst = [median1] * n

    else:
        lst = []
        for i in range(n):
            x = x_lst[i]

            if x <= median1:
                lst.append(median2)
            elif median2 <= x:
                lst.append(median1)

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
s = list(sorted(a))
ind = {}
for i in range(N):
    if s[i] not in ind:
        ind[s[i]] = i
for i in range(N):
    if ind[a[i]] < N//2:
        print(s[N//2])
    else:
        print(s[N//2-1])

Submission status: Accepted

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

pivots = (sorted(a)[n//2-1], sorted(a)[n//2])
# print(pivots)
for el in a:
    if el <= pivots[0]:
        print(pivots[1])
    else:
        print(pivots[0])

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]
if a==b:
  for _ in range(n): print(a)
else:
  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()))
x_sorted = sorted(x)
med_low = x_sorted[(n // 2) - 1]
med_upper = x_sorted[(n // 2)]

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

Submission status: Accepted

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

mid_ls = [sort_X[N//2-1],sort_X[N//2]]

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

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

answers = [x[n//2 - 1][0]] * n

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

for i in answers:
    print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
sorted_x=sorted(x)
min_m,max_m=sorted_x[n//2-1],sorted_x[n//2]

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

Submission status: Accepted

Solution code:
#51 C - Many Medians
N = int(input())
X = list(map(int,input().split()))
Xsrt = sorted(X,reverse = False)
XL = set(Xsrt[:N//2])
XR = set(Xsrt[N//2:])

ans = []
for x in X:
    if x in XR:
        ans.append(Xsrt[N//2-1])
    elif x in XL:
        ans.append(Xsrt[N//2])
for a in  ans:
    print(a)

Submission status: Accepted

Solution code:
N = int(input())
Xls = list(map(int,input().split()))
X2ls = sorted(Xls)
M1 = X2ls[N//2-1]
M2 = X2ls[N//2]
lsans = []
for i in range(N):
    if Xls[i] <= M1:
        M = M2
    else:
        M = M1
    lsans.append(M)
for i in lsans:
    print(i)

Submission status: Accepted

Solution code:
from copy import *

N=int(input())
X=list(map(int,input().split()))
Y=deepcopy(X)
Y.sort()
mid1=Y[N//2-1]
mid2=Y[N//2]
for i in range(N):
  if X[i]<=mid1:
    print(mid2)
  else:
    print(mid1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

b=a[:]
a.sort()

one=a[n//2-1]
two=a[n//2]

def get_median(i):
    if b[i]<=one:
        return two
    return one

for i in range(n):
	print(get_median(i))