Problem:


Score : 300 points

Problem Statement

When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.

You are given N numbers X_1, X_2, ..., X_N, where N is an even number.
For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.

Find B_i for each i = 1, 2, ..., N.

Constraints

2 \leq N \leq 200000

N is even.

1 \leq X_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
X_1 X_2 ... X_N

Output

Print N lines.
The i-th line should contain B_i.

Sample Input 1

4
2 4 4 3

Sample Output 1

4
3
3
4

Since the median of X_2, X_3, X_4 is 4, B_1 = 4.

Since the median of X_1, X_3, X_4 is 3, B_2 = 3.

Since the median of X_1, X_2, X_4 is 3, B_3 = 3.

Since the median of X_1, X_2, X_3 is 4, B_4 = 4.

Sample Input 2

2
1 2

Sample Output 2

2
1

Sample Input 3

6
5 5 4 4 3 3

Sample Output 3

4
4
4
4
4
4



Sample input:
4
2 4 4 3


Sample output:
4
3
3
4

Submission status: Time Limit Exceeded

Solution code:


if __name__ == "__main__":

    n = int(input())

    number_list = list(map(int,input().split()))
    tmp_list = number_list[:]
    tmp_list.sort()

    for number in number_list:
        i = tmp_list.index(number)
        if i < (n/2):
            print(tmp_list[int(n/2)])
        else :
            print(tmp_list[int(n/2)-1])

Submission status: Time Limit Exceeded

Solution code:
def median(list):
    list.sort()
    median = list[int((len(list)+1)/2)-1]
    return median

if __name__ == "__main__":

    n = int(input())

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

    for i in range(n):
        m = median(number_list[:i]+number_list[i+1:])
        print(m)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def median(list):
    list.sort()
    median = list[int((len(list)+1)/2)-1]
    return median


n = int(input())

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

for i in range(n):
    tmp_list = number_list[:i]+number_list[i+1:]
    m = median(tmp_list)
    print(m)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = input()
N_list = [int(x) for x in input().split()]
for i in range(len(N_list)):
    if i == 0:
        slice1 = N_list[i+1:len(N_list)]
    else:
        slice1 = N_list[0:i] + N_list[i+1:len(N_list)]
    print(int(np.median(slice1)))

Submission status: Time Limit Exceeded

Solution code:
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []    
    data = input()
    array_result.append(data.split(" "))

    flg = True

    try:
        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0])
val=(n-1)//2

arr=list(map(int, arr_data[1]))

#print(arr)

cnt = 0
while cnt < n:
      
    arr_temp=arr.copy()  
    
    arr_temp.pop(cnt)
    
    arr02 = sorted(arr_temp)
    print(arr02[val])
    
    cnt += 1

Submission status: Time Limit Exceeded

Solution code:
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []    
    data = input()
    array_result.append(data.split(" "))

    flg = True

    try:
        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0])

cnt = 0

