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(" ")))
x_s=sorted(x)
v1=x_s[int(len(x)/2)-1]
v2=x_s[int(len(x)/2)]
for i in x:
    if i>=v2:
        print(v1)
    else:
        print(v2)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
L = list(map(int, input().split()))
l = len(L)
L2 = sorted(L)
ans = (L2[l//2 - 1], L2[l//2])

if ans[0] == ans[1]:
    for n in range(N):
        print(ans[0])
else:
    for n in L:
        if n < ans[1]:
            print(ans[1])
        else:
            print(ans[0])

Submission status: Accepted

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

x_sort = sorted(x)
l_mid = x_sort[int(n/2)-1]
r_mid = x_sort[int(n/2)]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(raw_input())
x = map(int,raw_input().split())
x2 = sorted(x)

m1 = x2[n/2 - 1]
m2 = x2[n/2]

if m1 == m2:
  for a in range(n):
    print m1
  exit(0)

for a in x:
  if a <= m1:
    print m2
  else:
    print m1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
xs = list(map(int,input().split()))
sortxs = [i for i in xs]
sortxs.sort()
mins = sortxs[N//2-1]
majs = sortxs[N//2]
for i in range(N):
    t = xs[i]
    if t <= mins:
        print(majs)
    else:
        print(mins)

Submission status: Accepted

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

Xsort = sorted(X)
medR = Xsort[N//2]
medL = Xsort[N//2-1]

for i in X:
    if i < medR:
        print(medR)
    else:
        print(medL)

Submission status: Accepted

Solution code:
n=int(raw_input())
a=[int(k) for k in raw_input().split(" ")]

sa=sorted(a)
mn,mx=sa[n/2-1],sa[n/2]

for k in a:
    if k<=mn:
        print mx
    else:
        print mn

Submission status: Accepted

Solution code:
n=int(input())
x=[int(a) for a in input().split()]
sx = sorted(x)
a=sx[n//2-1]
b=sx[n//2]
for c in x:
    if c <=a:
        print(b)
    else:
        print(a)

Submission status: Accepted

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

Submission status: Runtime Error

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

def naive(x):
    return [median(x[:i] + x[i+1:]) for i in range(len(x))]
  
for i in naive(x):
  print(i)

Submission status: Runtime Error

Solution code:
// inputに入力データ全体が入る
function Main(input) {
	var line = input.split("\n");
	var N = Number(line[0]);
	var X = line[1].split(" ");

	var Y = X.slice().sort(function(a, b){
		return Number(a) - Number(b)
	});

	var median = [Number(Y[(N/2 - 1)]), Number(Y[N/2])];
	var ret = [];

	for(var i = 0; i < X.length; i++){
		if(median[1] <= Number(X[i])){
			console.log(median[0] + "\n");
		}else{
			console.log(median[1] + "\n");
		}
	}
	return 0;

}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Submission status: Runtime Error

Solution code:
fuckoff

Submission status: Runtime Error

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

for i in X:
  x = sorted(X)
  x.pop(i)
  print(x[n//2- 1])

Submission status: Runtime Error

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] >= x2[med1]:
		print(med2)
	else:
		print(med1)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def main():
    N = int(input().strip())
    X_list = [int(i) for i in input().strip().split()]
    sorted_x = sorted(X_list)

    left = sorted_x[(N // 2)-1]
    right = sorted_x[N // 2]
    for x in X_list:
        if X_list[x-1] <= left:
            print(right)
        else:
            print(left)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    N = int(input().strip())
    X_list = [int(i) for i in input().strip().split()]
    sorted_x = sorted(X_list)

    left = sorted_x[(N // 2)-1]
    right = sorted_x[N // 2]
    print(left, right)
    for x in X_list:
        if X_list[x-1] <= left:
            print(right)
        else:
            print(left)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def median():
    l = sorted(l)
    if len(l) % 2 == 1:
        return l[len(l) // 2]
    else:
        return (l[len(l) // 2] + l[(len(l) // 2) - 1]) // 2


def main():
    N = int(input().strip())
    X_list = [int(i) for i in input().strip().split()]
    num = 0
    sorted_x = sorted(X_list)

    left = sorted_x[N // 2 - 1]
    right = sorted_x[N // 2]
    for x in X_list:
        if X_list[x-1] >= right:
            print(right)
        else:
            print(left)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def median():
    l = sorted(l)
    if len(l) % 2 == 1:
        return l[len(l) // 2]
    else:
        return (l[len(l) // 2] + l[(len(l) // 2) - 1]) // 2


def main():
    N = int(input().strip())
    X_list = [int(i) for i in input().strip().split()]
    num = 0
    sorted_x = sorted(X_list)

    left = sorted_x[N // 2 - 1]
    right = sorted_x[N // 2 + 1]
    for x in X_list:
        idx = sorted_x.index(x)
        if idx >= N / 2:
            print(right)
        else:
            print(left)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = sorted(a)
    
    def seach(x):
        l = 0
        r = n - 1
        while True:
            i = (l + r) // 2
            if r - l <= 1:
                if b[r] == x:
                    return r
                else:
                    return l
            if b[i] < x:
                l = i
            elif f(i) > x:
                r = i
            else: 
                return i
    
    for i in range(n):
        j = seach(a[i])
        c = b[:j] + b[j+1:]
        print(c[n // 2 - 1])

        
if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import statistics
n = int(input())
x = list(map(int,input().split()))
a = x[:]
a.sort()
kijun = a[n//2]
a1 = a[n//2]
a2 = a[n//2-1]
for i in x:
	if i < kijun:
		print(a1)
	else:
		print(a2)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import copy
N=int(input())
X=list(map(int,input().split()))
d=[0]*(max(X))

for i in range(N):
  if d[X[i]-1]>0:
    print(d[X[i]-1])
  else:
    Y=copy.copy(X)
    Y.pop(i)
    Y.sort()
    ans = Y[(N-2)//2]
    print(ans)
    d[X[i]-1] = ans

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import copy
N = int(input())
X = list(map(int,input().split()))
length = len(X)
sortx = sorted(X)
bef = sortx[int(length//2)]
aft = sortx[int(length//2)+1]

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

Submission status: Runtime Error

Solution code:
import copy
N = int(input())
X = list(map(int,input().split()))
length = len(X)
sortx = sorted(X)
bef = sortx[int(length//2)]
aft = sortx[int(length//2)+1]

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

Submission status: Runtime Error

Solution code:
import copy
N = int(input())
X = list(map(int,input().split()))
length = len(X)
sortx = sorted(X)
bef = sortx[int(length/2)]
aft = sortx[int(length/2)+1]

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

Submission status: Runtime Error

Solution code:
import copy
N = int(input())
X = list(map(int,input().split()))
length = len(X)
X.sort()
bef = int(length/2)
aft = bef+1
for i in range(N):
    if(i<bef):
        print(X[bef])
    else:
        print(X[aft])

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
x = list(map(int,input().split()))
m = x
m.sort
k = m[n/2]
l = m[(n-2)/2]
for i in range(n):
  if(x[i]>l):
    pirnt(l)
  else:
    print(k)

Submission status: Runtime Error

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(Y[N//2+1])
  if X[i]>=l:
    print(Y[N//2-1])

Submission status: Runtime Error

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(Y[N//2+1])
  if x[i]>=l:
    print(Y[N//2-1])

Submission status: Runtime Error

Solution code:
n = int(input())
x = list(map(int,input().split()))
y = x.sorted()
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: Runtime Error

Solution code:
n = int(input())

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

from statistics import median

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

Submission status: Runtime Error

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

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 X <= left:
        print(right)
    else:
        print(left)

Submission status: Runtime Error

Solution code:
import copy
N = int(input())
Listx = list(map(int,input().split()))
Listxs = sorted(Listx)
A = Listxs[N//2]
B = Listxs[N//2-1]

for i in range(N):
    print(A if  B>= Listx[i] and else B)

Submission status: Runtime Error

Solution code:
n = int(input())
list = list(map(int, input().split()))
for i in range(len(list)):
  copy_list = list.copy()
  copy_list.pop(i)
  copy_list.sort()
  print(copy_list[n/2])

Submission status: Runtime Error

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

X_sort = sorted(X)

mid_r = X_sort[N//2]
mid_l = X_sort[N//2-1]

for i in range(N):
    if X[i] <= mid_l:
        print(mid_r)
    else:
        print(min_l)

Submission status: Runtime Error

Solution code:
import math

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

m = sum(li) / N

new = sorted(li)

for i in range(N):
  if i <= (N / 2) - 1
    print(new[math.floor(N/2)])
  else:
    print(new[math.floor(N/2) - 1])

Submission status: Runtime Error

Solution code:
n = int(input())
l = [int(input()) for i in range(n)]
l1=sorted(l)
a = l1[n//2]
b = l1[n//2+1]
if a == b:
  for i in range(n):
    print(a)
else:
  for i in l:
    if i <= a:
      print(b)
    else:
      print(a)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
package main

import (
  "fmt"
  "sort"
)

func main(){
  var N int
  fmt.Scan(&N)
  X := make([]int, N)
  for i:=0;i<N;i++{
    fmt.Scan(&X[i])
  }
  Y := make([]int,N)
  copy(Y,X)
  sort.Ints(X)
  // fmt.Println(X)
  // fmt.Println(Y)
  low := X[(N-1)/2]
  high := X[N/2]
  // fmt.Println(low,high)
  for i:=0;i<N;i++{
    if Y[i] <= low{
      fmt.Println(high)
    }else{
      fmt.Println(low)
    }
  }
}

Submission status: Runtime Error

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

li = sorted(a)
memo = li[n//2]

for i in range(n):
    if a[i] > memo:
        print(li[(n//2)]) 
    else:
        print(li[(n//2)+1])

Submission status: Runtime Error

Solution code:
n = int(input())
x = [int(i) for i in input().split()]
xs = sorted(x)
indices = [-1] * (max(x) + 1)
for i in range(n):
  if indices[xs[i]] == -1:
    indices[xs[i]] = i
for i in range(n):
  print(xs[n // 2 - int(indices[x[i]] >= n // 2)])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import copy

import numpy as np


def main():
    N = int(inpupt())
    X = np.array(list(map(int, input().split())))
    m = np.median(X)

    XX = copy.deepcopy(X)
    mm = np.argmin(X)
    XX = np.delete(XX, mm)
    m0 = np.median(XX)

    XX = copy.deepcopy(X)
    mm = np.argmax(X)
    XX = np.delete(XX, mm)
    m1 = np.median(XX)

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


main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
x=list(map(int,input().split()))
indices = [*range(len(x))]
index = sorted(indices, key=lambda i: x[i])
x.sort()
ans=[]
for i in range(n):
  if i < n//2:
    ans.append(x[(n//2)+1])
  else:
    ans.append(x[(n//2)-1])
for i in range(n):
  j=index.index(i)
  print(ans[j])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

//昇順
int asc(const void* a, const void* b){
    return *(int*)a-*(int*)b;
}

int main(void){
    int N;
    scanf("%d",&N);

    int* X;
    NEW(X,N);
    for(int i=0;i<N;i++){
        scanf("%d",&X[i]);
    }

    int* Y;
    NEW(Y,N);
    for(int i=0;i<N;i++) Y[i]=X[i];
    qsort(Y,N,sizeof(int),asc);

    for(int i=0;i<N;i++){
        if(X[i]>=Y[N/2]) printf("%d\n",Y[N/2-1]);
        else printf("%d\n",Y[N/2]);
    }

    return 0;
}

Submission status: Runtime Error

Solution code:
from bisect import bisect_left
N = int(input())
X = list(map(int,input().split()))
Y = X.copy()
Y.sort()
for i in range(N):
    k = bisect_left(Y,X[i])
    if k < N//2:
        print(Y[N//2])
    else:
        print(Y[N//2-1])

Submission status: Runtime Error

Solution code:
#import math
#import sys
#import bisect
#input = sys.stdin.readline
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return((a*b)//gcd(a,b))

def main():
    #x,y = map(int,input().split())	x=1,y=2
    #a = input().split()	a=['1','2','3',...,'n']
    #a = list(map(int,input().split()))	a=[1,2,3,4,5,...,n]
    #li = input().split('T')	FFFTFTTFF => li=['FFF', 'F', '', 'FF']
    n=int(input())
    a = list(map(int,input().split()))
    b=a.copy()
    for i in range(n):
        x=b[i]
        a.sort()
        if x<=a[(n//2)-1]:
            print(a[(n//2)])
        else:
            print(a[(n//2)-1])

main()

Submission status: Runtime Error

Solution code:
n = int(input())
x = list(map(int, input().split()))
y = sorted(set(x))
ms = y[len(y)//2-1]
mc = y[len(y)//2]
ml = y[len(y)//2+1]

#print(ms, mc, ml)

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

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 

signed main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int N; cin >>N;
    vector<int> X(N); cin >> X;
    vector<int> Xs(X);
    
    sort(all(Xs));

    int lhs = Xs[N/2-1], rhs = Xs[N/2];

    rep(i, N) {
        if (X[i] <= lhs) {
            cout << rhs << endl;
        } else {
            cout << lhs << endl;
        } 
    }
}

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#094c
N = int(input()) #N<200000=2 * 10**5
X_list = [int(e) for e in input().split()]

#l が奇数のとき，l 個の数 a1,a2,...,al の中央値とは，a1,a2,...,al の中で (l+1)/2番目に大きい値のことを言います．
#N個の数 X1,X2,...,XN が与えられます．ここで，N は偶数です． 
#i=1,2,...,N に対して，X1,X2,...,XN から Xi のみを除いたもの，すなわち X1,X2,...,Xi−1,Xi+1,...,XN の中央値を Biとします．
#i=1,2,...,Nに対して，Bi を求めてください．

X_list.sort(reverse=False)
print(X_list)
Bi_smaller = X_list[int(len(X_list)/2)]
Bi_bigger = X_list[int(len(X_list)/2 +1)]

for i in range(int(N/2)):
    print(Bi_bigger)
    
for i in range(int(N/2),N):
    print(Bi_smaller)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map((int,input.split())))
c = int(n / 2)
b = list(a)
for j in range(1,c):
    M = max(b)
    m= min(b)
    b.remove(M)
    b.remove(m)
ML = min(b)
MR = max(b)
for i in range(0,n):
    if a[i] > MR:
        print(ML)
    else:
        print(MR)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map((int,input.split()))
c = int(n / 2)
b = list(a)
for j in range(1,c):
    M = max(b)
    m= min(b)
    b.remove(M)
    b.remove(m)
ML = min(b)
MR = max(b)
for i in range(0,n):
    if a[i] > MR:
        print(ML)
    else:
        print(MR)

Submission status: Runtime Error

Solution code:
N=int(input())
X=[int(i) for i in input().split()
Y=sorted(X)
MidL=X[N//2-1]#ちっちゃいほう(変化なしの場合)
MidR=X[N//2]#でかいほう(下が減った場合)
for y in Y:
	if >=MidR:print(MidL)
	else:print(MidR)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import statistics
import math

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

for i in range(n):
  tmp = x
  print(statistics.median(x.pop(i)))

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    x = sorted([(int(input()), i) for i in range(N)])
    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])

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import collections
import numpy as np

n=int(input())
x=np.array([int(item) for item in input().split()])
x_sorted=np.sort(x)

for i in range(n):
  if i==0 and x[0]==x[1]:
    print(x_sorted[n//2-1])
  elif i==n-1 and x[n-1]==x[n-2]:
    print(x_sorted[n//2-1])
  elif x[i]==x[i-1] or x[i]==x[i+1]:
    print(x_sorted[n//2-1])
    
  else:
    ind=np.ones(n,dtype=bool)
    ind[np.searchsorted(x_sorted,x[i])]=False
    print(x_sorted[ind][n//2-1])

Submission status: Runtime Error

Solution code:
from statistics import median
n = int(input())
x = list(map(int,input().split()))
i1 = x.index(max(x))
i2 = x.index(min(x))
m1 = median(x[0:i1]+x[i1+1:n])
m2 = median(x[0:i2]+x[i2+1:n])
for i in range(n):
    if m2 == m1:
        print(m1)
    else:
        if x[i]<m2:
            print(m2)
        if x[i]>m1:
            print(m1)

Submission status: Runtime Error

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

print(min(sum(li[:x]), sum(li[x+1:])))

Submission status: Runtime Error

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

num=[i+1 for i in range(N)]
l=zip(num,X)
l=sorted(l,key=lambda x:x[1])
indexlist=[]
for i in range(N):
    indexlist.append(l[i][0])
for i in range(N):
    x=indexlist.index(i+1)
    if x<=N//2-1:
        ans=l[N//2][1]
    else:
        ans=l[N//2-1][1]
    print(ans)

Submission status: Runtime Error

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

_sum = sum(X)
buff_x = X.copy()


X.sort()
mm = X[N//2-1]
mx = X[N//2]
for i in range(N):
    if buff_x[i] < mx:
        print(mx)
    else:
        print(mm)

Submission status: Runtime Error

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

Y=sorted(X)

a1=Y[N//2]
a2=Y[N//2-1]

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

Submission status: Runtime Error

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

Y=sorted(X)

a1=Y[N//2]
a2=Y[N//2-1]

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input()))
for i in range(n//2):
  print(a[n//2+1])
for i in range(n//2):
  print(a[n//2])

Submission status: Runtime Error

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

m = N // 2

for x in (a[m], a[m-1]):
  for i in range(m):
    print(x)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:


def main():
    num = int(input())
    data = list(map(int, input().split()))
    data_kari = data.copy()
    data_kari.sort()
    # print(data_kari)
    min_chuou = data_kari[(num // 2) - 1]
    max_chuou = data_kari[num // 2]

    # print(min_chuou, max_chuou)

    # print(data)

    for i in range(num):
        if data[i] <= min_chuou:
            print(max_chuou)
        elif data[i] >= max_chuou:
            print(min_chuou)






if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from collections import defaultdict
import math


def kari():
    map(int, input().split())
    list(map(int, input().split()))
    math.ceil()

def main():
    num = int(input())
    data = list(map(int, input().split()))
    data_kari = data.copy()
    data_kari.sort()
    # print(data_kari)
    min_chuou = data_kari[(num // 2) - 1]
    max_chuou = data_kari[num // 2]

    # print(min_chuou, max_chuou)

    # print(data)

    for i in range(num):
        if data[i] <= min_chuou:
            print(max_chuou)
        elif data[i] >= max_chuou:
            print(min_chuou)






if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

for x in X:
    Y.remove(x)
    print(Y[N//2-1])
    Y.append(x)
    Y.sort()

Submission status: Runtime Error

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

for i in range(N):
    Y.remove(x)
    print(Y[N//2-1])
    Y.append(x)
    Y.sort()

Submission status: Runtime Error

Solution code:
sorted_X = sorted(X)
left, right = sorted_X[N // 2 - 1], sorted_X[N // 2]

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

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = tuple(a)
a.sort()
A1 = a[N//2-1]
A2 = a[N//2]
med = (A1+A2)/2
for i in range(N):
    if b[i] <= med:
        print(A2)
    else:
        print(A1)

Submission status: Runtime Error

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

small = L[N//2]
large = L[N//2+1]

for i in X:
    if i <= small:
        print(large)
    else:
        print(small)

Submission status: Runtime Error

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: Runtime Error

Solution code:
n = int(input())

a = list(map(int,input().split()))
for i in range(n):
    a[i].append(i)

a.sort()

n = a[n//2-1][0]
m = a[n//2][0]
for i in range(n):
    a[i].append(i)

a.sort(key = lambda x:x[1])

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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



a = statistics.median(sorted(x)[0:len(x)-1])
b = statistics.median(sorted(x)[1:len(x)])
for i in x:
    if i > a:
        print(a)
    else:
        print(b)

Submission status: Runtime Error

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

for i in x:
    if i > statistics.median(sorted(x)[0:len(x)-1]):
        print(statistics.median(sorted(x)[0:len(x)-1]))
    else:
        print(statistics.median(sorted(x)[1:len(x)]))

Submission status: Runtime Error

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

for i in X:
    new_X=X.copy()
    new_X.remove(i)
    print(sorted(new_X)[(Nß-1)//2])

Submission status: Runtime Error

Solution code:
n = int(input())
X=[i for i in map(int,input().split())]
 
for i in X:
    news_X=X.copy()
    news_X.remove(i)
    print(sorted(lst)[(n-1)//2])

Submission status: Runtime Error

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

for i in X:
    news_X=X.copy()
    news_X.remove(i)
    print(sorted(lst)[(n-1)//2])ß

Submission status: Runtime Error

Solution code:
n = int(input())
x = list(map(int, input().split()))
y = list(x)
y.sort()
if n % 2 != 0:
    a,b,c = y[n//2-1],y[n//2],y[n//2+1]
    m = b
else:
    a,b = y[n//2-1],y[n//2]    
    m = (a+b)/2
for i in range(n):
    if x[i] < m :
        if n%2==0:
            tm = b
        else:
            tm = (b+c)/2
    if i == n//2:
        if n%2==0:
            tm = a
        else:
            tm = (a+c)/2
    if x[i] > m:
        if n%2==0:
            tm = a
        else:
            tm = (a+b)/2
    print(int(tm))