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: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a = int(input())
ar = list(map(int,input().split(" ")))
br = sorted(ar)
j = a // 2
if a == 2:
    for r in ar:
        if ar.index(r) == 0:
            print(ar[1])
            print(ar[0])
            exit()
        else:
            print(ar[0])
            print(ar[1])
            exit()
for r in ar:
    if br.index(r) < j:
        print(br[j-1])
    else:
        print(br[j])
print(br)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
x = list(map(int,input().split()))
r = sorted(x)
median = r[(n+1)//2]
median_2 = r[max(0,((n+1)//2) - 1)]
median_3 = r[min(n-1,((n+1)//2) + 1)]
for i in range(n):
    if x[i] == median:
        if x.index(median) <= i:
            print(median_2)
        else:
            print(median_3)
    else:
        print(median)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

sys.setrecursionlimit(10 ** 8)

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

Submission status: Wrong Answer

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

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

sys.setrecursionlimit(10 ** 8)

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

Submission status: Wrong Answer

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

x2.sort()

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

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

Submission status: Wrong Answer

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

x2.sort()

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

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

Submission status: Wrong Answer

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

X.sort()

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
def find(A):
    X=[(A[i],i) for i in range(len(A))]
    X=sorted(X)
    ans=[0]*len(X)
    p1=(len(A)-1)//2
    p2=len(A)//2
    for i in range(len(X)):
        a,b=X[i]
        if i<p2:
            ans[b]=A[p2]
        else:
            ans[b]=A[p1]
    return ans
input()
A=[str(x) for x in find(list(map(int,input().strip().split(" "))))]
print("\n".join(A))

Submission status: Wrong Answer

Solution code:
def find(A):
    X=[(A[i],i) for i in range(len(A))]
    X=sorted(X)
    ans=[0]*len(X)
    p1=(len(A)-1)//2
    p2=len(A)//2
    for i in range(len(X)):
        a,b=X[i]
        if i<p2:
            ans[b]=A[p2]
        else:
            ans[b]=A[p1]
    return ans
A=[str(x) for x in find(list(map(int,input().strip().split(" "))))]
print("\n".join(A))

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce
from bisect import*
def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

n,*a=map(int,open(0).read().split())
a.sort()
b=a.pop()
#print(a)
if n>10:
    x=bisect_left(a,b//2)
    if x>=n-1:
        print(b,a.pop())
    else:
        z=[cmb(b,a[i])for i in range(x-2,x+1)]
        y=max(z)
        print(b,a[x+z.index(y)-1])
elif n==2:
    print(b,*a)
else:
    z=[cmb(b,a[i])for i in range(n-1)]
    y=a[z.index(max(z))]
    print(b,y)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from numpy import median
n = int(input())
x = list(map(int, input().split()))
print(x)

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from numpy import median
n = int(input())
x = list(map(int, input().split()))
print(x)

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
X=list(map(int,input().split()))
Y=sorted(X)
a=Y[N//2]
b=Y[N//2-1]
for i in range(N):
    if X[i]<=b:
        print(a)
        break
    else:
        print(b)
        break

Submission status: Wrong Answer

Solution code:
N = int(input())

a = list(map(int,input().split(' ')))

sorted_a = sorted(a)

if N > 2:
    for i in range(int(N/2)):
        print(sorted_a[int(N/2)])
    for i in range(int(N/2)):
        print(sorted_a[int(N/2)-1])
else:
    print(a[0])

Submission status: Wrong Answer

Solution code:
N = int(input())

a = list(map(int,input().split(' ')))

sorted_a = sorted(a)


for i in range(int(N/2)):
    print(sorted_a[int(N/2)])
for i in range(int(N/2)):
    print(sorted_a[int(N/2)-1])

Submission status: Wrong Answer

Solution code:
N = int(input())

a = list(map(int,input().split(' ')))

sorted_a = sorted(a)

for i in range(int(N/2)):
    print(sorted_a[int(N/2)-1])

for i in range(int(N/2)):
    print(sorted_a[int(N/2)])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
b = [int(i) for i in input().split()]
b.sort()
s = b[(N-1)//2]
l = b[N//2]

for i in range(N):
    if i > s:
       print(s)
    else:
       print(l)

Submission status: Wrong Answer

Solution code:
N = int(input())
b = [int(i) for i in input().split()]
b.sort()
s  = b[len(b)//2 - 1]
l  = b[len(b)//2]

for i in range(N):
    if i > len(b)//2-1:
       print(s)
    else:
       print(l)

Submission status: Wrong Answer

Solution code:
N = int(input())
b = [int(i) for i in input().split()]
b.sort()
s  = b[len(b)//2 - 1]
l  = b[len(b)//2]

for i in range(N):
    if i > len(b)//2:
       print(s)
    else:
       print(l)

Submission status: Wrong Answer

Solution code:
N = int(input())
b = [int(i) for i in input().split()]
b.sort()
s  = b[len(b)//2 - 1]
l  = b[len(b)//2]

for i in range(N):
    if s > i:
       print(s)
    else:
       print(l)

Submission status: Wrong Answer

Solution code:
N = int(input())
b = input()

for i in range(N):
    X = b.split(" ")
    X.pop(i)
    X.sort()
    print(X[len(X)//2])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())

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

a.sort()

a_max = a[N - 1]

ave = a_max / 2


dif = 1000000000
difidx = -1
difidx2 = -1
p = 1
s = 1


for i in range(N):
    an = abs(a[i] - ave)
    if dif > an:
        dif = an
        difidx = i
    elif dif == an:
        difidx2 = i

ans = a[difidx2] if difidx2 > 0 else a[difidx]
ans2 = str(a_max)
if N > 3:
    print(str(a_max) + " " + str(ans))
else:
    if a[0] > a[1]:
        print(str(a[0]) + " " + str(a[1]))
    else:
        print(str(a[1]) + " " + str(a[0]))

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())

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

a.sort()

a_max = a[N - 1]

ave = int(a_max / 2)


dif = 1000000000
difidx = -1
difidx2 = -1
p = 1
s = 1


for i in range(N):
    an = abs(a[i] - ave)
    if dif > an:
        dif = an
        difidx = i
    elif dif == an:
        difidx2 = i

ans = a[difidx] if a[difidx] > a[difidx2] else a[difidx2]
if N > 3:
    print(str(a_max) + " " + str(ans))
else:
    print(str(a[0]) + " " + str(a[1]))

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())

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

a.sort()

a_max = a[N - 1]

ave = int(a_max / 2)


dif = 1000000000
difidx = -1
difidx2 = -1
p = 1
s = 1


for i in range(N):
    an = abs(a[i] - ave)
    if dif > an:
        dif = an
        difidx = i
    elif dif == an:
        difidx2 = i

ans = a[difidx] if a[difidx] > a[difidx2] else a[difidx2]
print(str(a_max) + " " + str(ans))

Submission status: Wrong Answer

Solution code:
from statistics import median_high

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

for r in (median_high(list(set(Xarr) - set([X])))for X in Xarr):
    print(r)

Submission status: Wrong Answer

Solution code:
n = int(input())
line = input().split(' ')
a = []
for element in line:
    a.append(int(element))

maxVal = max(a)
closestVal = a[0]
for x in a:
    if abs(x-maxVal/2) < abs(closestVal-maxVal/2):
        closestVal = x

print (maxVal, closestVal)

Submission status: Wrong Answer

Solution code:
N = int(input())
N_d = int(N/2)
X1 = list(map(int,input().split()))
X = X1[:]
X1.sort()

def getMed(i):
  if i  < X[N_d]:
    print(X[N_d])
  else:
    print( X[N_d -1])

for i in X:
  getMed(i)

Submission status: Wrong Answer

Solution code:
n = int(input())

a = input().split()

a = [int(x) for x in a]

am = max(a)
ai = 0
r = abs(a[0] - (am/2)) 

for i in range(n):
    if r >= abs(a[i]-(am/2)):
        r = abs(a[i]-(am/2))
        ai = a[i]
        
print("{0} {1}".format(am,ai))

Submission status: Wrong Answer

Solution code:
import copy

n = int(input())
line = input().split(' ')
x = []
for element in line:
    x.append(element)

for i in range(len(x)):
    temp = copy.deepcopy(x)
    del temp[i]
    temp.sort()
    print (temp[int(len(temp)/2)])

Submission status: Wrong Answer

Solution code:
import copy

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

Y = copy.deepcopy(X)
Y.sort()

largeMedian = Y[int(N / 2)]
smallMedian = Y[int(N / 2)-1]


print(X)
print(Y)
print(smallMedian)
print(largeMedian)

for i in range(N):
    if X[i] <= smallMedian:
        X[i] = largeMedian
    else:
        X[i] = smallMedian

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

Submission status: Wrong Answer

Solution code:
import copy

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

Y = copy.deepcopy(X)
Y.sort()

largeMedian = Y[int(N / 2)]
smallMedian = Y[int(N / 2)-1]


print(X)
print(Y)
print(smallMedian)
print(largeMedian)

for i in range(N):
    if X[i] <= smallMedian:
        X[i] = largeMedian
    else:
        X[i] = smallMedian

for i in range(N):
    print(X[i], end=' ')

Submission status: Wrong Answer

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

x = n // 2

a_ = sorted(a)

for i in range(n):    
    if a[i] != a_[x]:
        print(a_[x])
    else:
        print(a_[x-1])

Submission status: Wrong Answer

Solution code:
n = int(input())
x = [int(a) for a in input().split()]
sorted_x = sorted(x)
print(x)
print(sorted_x)
for elem in x:
    if elem >= sorted_x[(len(x) + 1) // 2]:
        print(sorted_x[(len(x) + 1) // 2 - 1])
    else:
        print(sorted_x[(len(x) + 1) // 2])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
i = max(a)
a.remove(i)
j = min(a, key=lambda x: abs(i-x*2))
print(i, j)

Submission status: Wrong Answer

Solution code:
N = int(input())
x=[]
for i in range(N):
    x.append([i,0])
y = list(map(int, input().split()))

for i in range(N):
    x[i][1]=y[i]



x.sort(key=lambda a:a[1])
tmp1=x[int(N/2)-1]
tmp2=x[int(N/2)]


for i in range(N):
    if i <N/2-1 and i !=tmp2[0]:
        print(tmp2[1])
    if i <N/2-1 and i ==tmp2[0]:
        print(tmp1[1])
    if i >=N/2-1 and i !=tmp1[0]:
        print(tmp1[1])
    if i >=N/2-1 and i ==tmp1[0]:
        print(tmp2[1])

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(raw_input())
line = np.array(map(int,raw_input().split()))

max = np.amax(line)

line2 = np.abs(line - float(max / 2))

min = np.argmin(line2)

print max,line[min]

Submission status: Wrong Answer

Solution code:
# 再帰制限に引っかかった場合に外す
import sys
sys.setrecursionlimit(100000000)
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]


n = input()
n= int(n)
ls = input().split()
lsnum = list(map(int,ls))
ma = max(lsnum)

maxvalue = -1
ans = -1
for num in lsnum:
    val = cmb(ma,num)
    if(ma == num):
        continue
    if maxvalue < val:
        maxvalue = val
        ans = [ma, num]
print (ans[0], ans[1])

Submission status: Wrong Answer

Solution code:
import numpy as np

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

M = np.max(n_list)

best_k_bar = (M - 1) / 2
best_k_cand = [x for x in n_list if x >= best_k_bar]
best_k = np.min(best_k_cand)

print(M, best_k)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(zip(map(int, input().split()), range(n)))
for i in range(n//2):
  a[i] = a[n//2 - 1]
  a[i + n//2] = a[n//2]
print('\n'.join(map(lambda x: str(x[0]), sorted(a, key = lambda x: x[1]))))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

n_list2 = list(n_list1)
n_list_test = list(n_list1)

print(n_list_test)

n_list_max = np.max(n_list1)
n_list_min = np.min(n_list2)

n_list1.remove(n_list_max)
n_list2.remove(n_list_min)

# print(np.max(n_list))
# np.median(n_list - )
n_list1_median = int(np.median(n_list1))
n_list2_median = int(np.median(n_list2))

print(n_list1_median)
print(n_list2_median)

for x in n_list_test:
  if n_list1_median >= x:
    print(n_list2_median)
  else:
    print(n_list1_median)

Submission status: Wrong Answer

Solution code:
import random


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


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


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

    X = list(map(int, input().split()))
    # N = 200000
    # X = [random.randint(0, 1000000000) for _ in range(N)]
    X_ = X[:]
    X_.sort()
    X__ = X_[:N // 2]
    X__ = X_[-1]

    x_1 = mid_1(X_)
    x = mid(X_)

    ans = []
    # print(X_)
    # print(X__)
    for i in range(N):
        if X[i] < X__:
            print(x_1)
            # ans.append(x_1)
        else:
            print(x)
            # ans.append(x)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

N = int(input())

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

y = x
y.sort()

for i in range(N):
	if (i+1 <= (N/2)):
		print(y[int(N/2)])
	else:
		print(y[int(N/2-1)])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

y.sort()

#print(x)
#print(y)

b = int(n/2)
s = int(n/2)-1

if n == 2:
    print(x[1])
    print(x[0])
else:
    for i in range(n):
        if x[i] == y[b]:
            print(y[s])
        else:
            print(y[b])

Submission status: Wrong Answer

Solution code:
n = int(input())
l0 = list(map(int, input().split()))
l = sorted(l0)

m1 = l[n//2 - 1]
m2 = l[n//2]
for i in range(len(l0)):
    if l0[i] <= m2:
        print(m2)
    if l0[i] > m1:
        print(m1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
*X, = map(int, input().split())
Y = sorted(X)
p, q = Y[N//2-1:N//2+1]
ans = []
print(p, q)
for i in range(N):
    if X[i] < q:
        ans.append(q)
    else:
        ans.append(p)
print(*ans, sep='\n')

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
X = list(map(int,input().split()))
from statistics import median
for i in range(N):
    B = X[:i]+X[i+1:]
    print(median(B))

Submission status: Time Limit Exceeded

Solution code:
def median(lista):
  lista = sorted(lista)
  return lista[int((len(lista)+ 1)/ 2)- 1]

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

for i in range(N):
  if(i == 0):
    newlista = lista[1:]
  elif(i == N- 1):
    newlista = lista[:N- 1]
  else:
  	newlista = lista[:i]+ lista[i+ 1:]
   
  print(median(newlista))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
X = tuple(map(int,input().split()))
for i in range(n):
    b = list(X)
    del b[i]
    b.sort()
    print(b[int(n/2-1)])

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
ar = list(map(int,input().split(" ")))
b = a // 2 - 1
for i in range(a):
    br = ar[0:i] + ar[i+1:a]
    br.sort()
    print(br[b])

Submission status: Time Limit Exceeded

Solution code:
import statistics
N=int(input())
X=list(map(int, input().split()))
for i in range(0,N):
    print(statistics.median(X[:i]+X[i+1:]))

Submission status: Time Limit Exceeded

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

for i in range(n):
    y = sorted(x[0:i]+x[i+1::1])
    print(y[n//2-1])

Submission status: Time Limit Exceeded

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

import numpy as np
for i in range(n):
    y = np.array(x[0:i]+x[i+1::1])
    print(int(np.median(y)))

Submission status: Time Limit Exceeded

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

import numpy as np
for i in range(n):
    print(int(np.median(x[0:i]+x[i+1::1])))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

c=sorted(x)
a=c[n//2-1]
b=c[n//2]
del c[:n//2]
#print(c)
for i in range(n):
    if x[i] in c:
        print(a)
    else:
        print(b)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

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

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

for i in range(N):
    x = X[0:i]+X[i+1:]
    x.sort(reverse=True)

#    print(x)
    print( x[((len(x)+1) // 2)-1] )

Submission status: Time Limit Exceeded

Solution code:

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

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

for i in range(N):
    x = X[:]
    x.pop(i)
    x.sort(reverse=True)

#    print(x)
    print( x[((len(x)+1) // 2)-1] )

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
ar = list(map(int,input().split(" ")))
for i in range(a):
    br = []
    for j in range(a):
        if i != j:
            br.append(ar[j])
    br.sort()
    print(br[(a-1)//2])

Submission status: Time Limit Exceeded

Solution code:
N = input()
X = map(int, raw_input().split())
pair = [(v, i) for i, v in enumerate(X)]
pair.sort()
X = [v[0] for v in pair]
res = {}
for i, v in enumerate(pair):
    key = v[1]
    val = v[0]
    res[key] = (X[:i] + X[i + 1:])[(N - 1) / 2]
for i in range(N):
    print res[i]

Submission status: Time Limit Exceeded

Solution code:
N = input()
X = map(int, raw_input().split())
pair = [(v, i) for i, v in enumerate(X)]
pair.sort()
X.sort()
res = {}
for i, v in enumerate(pair):
    key = v[1]
    val = v[0]
    res[key] = (X[:i] + X[i + 1:])[(N - 1) / 2]
for i in range(N):
    print res[i]

Submission status: Time Limit Exceeded

Solution code:
N = input()
X = map(int, raw_input().split())
for i in range(N):
    print sorted(X[:i] + X[i + 1:])[(N - 1) / 2]

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from numpy import median
n = int(input())
x = list(map(int, input().split()))
for i in range(n):
    temp = x[0:i] + x[i+1::]
    temp.sort()
    print(temp[int(n/2-1)])

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N=int(input())
X=list(map(int,input().split()))
Y=sorted(X)
a=Y[N//2]
b=Y[N//2-1]
for i in range(N):
    for j in range(N):
        if X[i]==Y[j]:
            if j<N//2:
                print(a)
                break
            else:
                print(b)
                break

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N=int(input())
X=list(map(int,input().split()))
Y=sorted(X)
for i in range(N):
    for j in range(N):
        if X[i]==Y[j]:
            if j<N//2:
                print(Y[N//2])
                break
            else:
                print(Y[N//2-1])
                break

Submission status: Time Limit Exceeded

Solution code:


def binsearch(x,value):
    left=0; right=len(x)-1
    if x[right] == value:
        return right
    elif x[left] == value:
        return left
    while True:
        m = (right+left)//2
        if x[m] == value:
            return m
        elif x[m] > value:
            right = m
        else:
            left = m


def main():
    n = int(input())
    x = [int(i) for i in input().split()]
    newx = sorted(x)
    for i in x:
        index = binsearch(newx,i)
        del newx[index]
        print(newx[(n-1)//2])
        newx.insert(index,i)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    x = [int(i) for i in input().split()]
    for i in range(len(x)):
        tmp = x[i]
        del x[i]
        newx = sorted(x)
        print(newx[len(newx)//2])
        x.insert(i, tmp)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

X2 = sorted(X)

for i in range(0, N):
    idx = X2.index(X[i])
    if idx < N // 2:
        print(X2[N // 2])
    else:
        print(X2[N // 2 - 1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())

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

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import sys
import copy


# 標準入力
n = int(sys.stdin.readline().strip())
xArray = list(map(int, sys.stdin.readline().strip().split(" ")))

result = []

# 演算処理
for i in range(n):
    tmp = copy.copy(xArray)
    del tmp[i]
    tmp = sorted(tmp)
    result.append(tmp[int((n/2) - 1)]) # (l + 1)/2 の要素を参照


# 標準出力
print('\n'.join(map(str, result)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

center = int(n/2-1)

for i in range(n):
  print(sorted(x[:i]+x[i+1:],reverse = True)[center])

Submission status: Time Limit Exceeded

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

for i in range(n):
  print(sorted(x[:i]+x[i+1:],reverse=True)[int(n/2-1)])

Submission status: Time Limit Exceeded

Solution code:
def quickSort(alist):
   quickSortHelper(alist,0,len(alist)-1)

def quickSortHelper(alist,first,last):
   if first<last:

       splitpoint = partition(alist,first,last)

       quickSortHelper(alist,first,splitpoint-1)
       quickSortHelper(alist,splitpoint+1,last)


def partition(alist,first,last):
   pivotvalue = alist[first]

   leftmark = first+1
   rightmark = last

   done = False
   while not done:

       while leftmark <= rightmark and alist[leftmark] <= pivotvalue:
           leftmark = leftmark + 1

       while alist[rightmark] >= pivotvalue and rightmark >= leftmark:
           rightmark = rightmark -1

       if rightmark < leftmark:
           done = True
       else:
           temp = alist[leftmark]
           alist[leftmark] = alist[rightmark]
           alist[rightmark] = temp
           temp=vt[leftmark]
           vt[leftmark]=vt[rightmark]
           vt[rightmark]=temp

   temp = alist[first]
   alist[first] = alist[rightmark]
   alist[rightmark] = temp
   temp = vt[first]
   vt[first]=vt[rightmark]
   vt[rightmark]=temp
   return rightmark
n=int(input())
alist = [int(x) for x in input().split()]
vt=[int(x) for x in range(len(alist))]
result=[]
for i in range(len(vt)):
    result.append(i)
quickSort(alist)
for i in range(len(vt)):
    k=alist[i]
    alist.pop(i)
    m=len(alist)-int(n/2)
    result[vt[i]]=alist[m]
    alist.insert(i,k)
for i in range(len(result)):
    print(result[i])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())

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

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

Submission status: Time Limit Exceeded

Solution code:
from numpy import median
from copy import deepcopy

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

for i in range(n):
    newl = deepcopy(x)
    del newl[i]
    print(int(median(newl)))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
inp=list(map(int, input().strip().split(' ')))

med = int(N/2)
for i in range(N):
  X=[]
  for j in range(N):
    if i!=j:
      X.append(inp[j])
  Xsort = sorted(X)
  print(Xsort[med-1])

Submission status: Time Limit Exceeded

Solution code:
n=int(input());*a,=map(int,input().split())
for i in range(n):print(sorted(a[:i]+a[-~i:])[~-n//2])

Submission status: Time Limit Exceeded

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

for i in range(len(x)):
    b=list()
    for j in range(len(x)):
        if j!=i:b.append(x[j])
    b.sort()
    print(b[int(n/2)-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import copy

n = int(input())
line = input().split(' ')
x = []
xSorted = []
for element in line:
    x.append(int(element))
    xSorted.append(int(element))
xSorted.sort()

for i in range(n):
    temp = copy.deepcopy(xSorted)
    temp.remove(x[i])
    print(temp[int((n-1)/2)])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

X = input().split()


for i in range(N):
    x2 = [int(x) for x in X]
    del x2[i]
    x2.sort()
    
    print("%d"%x2[int((N/2)-1)])

Submission status: Time Limit Exceeded

Solution code:
import copy

n = int(input())
line = input().split(' ')
x = []
for element in line:
    x.append(int(element))

for i in range(len(x)):
    temp = copy.deepcopy(x)
    del temp[i]
    temp.sort()
    print (temp[int(len(temp)/2)])