while cnt < n:


    arr=[]
    for i in range(0, n):
        
        if cnt != i:

            arr.append(int(arr_data[1][i]))

    
    print(sorted(arr)[(n//2)-1])        
    cnt += 1

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    X = [int(i) for i in input().split()]
    
    sorted_X = sorted(X)
    median_1 = sorted_X[int(N/2)-1]
    median_2 = sorted_X[int(N/2)]
    
    for i in range(N):
        remove_num = X[i]
        if(sorted_X.index(remove_num) > (N/2 - 1)):
            print(median_1)
        else:
            print(median_2)
    
if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

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

if n==2:
    print(b[1])
    print(b[0])
    exit()
    
bs=sorted(b,reverse=True)

bl=[]
for i in b:
    indexb=bs.index(i)
    bl.append(indexb)
    bs[indexb]=-1
bs=sorted(bl[1:n])
mid=bs[n//2-1]
bd=dict(zip(bl,b))
print(bd[mid])

for i in range(1,n):
    if bl[i-1]>=mid>=bl[i]:
        mid+=1
    elif bl[i-1]<=mid<=bl[i]:
        mid-=1
    print(bd[mid])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import statistics

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

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

Submission status: Time Limit Exceeded

Solution code:
from statistics import median


N = int(input())

X = input().split()
X = [ int(x) for x in X]
"""
N = 4
X = [2,4,4,3]
"""

#F = copy.deepcopy(X)
F = X[:]
F.sort()

median1 = int(N/2 - 1)
median2 = int(N/2) 

for i in range(N):
    #print(F, median1, median2)
    
    if X[i] < median(F):
        ans = F[median2]
    else:
        ans = F[median1]
    print(int(ans))

Submission status: Time Limit Exceeded

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

for i in X:
    if list.index(i)<N/2:
        print(list[N//2])
    else:
        print(list[N//2-1])

Submission status: Time Limit Exceeded

Solution code:
Q=int(input())
a=[int(x) for x in input().split()]
for i in range(0,Q):
    k=a.pop(i)
    b=sorted(a)
    a.insert(i,k)
    l=int((Q-2)/2)
    #print(a,b)
    print(b[l])

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*
n = int(raw_input())
x =[]
x = map(int, raw_input().split())

for i in range(n):
 copyx = list(x)
 del copyx[i]
 copyx.sort()
 b = copyx[int((n-1)/2)]
 print(b)

Submission status: Time Limit Exceeded

Solution code:
import copy
#import bisect
from statistics import median


N = int(input())

X = input().split()
X = [ int(x) for x in X]
"""
N = 4
X = [2,4,4,3]
"""
j = int(N/2)
F = copy.deepcopy(X)
F.sort()

median1 = int(N/2 - 1)
median2 = int(N/2) 

for i in range(N):
    #print(F, median1, median2)
    
    if X[i] < median(F):
        ans = F[median2]
    else:
        ans = F[median1]
    print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
from copy import deepcopy

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

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

Submission status: Time Limit Exceeded

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

N = int(input())
target = N//2-1
X = [0] + list(map(int, input().split()))

for i in range(1, N+1):
  l = X[1:i] + X[i+1:N+1]
  print(sorted(l)[target])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
X = tuple(map(int,input().split()))
test = int(N/2)
for i in range(len(X)):
    temp = list(X)
    temp.pop(i)
    temp = sorted(temp)
    print(temp[test-1])

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

sortedx = x[:]
sortedx.sort()

for i in range(n):
    ix = sortedx.index(x[i])
    #print(sortedx)
    #print(ix)
    if ix < n/2:
        print(sortedx[n//2])
    else:
        print(sortedx[n//2-1])

Submission status: Time Limit Exceeded

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

def median(x, i):
    x = sorted(x)
        
    return(x[i])

def algo(x):
    l = len(x)
    t = (l + 1) // 2
    while True:
        p = x[len(x) // 2]
        a = []
        b = []
        for i in x:
            if i <= p:
                a.append(i)
            else:
                b.append(i)
        if len(a) == 0:
            return median(b, t - 1)
        elif len(b) == 0:
            return median(a, t - 1)
        elif len(a) >= t:
            x = a
        else:
            x = b
            t = t - len(a)


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

Submission status: Time Limit Exceeded

Solution code:
import copy
N=int(input())
X_list=list(map(int,input().split()))
a=int(N/2-1)
for i in range(N):
    Xcopy=copy.deepcopy(X_list)
    Xcopy[i]=0
    Xcopy.sort(reverse=True)
    print(Xcopy[a])

Submission status: Time Limit Exceeded

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

list_size = int(input())
num_list = [int(i) for i in input().split()]

for i in range(0, list_size):

	num_list2 = []
	for idx, num in enumerate(num_list):
		
		if idx != i:
			num_list2.append(num)
	
	# 昇順ソート
	num_list2.sort()
	# 中央値の計算
	ans = num_list2[int((len(num_list2) + 1) / 2) - 1]
	print(ans)

Submission status: Time Limit Exceeded

Solution code:
def c_many_medians(N, X):
    x = [[0, 0] for _ in range(N)]
    for i, e in enumerate(X):
        x[i] = [i, e]
    x.sort(key=lambda k: k[1])
    mid = N // 2 - 1
    a, b = [0] * N, [0] * N
    for i, (k, v) in enumerate(x):
        p=x.index([k,v])
        a[k] = p
        b[i] = v
    ans = ['' for _ in range(N)]
    for i in a:
        if b[mid]>=b[a[i]]:
            ans[i]='{}'.format(b[mid+1])
        else:
            ans[i]='{}'.format(b[mid])
    return '\n'.join(ans)

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
X = tuple(map(int,input().split()))
for i in range(len(X)):
    temp = list(X)
    temp.pop(i)
    test = int((len(temp)+1)/2)
    temp = sorted(temp)
    print(temp[test-1])

Submission status: Time Limit Exceeded

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

if __name__ == '__main__':
    N = int(input())
    X = list(int(i) for i in input().split()) 
    P = int(N/2)-1
        
    for i in range(N):
        Y = X[:]
        Y.pop(i)
#        Y.extend(X[0:i])
#        Y.extend(X[i+1:N])      
        Y.sort()
        print(Y[P])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
XX = list(int(i) for i in input().split())

X = []
Y = []
for i in range(0, N):
    X = XX + Y
    del X[i]
    X.sort(reverse=True)
    ans = X[int((N/2-1))]
    print(ans)

Submission status: Time Limit Exceeded

Solution code:

N=int(input())
X_list=list(map(int,input().split()))
a=int(N/2-1)
for i in range(N):
    Xcopy=list(X_list)
    Xcopy[i]=0
    Xcopy.sort(reverse=True)
    print(Xcopy[a])

Submission status: Time Limit Exceeded

Solution code:
import copy
import bisect
#from statistics import median


N = int(input())

X = input().split()
X = [ int(x) for x in X]
"""
N = 4
X = [2,4,4,3]
"""
j = int(N/2)
F = copy.deepcopy(X)
F.sort()


for i in range(N):
    S = copy.deepcopy(F)
#    print(S)
    #print(bisect.bisect_left(S, X[i]))
    del S[bisect.bisect_left(S, X[i])]
#    print(S)
    print(S[j-1])

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

import copy

N = input()
X = map(int, raw_input().split())
AN = N / 2 - 1

for i in range(N):
    RA = copy.deepcopy(X)
    del RA[i]
    RA.sort()
    print RA[AN]

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations 

def main():
    global N
    N = int(input())
    index = int((N - 2) / 2)
    X = list(map(int, input().split()))
    X = list(combinations(X, N - 1))
    A = []
    for i in X[::-1]:
        A = list(i)
        A.sort()
        print(A[index])

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
list = list(map(int, input().split()))
num = int(len(list)/2 - 1)
i = 0
for i in range(N):
  LIST = list[:]
  del LIST[i]
  LIST.sort()
  print(LIST[num])
  i = i + 1

Submission status: Time Limit Exceeded

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

for i in range(N):
    tmp = X[:i]
    tmp.extend(X[i+1:])
    print(int(np.median(tmp)))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

sorted_A = np.sort(A)
sort_list = np.argsort(A)

for i in range(len(A)):
	del_num = np.where(sort_list == i)
	sorted_A_i = np.delete(sorted_A, del_num)
	print(sorted_A_i[int(len(A)/2 - 1)])

Submission status: Time Limit Exceeded

Solution code:
import bisect
n = input()
l = map(int,raw_input().split())
nl = l[:]
nl.sort()
#print nl
for i in l:
    nl.remove(i)
    #print i,nl
    if len(nl)%2==0:
        print nl[(len(nl)+1)/2]
    else:
        print nl[len(nl)/2]

    bisect.insort(nl,i)

Submission status: Time Limit Exceeded

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

for i in range(N):
    li1 = X[:i+1]
    li2 = X[i+1:]
    li1.pop()
    li = li1 + li2
    li = sorted(li)
    print(li[int(N/2-1)])

Submission status: Time Limit Exceeded

Solution code:

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

sortedx = x[:]
sortedx.sort()

for i in range(n):
    ix = sortedx.index(x[i])
    #print(sortedx)
    #print(ix)
    if ix < n/2:
        print(sortedx[n//2])
    else:
        print(sortedx[n//2-1])

Submission status: Time Limit Exceeded

Solution code:
N = input()
N = int(N)
A = input()
array = A.split()
ind = 0
for n in array:
    array[ind] = int(n)
    ind = ind+1

sortedarray = sorted(array)

be = sortedarray[(N//2-1)]
af = sortedarray[N//2]
for flag in array:
    ind = sortedarray.index(flag)
    if ind < N/2:
        print(af)
    else: print(be)

Submission status: Time Limit Exceeded

Solution code:
import copy
n = int(input())
N = int(n/2-1)
x = list(map(int, input().split()))
y = sorted(x)

for i in range(n):
    Y  = copy.deepcopy(y)
    Y.remove(x[i])
    print(Y[N])

Submission status: Time Limit Exceeded

Solution code:
import copy
N = int(input())
list = list(map(int, input().split()))
num = int(len(list)/2 - 1)
i = 0
for i in range(N):
  LIST = list[:]
  del LIST[i]
  LIST.sort()
  print(LIST[num])
  i = i + 1

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations 

def main():
    global N
    N = int(input())
    index = int((N - 2) / 2)
    X = list(map(int, input().split()))
    X = list(map(list, list(combinations(X, N - 1))))
    for i in X[::-1]:
        i.sort()
        print(i[index])

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a1=input().split()
tag_list=[]
dic={}
for i in a1:
    tag_list.append(int(i))
 
for j in range(0,n):
    numnum=tag_list[j]
    if numnum in dic:
        print(dic[numnum])
    else:
        A=tag_list[0:j]
        test=tag_list[j+1:n]
        A.extend(test)
        A.sort()
        num=int(n/2-1)
        print(A[num])
        dic[numnum]=A[num]

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

n = int(raw_input())
XS = map(int, raw_input().split())

i = 0
while i < n:
    L = []
    j = 0
    while j < n:
        if j == i:
            j = j + 1
            continue
        if not XS[j] in L:
            L.append(XS[j])
        j = j + 1
    L.sort()
    b = (len(L)+1-1) / 2

    print(L[b])
    i = i + 1

Submission status: Time Limit Exceeded

Solution code:
# See:
# https://qiita.com/suecharo/items/30f5d817da4c948c3be6
def merge_sort(arr):
    if len(arr) <= 1:
        return arr

    mid = len(arr) // 2
    # ここで分割を行う
    left = arr[:mid]
    right = arr[mid:]

    # 再帰的に分割を行う
    left = merge_sort(left)
    right = merge_sort(right)

    # returnが返ってきたら、結合を行い、結合したものを次に渡す
    return merge(left, right)


def merge(left, right):
    merged = []
    l_i, r_i = 0, 0

    # ソート済み配列をマージするため、それぞれ左から見ていくだけで良い
    while l_i < len(left) and r_i < len(right):
        # ここで=をつけることで安定性を保っている
        if left[l_i] <= right[r_i]:
            merged.append(left[l_i])
            l_i += 1
        else:
            merged.append(right[r_i])
            r_i += 1

    # 上のwhile文のどちらかがFalseになった場合終了するため、あまりをextendする
    if l_i < len(left):
        merged.extend(left[l_i:])
    if r_i < len(right):
        merged.extend(right[r_i:])
    return merged


if __name__ == '__main__':
    n = int(input())
    x = list(map(int, input().split()))
    order = list(x)

    for i in range(n):
        tmp = order[i]
        x.remove(tmp)
        x = merge_sort(x)
        print(x[(n // 2) - 1])
        x += [tmp]

Submission status: Time Limit Exceeded

Solution code:
def c_many_medians(N, X):
    x = [[0, 0] for _ in range(N)]
    for i, e in enumerate(X):
        x[i] = [i, e]
    x.sort(key=lambda k: k[1])
    mid = N // 2 - 1
    a, b = [0] * N, [0] * N
    for i, (k, v) in enumerate(x):
        a[i] = k
        b[i] = v
    ans = ''
    for i in range(N):
        idx = a.index(i)
        value = b[idx]
        b.remove(value)
        ans += '{}\n'.format(b[mid])
        b.insert(idx, value)
    ans = ans[:-1]
    return ans

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

Submission status: Time Limit Exceeded

Solution code:
import copy

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

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

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

for i in range(N):
    li1 = X[:i]
    li2 = deque(X[i:])
    li2.popleft()
    li = li1 + list(li2)
    li = sorted(li)
    print(li[int(N/2-1)])

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
x = list(map(int, input().split(' ')))

res = {}
for i in range(n):
    if x[i] not in res.keys():
        res.update({x[i]:int(np.median(x[:i] + x[(i+1):]))})
    print(res[x[i]])

Submission status: Time Limit Exceeded

Solution code:
import copy

n = int(input())
x = [int(i) for i in input().split()]
sortedx = copy.copy(x)
sortedx.sort()

m = {}

for i in x:
    if i in m:
        print(m[i])
    else:
        cnt = 0
        flag = False
        for j in range(n):
            if i == sortedx[j] and not flag:
                flag = True
            elif cnt == (n/2)-1:
                print(sortedx[j])
                m[i] = sortedx[j]
                break
            else:
                cnt += 1

Submission status: Time Limit Exceeded

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

# AtCoder Beginner Contest
# Problem C


# See:
# https://qiita.com/suecharo/items/30f5d817da4c948c3be6
def quick_sort(arr):
    left = []
    right = []
    if len(arr) <= 1:
        return arr

    ref = arr[0]
    ref_count = 0

    for ele in arr:
        if ele < ref:
            left.append(ele)
        elif ele > ref:
            right.append(ele)
        else:
            ref_count += 1
    left = quick_sort(left)
    right = quick_sort(right)
    return left + [ref] * ref_count + right


if __name__ == '__main__':
    n = int(input())
    x = list(map(int, input().split()))
    order = list(x)

    for i in range(n):
        tmp = order[i]
        x.remove(tmp)
        x = quick_sort(x)
        print(x[(n // 2) - 1])
        x += [tmp]

Submission status: Time Limit Exceeded

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

for i in range(0, N):
    if i == 0:
        l = X[1:N]
    else:
        l = X[0:i] + X[i+1:N]
    l.sort()
    mid = N // 2 - 1
    print(l[mid])

Submission status: Time Limit Exceeded

Solution code:
import copy

n = int(input())

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

soredx = sorted(x)

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
X = [int(i) for i in input().split()]
for i in range(N):
    t = X.pop(i)
    print(int(np.median(X)))
    X.insert(i, t)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
x = list(map(int, input().split(' ')))

res = {}
for i in range(n):
    if i not in res.keys():
        res.update({i:int(np.median(x[:i] + x[(i+1):]))})
    print(res[i])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import copy
N = int(input())
list = list(map(int, input().split()))
num = int(len(list)/2 - 1)
i = 0
for i in range(N):
  i = i + 1
  LIST = list[:]
  del LIST[i-1]
  LIST.sort()
  print(LIST[num])

Submission status: Time Limit Exceeded

Solution code:
def merge_sort(arr):
    if len(arr) <= 1:
        return arr

    mid = len(arr) // 2
    # ここで分割を行う
    left = arr[:mid]
    right = arr[mid:]

    # 再帰的に分割を行う
    left = merge_sort(left)
    right = merge_sort(right)

    # returnが返ってきたら、結合を行い、結合したものを次に渡す
    return merge(left, right)


def merge(left, right):
    merged = []
    l_i, r_i = 0, 0

    # ソート済み配列をマージするため、それぞれ左から見ていくだけで良い
    while l_i < len(left) and r_i < len(right):
        # ここで=をつけることで安定性を保っている
        if left[l_i] <= right[r_i]:
            merged.append(left[l_i])
            l_i += 1
        else:
            merged.append(right[r_i])
            r_i += 1

    # 上のwhile文のどちらかがFalseになった場合終了するため、あまりをextendする
    if l_i < len(left):
        merged.extend(left[l_i:])
    if r_i < len(right):
        merged.extend(right[r_i:])
    return merged


import copy

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

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

Submission status: Time Limit Exceeded

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

if __name__ == '__main__':
    N = int(input())
    X = list(int(i) for i in input().split()) 
    P = int(N/2)-1
        
    for i in range(N):
        Y = []
        Y.extend(X[0:i])
        Y.extend(X[i+1:N])      
        Y.sort()
        print(Y[P])

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
XX=[int(x) for x in input().split()]   
X=sorted(XX)
for i in range(0,N):
    k=XX[i]
    l=int(N/2)-1
    idx=X.index(k)
    X.pop(idx)
    print(X[l])
    X.insert(idx,k)

Submission status: Time Limit Exceeded

Solution code:
d = int(input())
a = list(map(int, input().split()))
b = []
for i in range(d):
    for j in range(d):
        b.append(a[j])
    del b[i]
    b.sort()
    print(b[int(d/2-1)])
    b.clear()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
x =[int(i) for i in input().split()]
c = n//2 - 1

for i in range(0,n):
    temp = x.copy()
    temp.pop(i)
    temp.sort()
    print(temp[c])

Submission status: Time Limit Exceeded

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

for i,x in enumerate(Xs):
    arr = Xs[:i] + Xs[i+1:]
    arr.sort(reverse=True)
    m = int(N/2)-1
    print(arr[m])

Submission status: Time Limit Exceeded

Solution code:
import copy
N = int(input())
list = list(map(int, input().split()))
num = int(len(list)/2 - 1)
i = 0
for i in range(N):
  i = i + 1
  LIST = copy.deepcopy(list)
  del LIST[i-1]
  LIST.sort()
  print(LIST[num])

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import re
import doctest


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

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

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

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

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


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


def median_without(x, e, mid_left, mid_right):
    if x[mid_left] == x[mid_right]:
        return x[mid_left]
    else:
        if x.index(e) == mid_left:
            return x[mid_right]
        else:
            return x[mid_left]


def solve():
    [n] = IO_for_Contest.read_from_input()
    x = IO_for_Contest.read_n_int(n)
    y = sorted(x)
    threshold = 1000
    if len(y) <= threshold:
        for e in x:
            print(median_without_naive(y, e))
    else:
        buf = ''
        mid_left = len(y) // 2 - 1
        mid_right = len(y) // 2
        for e in x:
            buf += str(median_without(y, e, mid_left, mid_right)) + '\n'
        print(buf)


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

Submission status: Time Limit Exceeded

Solution code:
def main():
    n=int(input())
    x = [int(i) for i in input().split()]
    x = tuple(x)
    for i in range(n):
        x_l=list(x)
        del x_l[i]
        x_l.sort()
        print(x_l[int((len(x_l)-1)/2)])
            
main()

Submission status: Time Limit Exceeded

Solution code:

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

for i in range(n):
    memo = x.pop(i)
    b = sorted(x)
    print(b[int(n/2) - 1])
    x.insert(i, memo)

Submission status: Time Limit Exceeded

Solution code:
def median(lst):
    even = (0 if len(lst) % 2 else 1) + 1
    half = (len(lst) - 1) / 2
    return sum(sorted(lst)[half:half + even]) / float(even)
    
n=int(raw_input())
arr=map(int,raw_input().split(' '))
for i in range(0,n):
	t=list(arr)
	t.pop(i)
	print int(median(t))

Submission status: Time Limit Exceeded

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

# AtCoder Beginner Contest
# Problem C


# See:
# https://qiita.com/suecharo/items/30f5d817da4c948c3be6
def quick_sort(arr):
    left = []
    right = []
    if len(arr) <= 1:
        return arr

    ref = arr[0]
    ref_count = 0

    for ele in arr:
        if ele < ref:
            left.append(ele)
        elif ele > ref:
            right.append(ele)
        else:
            ref_count += 1
    left = quick_sort(left)
    right = quick_sort(right)
    return left + [ref] * ref_count + right


if __name__ == '__main__':
    n = int(input())
    x = list(map(int, input().split()))
    order = list(x)

    for i in range(n):
        tmp = order[i]
        x.remove(tmp)
        x = quick_sort(x)
        print(x[(n // 2) - 1])
        x = x + [tmp]

Submission status: Time Limit Exceeded

Solution code:
import copy
#from statistics import median


N = int(input())

X = input().split()
X = [ int(x) for x in X]
"""
N = 4
X = [2,4,4,3]
"""
j = int(N/2)
F = copy.deepcopy(X)
F.sort()

for i in range(N):
    S = copy.deepcopy(F)
#    print(S)
    S.remove(X[i])
#    print(S)
    print(S[j-1])

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = input()
x = list(map(int, input().split()))
for i, xx in enumerate(x):
    print(int(np.median(x[:i] + x[i+1:])))

Submission status: Time Limit Exceeded

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

# スペース区切りの整数の入力
N = int(input())
X = list(map(int, input().split()))

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

Submission status: Time Limit Exceeded

Solution code:

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

for i in range(n):
    memo = a.pop(i)
    b = sorted(a, key=lambda t: t[1])
    print(b[int(n/2) - 1][1])
    b.append(memo)
    a = sorted(b, key=lambda t: t[0])

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.pop(i)
    test = sorted(X)
    print(test[int((N-2)/2)])
    X[i:i] = [a]

Submission status: Time Limit Exceeded

Solution code:
def merge_sort(arr):
    if len(arr) <= 1:
        return arr

    mid = len(arr) // 2
    # ここで分割を行う
    left = arr[:mid]
    right = arr[mid:]

    # 再帰的に分割を行う
    left = merge_sort(left)
    right = merge_sort(right)

    # returnが返ってきたら、結合を行い、結合したものを次に渡す
    return merge(left, right)


def merge(left, right):
    merged = []
    l_i, r_i = 0, 0

    # ソート済み配列をマージするため、それぞれ左から見ていくだけで良い
    while l_i < len(left) and r_i < len(right):
        # ここで=をつけることで安定性を保っている
        if left[l_i] <= right[r_i]:
            merged.append(left[l_i])
            l_i += 1
        else:
            merged.append(right[r_i])
            r_i += 1

    # 上のwhile文のどちらかがFalseになった場合終了するため、あまりをextendする
    if l_i < len(left):
        merged.extend(left[l_i:])
    if r_i < len(right):
        merged.extend(right[r_i:])
    return merged


import copy

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

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