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:
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:
N = int(input())
X = list(map(int, input().split()))
A = sorted(X)
mid = (A[N//2] + A[N//2-1]) / 2

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

Submission status: Accepted

Solution code:
import sys

# import math
# import bisect

# import copy
# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
# INF = sys.maxsize
# MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    d = na()

    tmp_d = sorted(d)

    front = tmp_d[n//2-1]
    rear = tmp_d[n//2]

    for num in d:

        if front>=num:
            print(rear)
        else:
            print(front)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
x = [(i, int(j)) for i, j in enumerate(input().split())]
x.sort(key=lambda x:x[1])
l = x[n//2-1][1]
r = x[n//2][1]
ans = [None]*n
for ind, (i, j) in enumerate(x):
    if ind<n//2:
        ans[i] = r
    else:
        ans[i] = l

for i in ans:
    print(i)

Submission status: Accepted

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

mid1=x[N//2-1]
mid2=x[N//2]

for i in X:
    if 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-1]
b=y[n//2]
for i in x:
    if i<=a:
        print(b)
    else:
        print(a)

Submission status: Accepted

Solution code:
import sys
import bisect
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    X = list(map(int, input().split()))
    X_s = sorted(X)

    for i in range(n):
        idx = bisect.bisect_left(X_s, X[i])
        if idx <= n // 2 - 1:
            print(X_s[n // 2])
        else:
            print(X_s[n // 2 - 1])


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

#にぶたんサーチ
def search(arr, num):
    l = 0
    r = len(arr) - 1
    while r - l > 1:
        c = (r + l) // 2
        if arr[c] > num:
            r = c
        elif arr[c] < num:
            l = c
        else:
            r = c
            l = c
    if arr[l] == num:
        return l
    elif arr[r] == num:
        return r
    else:
        return -1

n = INT()
x = LIST()
arr1 = sorted(list(set(x)))
arr2 = Counter(x)
arr3 = [-1 for _ in range(len(arr1))]
for i in range(len(arr1)):
    arr3[i] = arr2[arr1[i]]
    arr3[i] += arr3[i - 1] if i > 0 else 0
med = n // 2 - 1
y = sorted(x)
mdx_mn = y[med]
mdx_mx = y[med + 1]

for xx in x:
    idx = search(arr1, xx)
    if idx == 0:
        print(mdx_mx)
        continue
    mn = arr3[idx - 1]
    mx = arr3[idx]
    if med < mn:
        print(mdx_mn)
    else:
        print(mdx_mx)

Submission status: Accepted

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

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:
from copy import deepcopy
n=int(input())
x=list(map(int, input().split()))
x1=deepcopy(x)
x.sort()
median1 = int(n//2)
median2 = int(n//2-1)
median=(x[median1]+x[median2])/2
for i in x1:
  if i<=median:
    print(x[median1])
  else:
    print(x[median2])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from copy import deepcopy


def main():
    n = int(input())
    x = list(map(int, input().split()))
    y = deepcopy(x)
    y.sort()
    median = y[n // 2]
    next_median = y[n // 2 - 1]
    for xx in x:
        if xx >= median:
            print(next_median)
        else:
            print(median)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

X_sort = sorted(X)

tmp_m = X_sort[N // 2 - 1]
tmp_p = X_sort[N // 2]

for x in X:
    if x <=tmp_m:
        print (tmp_p)
    else:
        print (tmp_m)

Submission status: Accepted

Solution code:
n = int(input())
x = [(ind, int(i)) for ind, i in enumerate(input().split())]
x.sort(key=lambda x:x[1])
ans = [None]*n
l = x[n//2-1][1]
r = x[n//2][1]
for ind, (i, _) in enumerate(x):
    if ind<n//2:
        ans[i] = r
    else:
        ans[i] = l
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    N=int(readline())
    A=list(map(int,readline().split()))

    B=sorted(A)
    left=B[N//2-1]
    right=B[N//2]

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

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
import statistics

n = int(input())
li = list(map(int,input().split()))
median_low = statistics.median_low(li)
median_high = statistics.median_high(li)

for i in li:
    if i <= median_low:
        print(median_high)
    else:
        print(median_low)

Submission status: Accepted

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

Submission status: Accepted

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

A_sorted = sorted(As)
med1 = A_sorted[N//2-1]
med2 = A_sorted[N//2]

for A in As:
  if A <= med1:
    print(med2)
  else:
    print(med1)

Submission status: Accepted

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

sorted_x = sorted(x)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
xl = list(map(int, input().split()))
xl_s = sorted(xl)

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

for x in xl:
    if x >= r:
        print(l)
    else:
        print(r)

Submission status: Accepted

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

y = sorted(x)
mid1 = y[(n + 1) // 2]
mid2 = y[(n - 1) // 2]

for i in range(n):
    if mid1 == mid2:
        ans = mid1
    elif x[i] >= mid1:
        ans = mid2
    elif x[i] <= mid2:
        ans = mid1

    print(ans)

Submission status: Accepted

Solution code:
n=int(input())
x=list(map(int,input().split()))
d=sorted(x)
b1=d[len(x)//2-1]
b2=d[len(x)//2]
for i in x:
  if i<=b1:
    print(b2)
  elif i>=b2:
    print(b1)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
n = int(input())
a = [int(x) for x in input().split()]
b = sorted(a)
if n%2:
  k1 = (b[n//2-1]+b[n//2])/2
  k2 = (b[n//2+1]+b[n//2])/2
  k3 = (b[n//2-1]+b[n//2+1])/2
else:
  k1 = b[n//2-1]
  k2 = b[n//2]
  k3 = -1

if k1 == k2:
  for i in range(n):
    print(k1)
else:
  for i in range(n):
    if n%2 and a[i] == b[n//2]:
      print(k3)
    elif a[i] <= k1:
      print(k2)
    else:
      print(k1)

Submission status: Accepted

Solution code:
def myAnswer(N:int,X:list) -> None:
   tmp = sorted(X)
   r1 = tmp[N//2-1]
   r2 = tmp[N//2]
   for x in X:
      if(x <=r1):
         print(r2)
      else:
         print(r1)




def modelAnswer():
   return
def main():
   N = int(input())
   X = list(map(int,input().split()))
   myAnswer(N,X)
if __name__ == '__main__':
   main()

Submission status: Accepted

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

L = sorted_x[(N-1)//2]
M = sorted_x[(N+1)//2]
base = (L+M)/2


for i in  list_x:
    if i >= base:
        print(L)
    else:
        print(M)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
from statistics import median_low,median_high
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
N = int(input())
arrX = list(map(int,input().split()))
# arrA = np.array(input().split(),dtype=np.int64)

X = sorted(arrX)
low = median_low(X)
high = median_high(X)

for i in arrX:
    if i <= low:
        print(high)
    elif i >= high:
        print(low)

# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Accepted

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

y = sorted(x)

m = (y[len(y)//2]+y[len(y)//2-1])/2



for i in range(len(x)):
    if x[i] > m:
        print(y[len(y)//2-1])
    else:
        print(y[len(y)//2])

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
arr0=limii()
arr=sorted(arr0)

#print(arr)

cenleft=arr[n//2 -1]
cenright=arr[n//2]
for i in range(n):
    if arr0[i]==cenleft:
        print(cenright)
    elif arr0[i]==cenright:
        print(cenleft)
    elif arr0[i]>=cenright:
        print(cenleft)
    else:
        print(cenright)

Submission status: Accepted

Solution code:
n = int(input())
li = list(map(int,input().split()))
lee = len(li)
sorted_li = sorted(li)
mid = sorted_li[lee//2]
mid_mae = sorted_li[lee//2-1]
tmp = mid
for l in li:
    if l < mid:
        print(mid)
    else:
        print(mid_mae)

Submission status: Accepted

Solution code:
N = int(input())
x = input().split()
X = [(int(x[i]), i) for i in range(N)]
X.sort()
ans = [0]*N
for i in range(N // 2):
    ans[X[i][1]] = X[N // 2][0]
for i in range(N // 2, N):
    ans[X[i][1]] = X[N // 2 - 1][0]
for i in range(N):
    print(ans[i])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import statistics
n = int(input())-1
a = list(map(int, input().split()))
N = sorted([[x,y] for y, x in enumerate(a)])

ans = [0] * (n+1)
for i in range(n+1):
    if i < n//2+1: 
        ans[N[i][1]] = N[n//2+1][0]
    else: ans[N[i][1]] = N[n//2][0]
for x in ans: print(x)

Submission status: Accepted

Solution code:
N = int(input())
X = [int(x) for x in input().split()]
X_sorted = sorted(X)
L = X_sorted[N//2 - 1]
R = X_sorted[N//2]

for x in X:
  if x >= R:
    print(L)
  else:
    print(R)

Submission status: Accepted

Solution code:
N = int(input())
X = [int(x) for x in input().split()]
X_sorted = sorted(X)
L = X_sorted[N//2 - 1]
R = X_sorted[N//2]

for x in X:
  print(L if x >= R else R)

Submission status: Accepted

Solution code:

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

y=sorted(x)

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

Submission status: Accepted

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

sx = sorted(x)
m = (n+1)//2
med1 = sx[m - 1]
med2 = sx[m]

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
ma = lambda : map(int,input().split())
ni = lambda : int(input())
import collections
n = ni()
x = list(ma())
x2 = sorted(x)
me1 = x2[n//2]
me2 = x2[n//2-1]
for nu in x:
    if nu<me1:
        print(me1)
    else:
        print(me2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def binary_search_loop(data, target):
    imin = 0
    imax = len(data) - 1
    while imin <= imax:
        imid = imin + (imax - imin) // 2
        if target == data[imid]:
            return imid
        elif target < data[imid]:
            imax = imid - 1
        else:
            imin = imid + 1
    return False
n = int(input())
lista = list(map(int, input().split()))
listb = sorted(lista)
for i in range(n):
    if binary_search_loop(listb, lista[i]) + 1 <= (n // 2):
        print(listb[(n // 2)])
    else:
        print(listb[(n // 2) - 1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

# https://atcoder.jp/contests/abc094/tasks/arc095_a
# 15:04-15:09


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

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


main()
# print(main())

Submission status: Accepted

Solution code:
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    n = ni()
    x = nl()

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

    x.sort(key=lambda x: x[0])

    left = n//2 - 1
    right = left + 1

    for i, arr in enumerate(x):
        arr.append(x[right][0] if i <= left else x[left][0])

    x.sort(key=lambda x: x[1])
    
    for arr in x:
        print(arr[2])


if __name__ == '__main__':
    main()

Submission status: Accepted

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

mid1, mid2 = sorted(X)[N//2-1:N//2+1]
smid1 = str(mid1)
smid2 = str(mid2)
print('\n'.join(smid1 if xi>mid1 else smid2 for xi in X))

Submission status: Accepted

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

mid1, mid2 = sorted(X)[N//2-1:N//2+1]
print('\n'.join(str(mid1) if xi>mid1 else str(mid2) for xi in X))

Submission status: Accepted

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

mid1, mid2 = sorted(X)[N//2-1:N//2+1]
print(*[mid1 if xi>mid1 else mid2 for xi in X], sep="\n")

Submission status: Accepted

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

mid = sorted(X)[N//2-1:N//2+1]
for xi in X:
    if xi > mid[0]:
        print(mid[0])
    else:
        print(mid[1])

Submission status: Accepted

Solution code:
# solution

import io
import sys

data = int(input())
array = list(map(int,input().split()))
qwe = sorted(array)
a = qwe[data//2]
b = qwe[data//2-1]
for i in array:
  if i >= a:
    print(b)
  else:
    print(a)

Submission status: Accepted

Solution code:
n = int(input())

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

left = x[n//2-1]
right = x[n//2]
mid = (left+right)/2

for i in range(n):
    if xx[i] >= mid:
        print(left)
    else:print(right)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

a.sort()

ans = [0] * n

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

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

Submission status: Accepted

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

        print(xs[tmp-1])

Submission status: Accepted

Solution code:
def main():
  N = int(input())
  X = [int(_) for _ in input().split()]
  Y = sorted(X)
  mid = (Y[(N-1)//2] + Y[N//2]) / 2
  for i in range(N):
    print(Y[N//2] if X[i] <= mid else Y[(N-1)//2])
  return

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import sys

def main():
    N = int(sys.stdin.readline())
    X = list(map(int, sys.stdin.readline().rstrip().split()))
    
    x_asc = sorted(X)
    m1, m2 = x_asc[N//2-1], x_asc[N//2]
    for x in X:
        if x <= m1:
            print(m2)
        else:
            print(m1)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Xs = sorted(As)

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

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

Submission status: Accepted

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

a1=li[n//2-1]
a2=li[n//2]

for i in x:
    if i<=a1:
        print(a2)
    else:
        print(a1)

Submission status: Accepted

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

Submission status: Accepted

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

sorted_x = sorted(x_ls)
bigger = sorted_x[n//2]
smaller = sorted_x[n//2 - 1]

# 含まれてるならそのインデックス 、含まれてないなら-1を返す
def binary_search(l, item):
    left = 0
    right = len(l) - 1
    while left <= right:
        mid  = (left + right) // 2
        if l[mid] == item:
            return mid
        elif l[mid] < item:
            left = mid + 1
        else:
            right = mid - 1
    return -1

for i in range(n):
    target_ind = binary_search(sorted_x, x_ls[i])
    if target_ind <= n // 2 - 1:
        ans = bigger
    else:
        ans = smaller
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Y = sorted(X)

Y_mid_left,Y_mid_right = Y[N//2-1],Y[N//2]

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

Submission status: Accepted

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

Submission status: Accepted

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

# 元のindexを保存
idx_dict = {}
for i in range(N):
    idx_dict[i] = l[i]

l.sort()
smaller_middle_idx = int(N / 2) - 1
bigger_middle_idx = int(N / 2)

for i in range(N):
    except_num = idx_dict[i] #今回取り除く数
    
    if l[smaller_middle_idx] == l[bigger_middle_idx]:
        print(l[smaller_middle_idx])

    elif except_num < l[bigger_middle_idx]:
        print(l[bigger_middle_idx])
    
    else:
        print(l[smaller_middle_idx])

Submission status: Accepted

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

sorted_a = sorted(a)

# 中央値を求める
med = [sorted_a[n // 2 - 1], sorted_a[n // 2]]


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

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int,input().split()))
y = x.copy()
y.sort()
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:
N = int(input())
X = list(map(int, input().split()))

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

indices = {(i + 1): x for i, (x, _) in enumerate(argsort)}

argsort = [[i, j] for j, [_, i], in enumerate(argsort)]
argsort.sort()

ranks = [j + 1 for _, j in argsort]

median = N // 2
for i in range(0, N):
    r = ranks[i]
    if r <= median:
        print(indices[median + 1])
    else:
        print(indices[median])

Submission status: Accepted

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

tmp = num_list.copy()
tmp.sort()

mid = tmp[n//2-1]
midu =  tmp[n//2]
for i in num_list:
    if i <= mid:
        print(midu)
    else:
        print(mid)

Submission status: Accepted

Solution code:
import copy

n = int(input())
x = list(map(int,input().split()))
key = {}
base = copy.deepcopy(x)
base.sort()

for i in range(n):

  if n//2 > i:
    ans = base[n//2]
  elif n//2 <= i:
    ans = base[n//2-1]
   
  if not ("key" + str(base[i]) in key):
    key["key" + str(base[i])] = ans
    
for i in range(n):
  print(key["key" + str(x[i])])

Submission status: Accepted

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

sort_x = sorted(X, key= lambda x: x)

mid_left = sort_x[N // 2 - 1]
mid_right = sort_x[N // 2]

for i in X:
    if i <= mid_left:
        print(mid_right)
    else:
        print(mid_left)

Submission status: Accepted

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

tmp = [0] * N
for i in range(N):
    tmp[i] = X[i]

tmp.sort()
mid_left = tmp[N // 2 - 1]
mid_right = tmp[N // 2]



for i in X:
    if i <= mid_left:
        print(mid_right)
    else:
        print(mid_left)

Submission status: Accepted

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

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

Submission status: Accepted

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

ansmed = ans[N//2]

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

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read

def main():
    N, *X = map(int, read().split())
    A = sorted(X)
    #if N%2 == 0:
    j = N//2 - 1
    Aj = A[j]; Aj1 = A[j+1]
    for i in range(N):
        if X[i] <= Aj:
            print(Aj1)
        else:
            print(Aj)
    #else:
    #    j = N//2 + 1
    #    A1j = A[j-1]; Aj = A[j]; Aj1 = A[j+1]
    #    for i in range(N):
    #        if X[i] <= A1j:
    #            print((Aj+Aj1)/2)
    #        elif X[i] == Aj:
    #            print((A1j+Aj1)/2)
    #        elif X[i] >= Aj1:
    #            print((A1j+Aj)/2)
    #        else:
    #            return
    #    

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
res = []
ind = {}
for i in range(n):
    res.append([a[i],i])
jun = [0]*n
res.sort()
for i in range(n):
    jun[res[i][1]] = i+1

#a[i]はjun[i]番目に大きいよ
ans = [0]*n
for i in range(n):
    if jun[i] <=n//2:ans[i]  = res[n//2][0]
    else:ans[i] = res[n//2-1][0]
print(*ans)

Submission status: Accepted

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

d = N // 2
dn = Xc[d]

for i in range(N):
    if X[i] < dn:
        print(Xc[d])
    else:
        print(Xc[d-1])

Submission status: Accepted

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

Xcmed = Xc[N//2]

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

Submission status: Accepted

Solution code:
import sys

n, *x = map(int, sys.stdin.read().split())

def main():
    a = sorted(x)
    l = a[n//2-1]; r = a[n//2]
    for i in range(n):
        print(l if x[i] >= r else r)

if __name__ ==  '__main__':
    main()