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:
N=int(input())
X=list(map(int,input().split()))
Y=sorted(X)
l,r=Y[N//2-1],Y[N//2]
for i in X:
    if l < i:
        print(l)
    else:
        print(r)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
X = list(map(int, input().split()))
XI = [[X[i], i] for i in range(N)]
XI.sort()
A = [0]*N
for k in range(N):
  x, i = XI[k]
  if k < N//2:
    A[i] = XI[N//2][0]
  else:
    A[i] = XI[N//2 - 1][0]
for a in A:
  print(a)

Submission status: Accepted

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

mid1 = X_sort[n//2 - 1]
mid2 = X_sort[n//2]

for x in X:
    if x <= mid1:
        print(mid2)
    else:
        print(mid1)

Submission status: Accepted

Solution code:
n = int(input())
if n == 2:
  a, b = map(str,input().split())
  print(b + " " + a)
else:
  L = list(map(int, input().split()))
  M = sorted(L)
  c = (n + 1) // 2 - 1
  a = M[c + 1]
  b = M[c]
  for l in L:
    if l> b:
      print(b)
    else:
      print(a)

Submission status: Accepted

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

lis = sorted(x)
median = lis[int(n/2)]
median2 = lis[int((n-2)/2)]

for i in range(n):
    if x[i] < median:
        print(median)
    else:
        print(median2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n=int(input())
    x=list(map(int,input().split()))
    sx = sorted(x)
    lx = len(x)//2
    m = sx[lx]
    _m = sx[lx-1] if 0 < m-1 else sx[0]
    for i in x:
        print(m if i<m else _m)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n, *x = map(int, open(0).read().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)

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]

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

Submission status: Accepted

Solution code:
from statistics import *
N = int(input())
X = list(map(int,input().split()))
Y = sorted(X)
m = median(X)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

x_sort = sorted(x[:])
a,b = x_sort[n//2 - 1], x_sort[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()))
_X = sorted(X)
m = N // 2
for x in X:
    if x >= _X[m]:
        print(_X[m - 1])
    else:
        print(_X[m])

Submission status: Accepted

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

x = [(j, i) for i, j in enumerate(x)]
x.sort(key=itemgetter(0))
medi1 = x[len(x)//2][0]
medi2 = x[len(x)//2-1][0]
ans = [0]*n
for i in range(len(x)):
    if i<len(x)//2:
        ans[x[i][1]] = medi1
    else:
        ans[x[i][1]] = medi2

for a in ans:
    print(a)

Submission status: Accepted

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

sor = sorted(X)
l = sor[N//2-1]
r = sor[N//2]
for i in range(0,N,1):
    print(l if X[i]>=r else r)

Submission status: Accepted

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

alpha=Y[N//2-1]
beta=Y[N//2]

S=[0]*N
for k in range(N):
    x=X[k]
    if x<=alpha:
        S[k]=beta
    else:
        S[k]=alpha

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

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

A = sorted(X)

med1 = A[N // 2 - 1] 
med2 = A[N // 2]

for i, x in enumerate(X):
    if x <= med1:
        print(med2)
    else:
        print(med1)

Submission status: Accepted

Solution code:
N = int(input())
X = [int(T) for T in input().split()]
SortX = sorted(X)
MedL = SortX[(N//2)-1]
MedR = SortX[(N//2)]
Disp = [0]*N
for T in range(0,N):
    if X[T]<=MedL:
        Disp[T] = str(MedR)
    else:
        Disp[T] = str(MedL)
print('\n'.join(Disp))

Submission status: Accepted

Solution code:
N = int(input())
X = [int(T) for T in input().split()]
SortX = sorted(X)
MedL  = SortX[(N//2)-1]
MedR  = SortX[(N//2)]
if MedL==MedR:
    Disp = [str(MedL)]*N
    print('\n'.join(Disp))
else:
    Disp = [0]*N
    for T in range(0,N):
        if X[T] <=MedL:
            Disp[T] = str(MedR)
        else:
            Disp[T] = str(MedL)
    print('\n'.join(Disp))

Submission status: Accepted

Solution code:
import math
import statistics
n = int(input())
x = [int(i) for i in input().split()]

x_sorted = sorted(x)
lower_med = statistics.median(x_sorted[1:])
upper_med = statistics.median(x_sorted[:len(x)-1])

median = statistics.median(x)

for i in range(n):
    if x[i] < median:
        print(lower_med)
    else:
        print(upper_med)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect

N = int(input())
X = list(int(x) for x in input().split())
Y = sorted(X)
m1 = Y[N//2-1]
m2 = Y[N//2]

for x in X:
    if bisect.bisect_left(Y, x) > N//2-1:
        print(m1)
    else:
        print(m2)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect

sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


N = z()
X = zz()
orig_X = X[:]
index = list(range(N))
# print(X, index)
X, index = zip(*sorted(zip(X, index)))

# print(X, index)
small_median = X[N//2 - 1]
big_median = X[N//2]

# print("small_median", small_median)
# print('big_median', big_median)
for i in range(N):
    if(orig_X[i] > small_median):
        pass
        print(small_median)
    else:
        pass
        print(big_median)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
X = LI()

X_sort = sorted(X)
# X.sort()

mid = X_sort[N // 2]

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n = int(input())
    b = [int(x) for x in input().split()]
    a = []
    for i in range(n):
        a.append((b[i], i))
    a.sort()
    ans = [0] * n
    m = n // 2


    for i in range(n):
        j = a[i][1]
        if i < m:
            ans[j] = (a[m][0])
        else:
            ans[j] = (a[m-1][0])

    for e in ans:
        print(e)


t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

2 3 4 4
3 4 4
2 3 4
2 3 4
2 4 4


"""

Submission status: Accepted

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

als = list(sorted(al))

x = als[n//2]
y = als[n//2-1]

for i in range(n):
    z = al[i]
    if z <=y:
        print(x)
    else:
        print(y)

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    N = int(input())
    Xs = [int(item) for item in input().split()]

    sorted_xs = sorted(Xs)

    for item in Xs:
        if item <= sorted_xs[(N-1)//2]:
            print(sorted_xs[N//2])
        else:
            print(sorted_xs[(N-1)//2])

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

sortX = sorted(X)
#%%
lB = sortX[n//2-1]
rB = sortX[n//2]

for x in X:
    if x <= lB:
        print(rB)
    else:
        print(lB)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[25]:


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


# In[26]:


x1 = sorted(X)[N//2-1]
x2 = sorted(X)[N//2]
for i in range(N):
    if X[i] >= x2:
        print(x1)
    else:
        print(x2)


# In[ ]:

Submission status: Accepted

Solution code:
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n = readInt()
t = readInts()
x = []
for i in range(n):
	x.append([i,t[i]])
x = sorted(x, key=lambda x: x[1])
ans = [-1]*n
for i in range(len(x)):
	if i<n//2:
		ans[x[i][0]]=x[n//2][1]
	else:
		ans[x[i][0]]=x[n//2-1][1]

for i in ans:
	print(i,end=" ")

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from copy import deepcopy

def main():
    n, *x = map(int, read().split())
    if n == 2:
        print(x[1])
        print(x[0])
        sys.exit()

    x2 = deepcopy(x)
    x2.sort()
    r1 = x2[n//2-1]
    r2 = x2[n//2]
    for xe in x:
        if xe > r1:
            print(r1)
        else:
            print(r2)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

l = sorted(x)
m1 = l[(n-1)//2]
m2 = l[(n-1)//2+1]
for i in x:
  if i <= m1: print(m2)
  else: print(m1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
X=list(map(int,input().split()))
Z=sorted(X)
left=Z[N//2-1]
right=Z[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()))
xs = sorted(x)

default = (n+1)//2

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

Submission status: Accepted

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

X_dict={}
X_=X.copy()
X_.sort()
for x_idx,x in enumerate(X_):
    X_dict[x]=x_idx

median_idx = N//2-1
for x in X:
#     print('=====')
#     print(x)
    x_sort_idx=X_dict[x]
    if median_idx < x_sort_idx:
        ans = X_[median_idx]
    else:
        ans = X_[median_idx+1]
    print(ans)

Submission status: Accepted

Solution code:
import copy
N = int(input())
X = list(map(int, input().split()))
x = copy.copy(X)
x.sort()
left = x[N//2-1]
right = x[N//2]

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

Submission status: Accepted

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

y = sorted(X)

a = y[N//2-1]
b = y[N//2]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
x = list(map(int, input().split()))
pivot = n // 2
l = []
for i in range(n):
    l.append([x[i], i])
l.sort()
r = []
for i in range(n):
    l[i].append(i)
    l[i] = l[i][1:]
    r.append([l[i][1], l[i][0]])
d1 = dict(l)
d2 = dict(r)
for i in range(n):
    if d1[i] >= pivot:
        print(x[d2[pivot-1]])
    else:
        print(x[d2[pivot]])

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

a=n//2
p=sorted_lst[a-1]
q=sorted_lst[a]

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

Submission status: Accepted

Solution code:
n = int(input())
x_1 = list(map(int, input().split()))
x_2 = sorted(x_1)
median_1 = x_2[n//2-1]
median_2 = x_2[n//2]
for v in x_1:
    if v <= median_1:
        print(median_2)
    else:
        print(median_1)

Submission status: Accepted

Solution code:
n = int(input())
X = list(int(x) for x in input().split())
Y = sorted(X)
mid1 = Y[(n//2)-1]
mid2 = Y[n//2]
for x in X:
    if x <= mid1:
        print(mid2)
    else:
        print(mid1)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

N = int(input())
X =list(map(int,input().split()))
sX = sorted(X)
med_s = sX[((N-1)+1)//2-1]
med_b = sX[((N-1)+1)//2]
ave_med = (med_s+med_b)/2

for i in range(N):
    if X[i] <= ave_med:
        print(med_b)
    else:
        print(med_s)

Submission status: Accepted

Solution code:
import sys
from bisect import bisect_left
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    X = list(map(int, input().split()))
    Y = [(x, i) for i, x in enumerate(X)]
    Y.sort()

    for i, x in enumerate(X):
        idx = bisect_left(Y, (x, i))
        if idx < N // 2:
            print(Y[N//2][0])
        else:
            print(Y[N//2-1][0])


if __name__ == "__main__":
    main()

Submission status: Accepted

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

m = (n-1)//2
l = sorted(x)
for i in x:
  if i > l[m]: print(l[m])
  else: print(l[m+1])

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N = in_n()
    X = in_nl()
    X = [(num, i) for i, num in enumerate(X)]

    ans = [0] * N
    X.sort()
    for i in range(N):
        _, j = X[i]
        if i < N // 2:
            ans[j] = X[N // 2][0]
        else:
            ans[j] = X[N // 2 - 1][0]

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
x = [int(i) for i in input().split()]
y = sorted(x)
a = y[n // 2 - 1]
b = y[n // 2]
for i in x:
  if i <= a:
    print(b)
  elif i >= b:
    print(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy
n = int(input())
lst = list(map(int, input().split()))
clst = sorted(copy.deepcopy(lst))
lmed = clst[n // 2 - 1]
rmed = clst[n // 2]
for i in range(n):
  if lst[i] <= lmed:
    print(rmed)
  else:
    print(lmed)

Submission status: Accepted

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

newx=sorted(x)

lower_med=newx[n//2-1]
higher_med=newx[n//2]

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

Submission status: Accepted

Solution code:
import bisect,copy,heapq,itertools,string
from collections import *
from math import *
import sys
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
x = LIST()
y = sorted(x)

b0 = y[n//2-1]
b1 = y[n//2]
for a in x:
  if a<=b0:
    print(b1)
  else:
    print(b0)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    xs = list(map(int, input().split()))
    xs_sorted = sorted(xs)
    mid_n2, mid_n1 = (n+1)//2, (n-1)//2
    for x in xs:
        if x == xs_sorted[mid_n1]:
            print(xs_sorted[mid_n2])
        elif x == xs_sorted[mid_n2]:
            print(xs_sorted[mid_n1])
        elif x < xs_sorted[mid_n1]:
            print(xs_sorted[mid_n2])
        else:
            print(xs_sorted[mid_n1])


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import bisect
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


n = I()
x = LI()
sx = [(i, x[i]) for i in range(n)]
sx = sorted(sx, key=lambda a: a[1])
mid_l = sx[n // 2 - 1][1]
mid_r = sx[n // 2][1]
# print(mid_l, mid_r)
sx = [(sx[i][0], i, sx[i][1]) for i in range(n)]
sx = sorted(sx, key=lambda a: a[0])
# print(sx)
for _, sort_i, elem in sx:
    if sort_i < n // 2:
        print(mid_r)
    else:
        print(mid_l)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
b = sorted(a)
mi = b[n//2-1]
ma = b[n//2]
for x in a:
    print(ma if x <= mi else mi)

Submission status: Accepted

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

smaller = sort_x[n//2-1]
bigger = sort_x[n//2]

for x in X:
    if x <= smaller:
        print(bigger)
    else:
        print(smaller)

Submission status: Accepted

Solution code:
import sys
# from collections import defaultdict, deque
# import math
# import copy
from bisect import bisect_left, bisect_right
# import heapq

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 1000000007

def solve():
    n = getN()
    nums = getList()
    
    b1, b2 = sorted(nums)[n//2 - 1], sorted(nums)[n//2]
    for i, num in enumerate(nums):
        if num <= b1:
            print(b2)
        else:
            print(b1)
def main():
    n = getN()
    for _ in range(n):
        solve()
if __name__ == "__main__":
    # main()
    solve()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
Xs = list(mapint())
cX = Xs[:]
cX.sort()

lm = cX[N//2-1]
rm = cX[N//2]

for x in Xs:
    if x<=lm:
        print(rm)
    else:
        print(lm)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

mr=Y[N//2]
ml=Y[N//2-1]

for x in X:
    if mr<=x:
        print(ml)
    else:
        print(mr)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = [[A[i],i] for i in range(N)]
d = {}
B.sort()
for i in range(N):
    d[B[i][1]] = i
for i in range(N):
    if d[i] <N//2:
        print(B[N//2][0])
    else:
        print(B[-1+(N//2)][0])

Submission status: Accepted

Solution code:
import math
n = int(input())

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

nlis = sorted(lis)

med1 = nlis[n//2-1]
med2 = nlis[n//2]

for i in lis:
    if i <= med1:
        print(med2)
    else:
        print(med1)

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N = i()
X = l()
x = sorted(X)
l = x[N//2-1]
u = x[N//2]
for i in range(N):
    if X[i] >= u:
        print(l)
    else:
        print(u)

Submission status: Accepted

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

# 偶数この時のlen(L) // 2のとlen(L)-1のどちらかのみ中央値になる
len_X_first = len(X) // 2 - 1
len_X_second = len(X) // 2

for i in X:
    if (L[len_X_first] >= i):
        print(L[len_X_second])
    elif (L[len_X_second] <= i):
        print(L[len_X_first])

Submission status: Accepted

Solution code:
import copy
N=int(input())
X=list(map(int,input().split()))
B=[]
P=copy.copy(X)
X.sort()
a=X[N//2-1]
b=X[N//2]
for i in range(N):
  if P[i]<=a:
    B.append(b)
  else:
    B.append(a)
for j in range(N):
  print(B[j])

Submission status: Accepted

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

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

Submission status: Accepted

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

ind = [i for i in range(N)]
# XのindexをXが昇順になるように並び替える
ind = sorted(ind, key = lambda i : X[i])
ans = [0] * N
for i in range(N // 2):
    ans[ind[i]] = X[ind[N // 2]]
for i in range(N // 2, N):
    ans[ind[i]] = X[ind[N // 2 - 1]]

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

Submission status: Accepted

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

Submission status: Accepted

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

M=sorted(L)
a=M[n//2]
b=M[n//2-1]

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

Submission status: Accepted

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

Y = sorted(X)
m = Y[N//2 - 1]
M = Y[N//2]

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

Submission status: Accepted

Solution code:
import statistics

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

small = statistics.median_low(xl)
big = statistics.median_high(xl)
#print(small,big)
for i in range(N):
    if xl[i] <= small:
        print(big)
    else:
        print(small)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

x2=sorted(x)
mid_left = x2[n // 2 - 1]
mid_right = x2[n // 2]

for v in x:
    if v <= mid_left:
        print(mid_right)
    else:
        print(mid_left)

Submission status: Accepted

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

y=copy.copy(x)
y.sort()

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

A=sorted(a)

m1=A[n//2 -1]
m2=A[n//2]
for i in range(n):
    if a[i]<=m1:
        print(m2)
    else:
        print(m1)

Submission status: Accepted

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

Submission status: Accepted

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

# check
l, r = N // 2 - 1, N // 2
sort_x = sorted(X)
lx, rx = sort_x[l], sort_x[r]

if lx == rx:
    for i in range(N):
        print(lx)
else:
    for ind in range(N):
        target = X[ind]
        if target <= lx:
            print(rx)
        if target >= rx:
            print(lx)

Submission status: Accepted

Solution code:
import copy

N = int(input())

x = list(map(int,input().split()))
sort_x = copy.copy(x)
sort_x.sort()

center_num = (N-1) // 2

for l in x:
    if l <= sort_x[center_num]:
        print(sort_x[center_num+1])
    else:
        print(sort_x[center_num])

Submission status: Accepted

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

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


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

    N = ii()
    X = il()
    S = sorted(X)
    l = S[N // 2 - 1]
    r = S[N // 2]
    for x in X:
        if x <= l:
            print(r)
        else:
            print(l)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import copy

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

y = copy.copy(x)
x.sort()
num1 = x[n//2-1]
num2 = x[n//2]

for i in y:
  if i <= num1:
    print(num2)
  else:
    print(num1)

Submission status: Accepted

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