Problem:


Score : 300 points

Problem Statement

Takahashi made N problems for competitive programming.
The problems are numbered 1 to N, and the difficulty of Problem i is represented as an integer d_i (the higher, the harder).

He is dividing the problems into two categories by choosing an integer K, as follows:

A problem with difficulty K or higher will be for ARCs.

A problem with difficulty lower than K will be for ABCs.

How many choices of the integer K make the number of problems for ARCs and the number of problems for ABCs the same?

Problem Statement

2 \leq N \leq 10^5

N is an even number.

1 \leq d_i \leq 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
d_1 d_2 ... d_N

Output

Print the number of choices of the integer K that make the number of problems for ARCs and the number of problems for ABCs the same.

Sample Input 1

6
9 1 4 4 6 7

Sample Output 1

2

If we choose K=5 or 6, Problem 1, 5, and 6 will be for ARCs, Problem 2, 3, and 4 will be for ABCs, and the objective is achieved.
Thus, the answer is 2.

Sample Input 2

8
9 1 14 5 5 4 4 14

Sample Output 2

0

There may be no choice of the integer K that make the number of problems for ARCs and the number of problems for ABCs the same.

Sample Input 3

14
99592 10342 29105 78532 83018 11639 92015 77204 30914 21912 34519 80835 100000 1

Sample Output 3

42685



Sample input:
6
9 1 4 4 6 7


Sample output:
2

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
d=list(map(int,input().split()))
dd=sorted(d)
N=dd[n-1]
sum1=0
sum2=0
count=0
for k in range(N+1):
    for i in range(n):
        if d[i]>=k:
            sum1+=1
    if sum1==n-sum1:
        count+=1
    sum1=0
    sum2=0
print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

size=input()
pro=input()

p=np.array(pro.split(" "),dtype=np.int32)
p=np.sort(p)

k_end=max(p)
k_start=min(p)

check=p[int(len(p)/2)]


c=0
for k in range(k_start,k_end+1):
    if(check+1<k):
        break
    a=len(p[k<=p])
    b=len(p[k>p])
    if(a==b):
        c+=1
    else:
        pass
print(c)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
def main():
    N = int(input())
    D =[int(i) for i in input().split()]
    count = 0
    D.sort()
    D.reverse()
    #print(D)
    for j in range(100000):
        if j > D[0]:
            break
        for i in range(N):
            if D[i] < j:
                if i == (N/2):
                    count+=1
                else:
                    break
    print(count)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
t =list(map(int, input().split()))
counter=0
x=max(t)
y=min(t)



for i in range(y,x+1):
    ABC=0
    ARC=0
    for j in t:
        if(j>=i):
            ARC+=1
        #if(j<i):
            #ABC+=1
    if(n-ARC==ARC):
        counter+=1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
d=list(map(int,input().split()))
dd=sorted(d)
N=dd[n-1]
sum1=0
sum2=0
count=0
for k in range(N+1):
    for i in range(n):
        if d[i]>=k:
            sum1+=1
        else:
            sum2+=1
    if sum1==sum2:
        count+=1
    sum1=0
    sum2=0
print(count)

Submission status: Time Limit Exceeded

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

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

p.sort()
half = n/2
minn = min(p)
maxn = max(p)
count = 0

for minn in range(maxn + 1):
    if(half == len([i for i in p if i <= minn])):
      count = count + 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys 
import numpy as np
def divide():
    N=int(input())
    d=list(map(int,input().split()))
    d=np.array(d)
    countour=0
    countourf1=0
    countourf2=0
    for i in range(1,100000):
        x=np.where(d < i, 0,1)
        for y in range(0,N):
            if x[y] ==0:
                countourf1+=1
            else :
                countourf2+=1
    
        if countourf1==countourf2:
            countour+=1
        countourf1=0
        countourf2=0    
            
    print(countour)


divide()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
t =list(map(int, input().split()))
counter=0
x=max(t)
y=min(t)



for i in range(y,x+1):
    ABC=0
    ARC=0
    for j in t:
        if(j>=i):
            ARC+=1
        if(j<i):
            ABC+=1
    if(ARC==ABC):
        counter+=1
print(counter)

Submission status: Time Limit Exceeded

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

li.sort()

ind=int(n//2)-1

count=0
for k in range(li[ind],li[ind+1]+1):
  miman=0
  ijou=0
  for num in li:
    if num >= k:
      ijou+=1
    elif num < k:
      miman+=1
      
  if ijou==miman:
    count+=1
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

d = list(map(int,input().split()))
ans = 0
k_m = max(d)

for i in range(1, k_m+1):
    abc = []
    arc = []
    arc = [j for j in d if j >= i]  
    abc = [k for k in d if k < i]
    if len(arc) == len(abc):
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
D = list(map(int, input().split()))
D.sort()
ans = 0
for i in range(D[N // 2 - 1], max(D)) :
  cnt = len(list(filter(lambda x : x <= i, D)))
  if(cnt == N // 2) :
    ans += 1
  elif(cnt > N // 2) :
    break
  else :
    pass
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

size=input()
pro=input()

p=np.array(pro.split(" "),dtype=np.int32)

k_end=max(p)
k_start=min(p)

c=0
for k in range(k_start,k_end+1):
    a=len(p[k<=p])
    b=len(p[k>p])
    if(a==b):
        c+=1
    else:
        pass
print(c)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
def main():
    N = int(input())
    D =[int(i) for i in input().split()]
    count = 0
    D.sort()
    D.reverse()
    #print(D)
    for j in range(100000):
        for i in range(N):
            if D[i] < j:
                if i == (N/2):
                    count+=1
                else:
                    break
    print(count)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
D = list(map(int, input().split()))
ans = 0
for i in range(min(D), max(D)) :
  cnt = len(list(filter(lambda x : x <= i, D)))
  if(cnt == N // 2) :
    ans += 1
  elif(cnt > N // 2) :
    break
  else :
    pass
print(ans)

Submission status: Time Limit Exceeded

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

L=0
R=0
DDT = 0
ans = 0
for K in range(min(d),max(d)+1):
    for i in range(N):
        if d[i] == K:
            DDT += 1
        elif d[i] < K:
            L += 1
        else:
            R += 1
    if L == R:
        ans += 1
    else:
        while DDT > 0:
            if L < R:
                L += 1
                DDT -= 1
            elif L > R:
                R += 1
                DDT -= 1
            else:
                L += 1
                DDT -= 1
        if L == R:
            ans += 1
    L = 0
    R = 0
    DDT = 0
print(ans-1)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
D = list(map(int, input().split()))
ans = 0
for i in range(max(D)) :
  cnt = len(list(filter(lambda x : x <= i, D)))
  if(cnt == N // 2) :
    ans += 1
  elif(cnt > N // 2) :
    break
  else :
    pass
print(ans)

Submission status: Time Limit Exceeded

Solution code:
size=input()
pro=input()

p=pro.split(" ")

for i in range(len(p)):
    p[i]=int(p[i])

k_end=max(p)
k_start=min(p)

c=0
for k in range(k_start,k_end+1):
    a=[]
    b=[]
    for x in p:
        if(k<=x):
            a.append(x)
        else:
            b.append(x)
    if(len(a)==len(b)):
        c+=1
    else:
        pass
print(c)

Submission status: Time Limit Exceeded

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

l = int(n/2)

for i in range(l-1):
    t1 = max(p)
    t2 = min(p)
    #print(t1, t2)
    p.remove(t1)
    p.remove(t2)

print(max(p) - min(p))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
D = list(map(int, input().split()))
ans = 0
for i in range(max(D)) :
  cnt = len(list(filter(lambda x : x <= i, D)))
  if(cnt == N // 2) :
    ans += 1
  else :
    pass
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
p = sorted(list(map(int, input().split())))
mid = n // 2
ans = 0
for i in range(p[mid-1], p[mid]):
  if len([j for j in p if j > i]) == mid:
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

half = n/2
minn = min(p)
maxn = max(p)
count = 0

for minn in range(maxn + 1):
    if(half == len([i for i in p if i <= minn])):
      count = count + 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
p = sorted(list(map(int, input().split())))
mid = n // 2
ans = 0
for i in range(p[mid-1], p[mid]):
  if len([j for j in p if j > i]) == (n//2):
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
input_line = [input() for i in range(1)]
d = list(map(int,input_line[0].split()))
K = []

for k in range(max(d)+1):
    ARC = []
    ABC = []    
    for i in range(N):
        if d[i] >= k:
            ARC.append(d[i])
        if d[i] < k:
            ABC.append(d[i])
    if len(ARC) == len(ABC):
        K.append(k)
print(len(K))

Submission status: Time Limit Exceeded

Solution code:
a=[]
i=1
k=1
l=0
rk=[]
bk=[]
a.append(int(input()))
for x in input().split(" "):
    a.append(int(x))

while k<=100000:
    while i<=a[0]:
        if a[i]>=k:
            rk.append(a[i])
        else:
            bk.append(a[i])
        i+=1
    if len(rk)==len(bk):
        l+=1
    rk=[]
    bk=[]
    i=1
    k+=1
        
print(l)

Submission status: Time Limit Exceeded

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

max_d = max(d)

under = 0
over = 0
num = 0
for i in range(min(d), max_d):
    for j in range(len(d)):
        if i >= d[j]:
            under += 1
        elif i < d[j]:
            over += 1
    if under == over:
        num += 1
    under = 0
    over = 0

print(num)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d = list(map(int,input().split()))
ans = 0
k_m = max(d)

for i in range(1, k_m+1):
    abc = 0
    arc = 0
    for j in d:
        if j >= i:
            arc += 1
        elif j < i:
            abc += 1
    if arc == abc:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d = list(map(int, input().split()))
mid = int(n/2)+1
for i in range(mid):
    min_index=i
    min_value=d[i]
    for j in range(i,n):
        if d[j]<min_value:
            min_index = j
            min_value = d[j]
    v = d[i]
    d[i] = d[min_index]
    d[min_index] = v
print(d[mid-1]-d[mid-2])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d = list(map(int, input().split()))
ans = 0
for i in range(max(d)):
	a = sum(x > i for x in d)
	if a == (n/2):
		ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
d = list(map(int,input().split()))
d.sort()
var = 0
y = d[N//2] - d[(N//2)-1]
k = d[(N//2)-1]
for j in range(y):
  k = k+1
  m = len([i for i in d if i < k])
  if m*2 == N:
    var = var + 1
print(var)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

ans = 0

k_m = max(d)

for i in range(1, k_m+1):
    abc = 0
    arc = 0
    for j in d:
        if j >= i:
            arc += 1
        elif j < i:
            abc += 1

    if arc == abc:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
d = list(map(int, input().split()))
c = 0

c_R = 0
c_B = 0

d_min = min(d)
d_max = max(d)

for K in range(d_min,d_max+1):
    c_R = 0
    c_B = 0
    for i in range(N):
        if K <= d[i] :
            c_R = c_R + 1
        else:
            c_B = c_B + 1
    if c_R == c_B:
        c = c + 1

print(c)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d = map(int, input().split())
d = sorted(d)
l = []
now = 0
ans = 0
for i in range(n-1):
    if d[i] != d[i+1]:
        a = d.index(d[i])
        b = d.count(d[i])
        index = a+b-1
        #print(index)
        if index+1 == n/2:
            #print(d[i+1], d[i])
            ans = d[i+1]-d[i]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
dif = np.array(list(map(int, input().split())))
divide = 0
for k in range(min(dif), max(dif)+1):
    count_over = 0
    count_under = 0
    for i in range(len(dif)):
        if dif[i] >= k:
            count_over += 1
        else:
            count_under += 1
    if count_over == count_under:
        divide += 1
print(divide)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
X = list(map(int,input().split()))
Y = sorted(list(set(X)))
Z = [X.count(y) for y in Y]
cnt = 0
for i in range(len(Y)):
    cnt += Z[i] 
    if cnt == N//2:
        cnt = Y[i+1] - Y[i]
        break
    elif cnt > N//2:
        cnt = 0
        break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


def resolve():
    N = int(input())
    d = [int(i) for i in input().split()]
    d = np.array(d)
    d = np.sort(d)
    count = 0
    for i in range(100000):
        if (np.nonzero(d >= i)[0].size == np.nonzero(d < i)[0].size):
            count += 1
    print(count)
    
resolve()

Submission status: Time Limit Exceeded

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

cnt = 0

for i in range(1, max(d_list)+1):
  cnt_low = 0
  cnt_high = 0
  for d in d_list:
    if i >= d:
      cnt_high += 1
    else:
      cnt_low += 1

  if cnt_high == cnt_low:
    cnt += 1
      
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
dif = list(map(int, input().split()))
divide = 0
for k in range(min(dif), max(dif)+1):
    count_over = 0
    count_under = 0
    for i in range(len(dif)):
        if dif[i] >= k:
            count_over += 1
        else:
            count_under += 1
    if count_over == count_under:
        divide += 1
print(divide)

Submission status: Time Limit Exceeded

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


res_count = 0
for K in range(min(d_list), max(d_list)+1):
    ARC = 0
    ABC = 0
    for d in d_list:
        if( d >= K ):
            ARC += 1
        else:
            ABC += 1
    if( ARC == ABC ):
        res_count += 1
print(res_count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input()) 
d = list(map(int, input().split()))
a=int(N/2)
for i in range(len(d)-1):
	for j in range(i+1, len(d)):
		if d[i] > d[j]:
			temp = d[i]
			d[i] = d[j]
			d[j] = temp
print(d[a]-d[a-1])

Submission status: Time Limit Exceeded

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

max_k = max(d)
min_k = min(d)

d.sort()

abc = []
arc = []
count = 0

for k in range(min_k,max_k + 1):
    abc = [num for num in range(0,N) if d[num] < k]
    arc = [num for num in range(0,N) if d[num] >= k]
    if(len(abc) == len(arc)):
        count += 1
print(count)

Submission status: Time Limit Exceeded

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

def main():
    n=int(input())
    d = list(map(int,input().split()))
    cnt=0

    d.sort()
    a=d[0]
    b=d[n-1]
    c=b-a+1

    for i in range(c):
        index=bisect.bisect_right(d,i+a)
        D=d[index:]
        lend=len(D)
        if(int(n//2)==lend):
            cnt+=1
    
    print(cnt)
    
main()

Submission status: Time Limit Exceeded

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

rates = sorted(list(set(D)))
counter = [0] * len(rates)
for i in range(len(rates)):
    counter[i] += D.count(rates[i])

acc = 0
found = False
for i in range(len(counter)):
    acc += counter[i]
    if acc == N/2:
        found = True
        break
    if acc > N/2:
        found = False
        break

if found == False:
    print(0)
else:
    print(rates[i+1]-rates[i])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
X = list(map(int,input().split()))
Y = sorted(list(set(X)))
Z = [X.count(y) for y in Y]
cnt = 0
for i in range(len(Y)):
    cnt += Z[i] 
    if cnt == N//2:
        cnt = len(list(range(Y[i],Y[i+1])))
        break
    elif cnt > N//2:
        cnt = 0
        break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
d=list(map(int, input().split()))
C=N//2
for x in reversed(range(1,N+1)):
    for y in range(0,x-1):
        if d[y]<d[y+1]:
            t=d[y]
            d[y]=d[y+1]
            d[y+1]=t
if d[C]==d[C-1]:
    print(0)
else:
    print(d[C-1]-d[C])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d = list(map(int, input().split()))
d.sort()
k_count = 0
for i in range(len(d)):
    arc = len(list(filter(lambda x: x > d[i], d)))
    abc = len(list(filter(lambda x: x <= d[i], d)))
    if arc == abc:
        k_count += (d[i+1] - d[i])
print(k_count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
p = list(map(int, input().split(" ")))
a = 0
for r in range(min(p) - 1, max(p)+1):
    abc = list(filter(lambda x: x < r, p))
    arc = list(filter(lambda x: x >= r, p))
    if len(abc) == len(arc) :
        a += 1
print(a)

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    import numpy as np
    N = int(input())
    D = sorted(list(map(int, input().split())))
    d = np.array(D)
    idx = len(D) // 2
    ans = 0
    for i in range(d[idx - 1], d[idx]+1):
        if len(d[d < i]) == len(d[d >= i]):
            ans += 1
    print(ans)

resolve()

Submission status: Time Limit Exceeded

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

rates = sorted(list(set(D)))
counter = [0] * len(rates)
for d in D:
    counter[rates.index(d)]+=1

acc = 0
found = False
for i in range(len(counter)):
    acc += counter[i]
    if acc == N/2:
        found = True
        break
    if acc > N/2:
        found = False
        break

if found == False:
    print(0)
else:
    print(rates[i+1]-rates[i])

Submission status: Time Limit Exceeded

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


num =0
for i in range(max(l)+1):
    s =0
    u =0
    for j in l:
        if j <i:
            s +=1
        else:
            u +=1
    if s ==u:
        num +=1
print(num)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d = list(int(x) for x in input().split())

ans = 0

for k in range(1, max(d) + 1):
    arc_num = 0
    abc_num = 0
    for i in range(n):
        if d[i] >= k:
            arc_num += 1
        else:
            abc_num += 1
    if arc_num == abc_num:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
def resolve():
    N = int(input())
    d = [int(i) for i in input().split()]
    d = np.array(d)
    count = 0
    for i in range(100000):
        if (np.where(d >= i)[0].size == np.where(d < i)[0].size):
            count += 1
    print(count)
resolve()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
D=list(map(int,input().split()))
D.sort()
for i in range(1, n):
    l = D[:i]
    r = D[i:]
    if len(l) == len(r):
        ans = r[0] - l[-1]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
q = list(map(lambda x:int(x),input().split()))
a = max(q)
b = min(q)
cnt = 0
for d in range(b,a+1):
    ARC = 0
    ABC = 0
    for qq in q:
        if qq >= d : ARC += 1
        else: ABC += 1
    if ARC == ABC:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

n=int(input())
d = list(map(int,input().split()))
cnt=0

d.sort()
a=d[0]
b=d[n-1]
c=b-a+1

for i in range(c):
    index=bisect.bisect_right(d,i+a)
    D=d[index:]
    lend=len(D)
    if(int(n//2)==lend):
        cnt+=1
    

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
d=list(map(int, input().split()))
C=N//2
for x in range(0,N):
    for y in range(0,N-1):
        if d[y]<d[y+1]:
            t=d[y]
            d[y]=d[y+1]
            d[y+1]=t
    N=N-1
if d[C]==d[C-1]:
    print(0)
else:
    print(d[C-1]-d[C])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d = list(map(int, input().split()))
way = 0
for k in range(1,max(d)+1):
    arc = 0
    abc = 0
    for di in d:
        if di >= k:
            arc += 1
        else:
            abc += 1
    if arc == abc:
        way += 1
print(way)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d_lis = [int(d) for d in input().split()]
cnt = 0
ans = 0
for i in range(max(d_lis)+1):
    cnt += d_lis.count(i)
    if cnt == n // 2:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d = list(map(int,input().split()))
d = sorted(d)
length = len(d) // 2
count = 0
for k in range(d[length - 1], d[length] + 1):
    min = sum(x<k for x in d)
    max = sum(x>=k for x in d)
    if min == max:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d = list(map(int, input().split()))
k_count = 0
for i in range(min(d), max(d)):
    arc = len(list(filter(lambda x: x > i, d)))
    abc = len(list(filter(lambda x: x <= i, d)))
    if arc == abc:
        k_count += 1
print(k_count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
d=list(map(int, input().split()))
B=N
for x in range(0,N):
    for y in range(0,N-1):
        if d[y]<d[y+1]:
            t=d[y]
            d[y]=d[y+1]
            d[y+1]=t
    N=N-1
C=B//2
if d[C]==d[C-1]:
    print(0)
if d[C]!=d[C-1]:
    print(d[C-1]-d[C])

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
suu=(N/2)-1
d=list(map(int,input().split()))
for n in range(round(suu)):
    s=d.index(max(d))
    d.pop(s)
dai=max(d)
s=d.index(max(d))
d.pop(s)
syo=max(d)
print(dai-syo)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d = list(map(int, input().split()))
ans = 0

for i in range(max(d)):
    low = len([x for x in d if x > i])
    if low == n - low:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
d = list(map(int,input().split()))
count = 0
for k in range(1, 10**5):
    min = sum(x<k for x in d)
    max = sum(x>=k for x in d)
    if min == max:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import copy


def main():
    N = int(input())
    ds = list(map(int, input().split()))
    ds = np.array(ds, dtype=np.int)
    ans = 0
    for K in range(int(np.max(ds))+1):
        if np.sum(ds >= K) == N // 2:
            ans += 1
    print(int(ans))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

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

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

import numpy as np
N = int(input())
d = LI()
d.sort()
cnt_k = np.array([0 for i in range(max(d))])

for i in range(N):
    cnt_k[:d[i]] += 1

print(np.count_nonzero(cnt_k==N//2))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
#ABC132 C

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

ans = 0
for i in range(min(d),max(d)):
    s = 0
    t = 0
    for j in range(N):
        if d[j] <= i:
            s += 1
        else:
            t += 1
        if s > N//2:
            break
        if t > N//2:
            break
    if s == t:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
d=sorted([int(i) for i in input().split()])
dif=[0]*d[-1]
for i in d:
    dif[i-1]+=1
SUM=sum(dif)
ans=0
for i in range(n-1):
    S=sum(dif[:d[i]])
    if S==SUM-S:
        ans+=d[i+1]-d[i]
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
d=list(map(int,input().split()))
d.sort()
m=n//2
print(d[m]-d[m-1])

Submission status: Accepted

Solution code:
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase


def main() -> None:
    input()
    arr = list(map(int, input().split()))

    cnt = [0] * (10 ** 5 + 10)
    for i in arr:
        cnt[i] += 1

    for i in range(len(cnt) - 2, -1, -1):
        cnt[i] += cnt[i+1]

    print(cnt.count(len(arr) // 2))

# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self, **kwargs):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
dlist=list(map(int,input().split()))
dlist.sort()
print(dlist[(N+1)//2]-dlist[(N-1)//2])

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
a.sort()
half = int(len(a)/2)
if a[half-1] == a[half]:
  print(0)
else:
  print(a[half]-a[half-1])

Submission status: Accepted

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

left = D[N // 2 - 1]
right = D[N // 2]

print(right - left)

Submission status: Accepted

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

d.sort()
c = int(len(d) / 2)
l = d[:c]
r = d[c:]
print(r[0] - l[-1])

Submission status: Accepted

Solution code:
N = int(input())
d = sorted([int(i) for i in input().split()])
print(d[N//2] - d[(N//2)-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#ABC132 C

N = int(input())
D = list(map(int,input().split()))
D.sort()
A = list(range(D[int(N/2)-1]+1,D[int(N/2)]+1))

print(len(A))

Submission status: Accepted

Solution code:
n = int(input())
d = list(map(int,input().split()))
s = sorted(d)
t = n//2
print(s[t]- (s[t-1]+1)+1)

Submission status: Accepted

Solution code:
n = int(input())
d = sorted(map(int, input().split()))
k1 = d[int(n/2)-1]+1
k2 = d[int(n/2)]
print(k2-k1+1)

Submission status: Accepted

Solution code:
#import math
#import itertools
#import numpy as np
#from collections import deque
# sys.setrecursionlimit(10 ** 6)
#MOD = 10 ** 9 + 7
#INF = 10 ** 9
#PI = 3.14159265358979323846

INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))

def do():
    n=INT()
    A=LIST()
    A=sorted(A)
    print(A[n//2]-A[n//2-1])
if __name__=='__main__':
    do()

Submission status: Accepted

Solution code:
N  = int(input())
nums = list(map(int,input().split()))
nums.sort()
cnt = nums[N//2] - nums[N//2-1] 
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
d = list(map(int, input().split()))
d.sort()
print(len(range(d[n//2-1],d[n//2])))

Submission status: Accepted

Solution code:
n=int(input())
d=sorted(list(map(int,input().split())))
ans=d[n//2]-d[n//2-1]
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left

n=int(input())
d=list(map(int,input().split()))
d=sorted(d)
ans=0

for i in range(1,10**5+1):
  p=bisect_left(d,i)
  ans+=1 if p==(n-p) else 0

print(ans)

Submission status: Accepted

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

print(D[N//2] - D[N//2-1])

Submission status: Accepted

Solution code:
n=int(input())
arr=list(map(int, input().rstrip().split()))
arr.sort()

if arr[n//2-1] == arr[n//2]:
  print(0)
else:
  print(arr[n//2]-arr[n//2-1])

Submission status: Accepted

Solution code:
N = int(input())
d = list(map(int, input().split()))
p = [0] * N
for i in range(N):
    p[i] = (d[i], i)
p.sort()
result = abs(p[N//2][0] - p[N//2-1][0])
# print(p)
print(result)

Submission status: Accepted

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

d.sort()
print(d[n//2]-d[n//2-1])

Submission status: Accepted

Solution code:

def main():

    N = int(input())
    d = [int(i) for i in input().split()]
    d.sort()
    n = N // 2
    print(d[n] - d[n-1])

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())
d=list(map(int,input().split()))
 
d.sort()
 
print(d[n//2]-d[n//2-1])

Submission status: Accepted

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

D.sort()

if N % 2 == 1:
    print(0)
else:
    M = N //2
    res = D[M] - D[M-1]
    print(res)

Submission status: Accepted

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

d.sort()

print(d[n//2]-d[n//2-1])

Submission status: Accepted

Solution code:
n = int(input())
d = list(map(int,input().split()))
d = sorted(d)
n2 = int(n/2)
if d[n2] == d[n2 - 1]:
    print(0)
else:
    print(d[n2] -d[n2 - 1])

Submission status: Accepted

Solution code:
n = int(input())
d = list(map(int,input().split()))
d.sort()
abc = d[n//2-1]
arc = d[n//2]
if abc == arc:
    ans = 0
else:
    ans = arc - abc
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
d = sorted(list(map(int, input().split())))
print(d[N//2]-d[N//2-1])

Submission status: Accepted

Solution code:
n = int(input())
dlst = list(map(int, input().split()))
dlst.sort()
abc_max = dlst[n // 2 - 1]
arc_min = dlst[n // 2]
print(arc_min - abc_max)

Submission status: Accepted

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

Submission status: Accepted

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

d.sort()
print(d[N // 2] - d[N // 2 - 1])