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

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

def swap(a,i,j):
  c = a[i]
  d = a[j]
  if a[i]>a[j]:
    a[j] = c
    a[i] = d
  return a

for i in range (int(n/2)+1):
  for j in range (i+1,n):
    swap(a,i,j)
    
print(a[int(n/2)+1]-a[int(n/2)])

Submission status: Runtime Error

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

def swap(a,i,j):
  c = a[i]
  d = a[j]
  if a[i]>a[j]:
    a[j] = c
    a[i] = d
  return a

for i in range (int(n/2)+1):
  for j in range (i+1,n):
    swap(a,i,j)
    
print(a[int(n/2)+1]-a[int(n/2)])

Submission status: Runtime Error

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

def swap(a,i,j):
  c = a[i]
  d = a[j]
  if a[i]>a[j]:
    a[j] = c
    a[i] = d
  return a

for i in range (n/2+1):
  for j in range (i+1,n):
    swap(a,i,j)
    
print(a[n/2+1]-a[n/2])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
from operator import mul
from functools import reduce

def comb(n, r):
  r = min(r, n-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, k = map(int, input().split())
mod = 10**9+7

for i in range(1, k+1):
  if i <= n-k+1:
    ans = comb(n-k+1, i) * comb(k-1, i-1)
    ans %= mod
  else:
    ans = 0
  print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
a = list(map(int, input().split())) 　
arc=[]
abc=[]
int ans=0
int j=0
for j in max(a):
    for i in a:
        if(i<j) :
            abc.append(i)
        else:
            arc.append(i)
    
        if(len(arc)==len(abc)):
            ans ++
print(ans)

Submission status: Runtime Error

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


ans = p[int(n/2)] - [int(n/2)-1]
print(ans)

Submission status: Runtime Error

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

if len(d) % 2 != 0:
    print(0)
else:
    print(d[len(d) / 2])

Submission status: Runtime Error

Solution code:
 N = int(input())
 d = list(map(int, input().split()))
""" 
d = [9, 1, 4, 4, 6, 7]
#N = 8
N = 6
#d = [9, 1, 14, 5, 5, 4, 4, 14]
d = [9, 1, 4, 4, 6, 7]
 """
# prob
# [number,value]
prob = []
cnt = 0
for i in d:
    prob.append([cnt, i])
    cnt += 1

""" print(prob)
print(sorted(prob, key=lambda x: x[1]))
 """
sorted_d = sorted(prob, key=lambda x: x[1])

d_max = sorted_d[N-1][1]
d_min = sorted_d[0][1]
#print(d_min, d_max)

cnt = 0
for i in range(N):
    """ print(sorted_d[0:i])
    print(sorted_d[i:])
 """
    if len(sorted_d[0:i]) == len(sorted_d[i:]):
        """ print("True")
        print(sorted_d[i][1])
        print(sorted_d[i-1][1])
        print(sorted_d[i][1] - sorted_d[i-1][1])
         """
        cnt += sorted_d[i][1] - sorted_d[i-1][1]
    # print("------")

print(cnt)

Submission status: Runtime Error

Solution code:
    def q38(n, d):
        max_d = max(d)
        min_d = min(d)
        count = 0
        for i in range(min_d+1, max_d):
            a = []
            b = []
            for j in d:
                if j >= i:
                    a.append(j)
                else:
                    b.append(j)
            if len(a) == len(b):
                count += 1
        return count
     
  N = int(input())
  d = [int(i) for i in input().split()]
  print(q38(N, d))

Submission status: Runtime Error

Solution code:
def q38(n, d):
    max_d = max(d)
    min_d = min(d)
    count = 0
    for i in range(min_d+1, max_d):
        a = []
        b = []
        for j in d:
            if j >= i:
                a.append(j)
            else:
                b.append(j)
        if len(a) == len(b):
            count += 1
    return count
N = int(input())
d = [int(i) for i in input.split()]
print(q38(N, d))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
d = [int(x) for x in input().split()]
d.sort()
print(d[int(n / 2) + 1] - d[int(n / 2)])

Submission status: Runtime Error

Solution code:
N = input()


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

ls_sorted = sorted(ls)

K = ls_sorted[N//2] - ls_sorted[N//2 - 1]

print(K)

Submission status: Runtime Error

Solution code:
N = input()

if N/2 %2 != 0:
    print(0)

else:
    ls = list(map(int, input().split()))

    ls_sorted = sorted(ls)

    K = ls_sorted[N/2] - ls_sorted[N/2 - 1]

    print(K)

Submission status: Runtime Error

Solution code:
N = input()

if N/2 %2 != 0:
    print '0'

else:
    ls = list(map(int, input().split()))

    ls_sorted = sorted(ls)

    K = ls_sorted[N/2] - ls_sorted[N/2 - 1]

    print(K)

Submission status: Runtime Error

Solution code:
a = sorted(list(map(int, input().split())))
print(a[len(a)] - a[len(a)-1])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

ans = ps[n/2] - ps[n/2-1]
print(ans)

Submission status: Runtime Error

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

c_idx = n / 2 - 1
l.sort()
print(l[c_idx + 1] - l[c_idx])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np

def count_ABC_num(D, thr):
    return len([_ for _ in D if _ < thr])


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

D = np.sort(np.array(D))
cent_index = int(len(D)/2)

print(len([threshold for threshold in range(D[cent_index - 1], D[cent_index + 1] + 1) if count_ABC_num(D, threshold) == cent_index]))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
d_s=input().split()
d_i=[int(x) for x in d_s]
d=sorted(d_i)
k=d[n/2]
t=d[n/2-1]
print(k-t)

Submission status: Runtime Error

Solution code:
n = int(input())
d = list(map(int,input().split()))
k = max(d)
i,j,ans,b,s = 0
while i <= k:
  while j <= n-1:
    if d[j] <= i:
      b += 1
    if d[j] > i:
      s += 1
  if b == s:
    ans += 1
  i += 1
print(ans)

Submission status: Runtime Error

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

count = 0
cur = 0
for i in range(10**5 + 1):
    if cur == N / 2:
        count += 1
    if cur > N / 2:
        break
    if D[cur] < i and cur < N:
        cur += 1
        while D[cur - 1] == D[cur]:
            cur += 1
print(count)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
N = int(input())
L = list(map(int,input().split()))
 
L.sort()
 
target_num = int(N/2)
if L[target_num-1] = L[target_num]:
	ans = 0
else:
  	ans= L[target_num]-L[target_num-1]

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
L = list(map(int, input().split()))
 
L_sorted= L.sort()
 
target_num = int(N/2)
if L_sorted[target_num-1] = L_sorted[target_num]:
	ans = 0
else:
  	ans= L_sorted[target_num]-L_sorted[target_num-1]

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
L = list(map(int, input().split()))
 
L_sorted= L.sort()
 
target_num = N/2
if L_sorted[target_num-1] = L_sorted[target_num]:
	ans = 0
else:
  	ans= L_sorted[target_num]-L_sorted[target_num-1]

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

L_sorted= L.sort()

target_num = N/2
if L_sorted[target_num-1] = L_sorted[target_num]
	print(0)
else:
  	print(L_sorted[target_num]-L_sorted[target_num-1])

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
  z = int(input())
  if 10000 >= z and z >= 2 and z%2==0:
    rank_list = list(map(int, input().strip().split()))
    if  10000 >= rank_list and rank_list >= 1:
      rank_sort = sorted(rank_list)
      num = int(len(rank_sort)/2)
      arc = rank_sort[:num]
      abc = rank_sort[num:]
      dif = min(abc) - max(arc)
      if len(arc) == len(abc):
          print(min(abc) - max(arc))

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
  z = int(input())
  if 10000 >= z and z >= 2 and z%2==0:
    rank_list = list(map(int, input().strip().split()))
    if  10000 >= rank_list and z >= rank_list:
      rank_sort = sorted(rank_list)
      num = int(len(rank_sort)/2)
      arc = rank_sort[:num]
      abc = rank_sort[num:]
      dif = min(abc) - max(arc)
      if len(arc) == len(abc):
          print(min(abc) - max(arc))

Submission status: Runtime Error

Solution code:
N=int(input())
d=[int(input().sprit())]
d.sort()
print(d[N]-d[N-1])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

n1 = d_list[N//2]
print(d_list[n1 + 1] - d_list[n1])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())

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

D2 = sorted(D)
A = D2[N//2]
B = D2[N//2+1]
print(abs(A-B))

Submission status: Runtime Error

Solution code:
N=int(int(input())/2)
N-=(N+1)%2
a=sorted(input().split())
print(int(a[N+1])-int(a[N]))

Submission status: Runtime Error

Solution code:
N=int(int(input())/2)
a=sorted(input().split())
print(int(a[N+1])-int(a[N]))

Submission status: Runtime Error

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

d.sort()

left = d[int(N/2)]
right = d[int(N/2) +1]

dif = right - left

print(dif)

Submission status: Runtime Error

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

d.sort()

left = d[N//2]
right = d[N//2 +1]

dif = right - left

print(dif)

Submission status: Runtime Error

Solution code:
N = int(input()) / 2
a = input().split()

if a[N] == a[N + 1]:
    print(0)
else:
    print(int(a[N+1]) - int(a[N]))

Submission status: Runtime Error

Solution code:
N = int(input()) / 2
a = input().split()

if a[N] == a[N + 1]:
    print(0)
else:
    print(a[N+1] - a[N])

Submission status: Runtime Error

Solution code:
N = int(input())
d = list(map(int,input().split()))
dunder = 0
count = 0
for i in range():
    dunder = sum (x<i for x in d)
    if 2*dunder == len(d):
        count += 1
    elif 2*dunder > len(d):
        break
print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = input()
l = sorted[int(x) for x in raw_input().split()]
print l[n/2] - l[n/2-1]

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s=list(input())
k=int(input())
s.append(-1)
i=0
ans=-1
while True:
    if s[i]=="-1":
        ans=s[i]
        break
    if s[i]!="1":
        ans=s[i]
        if i+1>k:
            ans="1"   
        break
    i+=1
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def quick_sort(arr):
    left = []
    right = []
    if len(arr) <= 1:
        return arr
 
    # データの状態に左右されないためにrandom.choice()を用いることもある。
    # ref = random.choice(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
n=input()
S=map(int,input().split())
S=quick_sort(S)
word=int(int(n)/2)
s=int(S[word])-int(S[word-1])
s2=int(S[word+1])-int(S[word])
print(s)

Submission status: Runtime Error

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

a = len(d)/2
l = d[a+1] - d[a]

print(l)

Submission status: Runtime Error

Solution code:
#coding:utf-8
N = int(input())
D = list(map(int,input().split()))
D = sorted(D)
idx = len(D) // 2
print(D[idx] - D[odx-1])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

n=int(input())
t =list(map(int, input().split()))
counter=0

ans=0
t.sort()

half=t//2

ans=t[half]-t[half-1]

Submission status: Runtime Error

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

if(len(d)%2!=0):
    print(0)
else: 
    print(d[int(len(d)/2)+1]-d[int(len(d)/2)])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
d_lis = [int(d) for d in input().split()]
ans = 0
c = 0
li = sorted(li)
for a in set(li):
    if a > li[n // 2] and a <= li[(n // 2) + 1]:
        b = a
        c = 1
if c == 1:
    ans = li[(n // 2) + 1] - b + 1
    print()

Submission status: Runtime Error

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

if(len(d)%2!=0):
    print(0)
else: 
    print(d[int(len(d)/2)+1]-d[int(len(d)/2)])

Submission status: Runtime Error

Solution code:
N=input()
m=N/2
D=[int(i) for i in input().split()]
p=m

while P=0:
	for i in range(m+1):
		if D[i]>D[i+1]:
			D[i]=D[i+1]
			P=M-1


print(int(D[m+1]-D[m]))

Submission status: Runtime Error

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

if(len(d)%2!=0):
    print(0)
else: 
    print(d[int(len(d)/2)+1]-d[int(len(d)/2)])

Submission status: Runtime Error

Solution code:
n = int(input())
d = list(map(int,input().split()))
p = 0
q = 0
m = 0
d.sort()
if (len(d)%2) == 0:
  m = (d[(len(d)//2)-1]+d[len(d)//2])/2
else:
  m = d[(len(d)//2)]
for i in range(len(d)):
  if d[i]>=m:
    if d[i] == d[i+1]:
      p = d[i]
      q = d[i+1]
    else:
      p = d[i]
      q = d[i-1]
      break
print(p-q)

Submission status: Runtime Error

Solution code:
import numpy as np
import collections


def func2(c):
  cs = sorted(c)
  col = collections.Counter(c)

  cc = 0
  if len(col)%2 == 1: return 0;

  half = int(len(c)/2)
  hoge = (cs[half+1]- cs[half-1])
  return hoge
  

a = input()
b = map(int,input().split())
c =[]
for x in b:
	c.append(x)

print(func2(c))

Submission status: Runtime Error

Solution code:
n = int(input())
d = list(map(int,input().split()))
p = 0
q = 0
m = 0
d.sort()
if (len(d))%2 == 0:
  m = (d[(len(d)//2)-1]+d[len(d)//2])/2
else:
  m = d[(len(d)//2)]
for i in range(len(d)):
  if d[i]>=m:
    if d[i] == d[i+1]:
      p = d[i]
      q = d[i+1]
    else:
      p = d[i]
      q = d[i-1]
      break
print(p-q)

Submission status: Runtime Error

Solution code:
n = int(input())
d = list(map(int,input().split()))
p = 0
q = 0
m = 0
d.sort()
if (len(d))%2 == 0:
  m = (d[(len(d)//2)-1]+d[len(d)//2])/2
else:
  m = d[(len(d)//2)]
for i in range(len(d)):
  if d[i]>=m:
    if d[i] == d[i+1]:
      p = d[i]
      q = d[i-1]
    else:
      p = d[i]
      q = d[i-1]
      break
print(p-q)

Submission status: Runtime Error

Solution code:
def _quick_sort(array, left, right):
    if left >= right: return

    # ピボットを決定
    pivot = median(array[left], array[(left + (right - left) // 2)], array[right])
    l = left
    r = right

    # ピボットを中心に分ける
    while True:
        # ピボットより小さい値を左、大きい値を右に移動する
        while array[l] < pivot:
            l += 1
        while pivot < array[r]:
            r -= 1
        if (r <= l): break

        # 見つかった要素を交換
        tmp = array[l]
        array[l] = array[r]
        array[r] = tmp
        l += 1
        r -= 1

    # 左右に分けた部分を再帰的にクイックソート
    _quick_sort(array, left, l - 1)
    _quick_sort(array, r + 1, right)

def quick_sort(array):
    _quick_sort(array, 0, len(array)-1)

def median(x, y, z):
    if x < y:
        return (y if y < z else z) if x < z else x
    else:
        return (x if x < z else z) if y < z else y

n=input()
S=[]
for i in input().split():
    S.append(int(i))
S=quick_sort(S)
word=int(int(n)/2)
s=int(S[word])-int(S[word-1])
s2=int(S[word+1])-int(S[word])
print(s)

Submission status: Runtime Error

Solution code:
def _quick_sort(array, left, right):
    if left >= right: return

    # ピボットを決定
    pivot = median(array[left], array[(left + (right - left) // 2)], array[right])
    l = left
    r = right

    # ピボットを中心に分ける
    while True:
        # ピボットより小さい値を左、大きい値を右に移動する
        while array[l] < pivot:
            l += 1
        while pivot < array[r]:
            r -= 1
        if (r <= l): break

        # 見つかった要素を交換
        tmp = array[l]
        array[l] = array[r]
        array[r] = tmp
        l += 1
        r -= 1

    # 左右に分けた部分を再帰的にクイックソート
    _quick_sort(array, left, l - 1)
    _quick_sort(array, r + 1, right)

def quick_sort(array):
    _quick_sort(array, 0, len(array)-1)

def median(x, y, z):
    if x < y:
        return (y if y < z else z) if x < z else x
    else:
        return (x if x < z else z) if y < z else y

n=input()
S=[]
for i in input().split():
    S.append(int(i))
S=quick_sort_(S)
word=int(int(n)/2)
s=int(S[word])-int(S[word-1])
s2=int(S[word+1])-int(S[word])
print(s)

Submission status: Runtime Error

Solution code:
def quick_sort_with_count(arr):
    left = []
    right = []
    if len(arr) <= 1:
        return arr
    ref = choice(arr)
    ref_count = 0

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

    if len(left) <= 1000:
        left = count_sort(left)
    else:
        left = quick_sort_with_count(left)

   if len(right) <= 1000:
        right = count_sort(right)
    else:
        right = quick_sort_with_count(right)

    return left + [ref] * ref_count + right
n=input()
S=[]
for i in input().split():
    S.append(int(i))
S=quick_sort_with_count(S)
word=int(int(n)/2)
s=int(S[word])-int(S[word-1])
s2=int(S[word+1])-int(S[word])
print(s)

Submission status: Runtime Error

Solution code:
import bisect

n = int(input())
d = list(int(x) for x in input().split())
d.sort()

ans = 0

for k in range(min(d), d[(n // 2) + 1]):
    idx = bisect.bisect_left(d, k)
    if idx == n // 2:
        ans += 1

print(ans)

Submission status: Runtime Error

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

n=input()
S=[]
for i in input().split():
    S.append(int(i))
S=merge_sort(S)
word=int(int(n)/2)
s=int(S[word])-int(S[word-1])
s2=int(S[word+1])-int(S[word])
print(s)

Submission status: Runtime Error

Solution code:
def quick_sort(arr):
    left = []
    right = []
    if len(arr) <= 1:
        return arr

    # データの状態に左右されないためにrandom.choice()を用いることもある。
    # ref = random.choice(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

n=input()
S=[]
for i in input().split():
    S.append(int(i))
S=quick_sort(S)
word=int(int(n)/2)
s=int(S[word])-int(S[word-1])
s2=int(S[word+1])-int(S[word])
print(s)

Submission status: Runtime Error

Solution code:
a = input()
b = input()

from heapq import nsmallest

m = int(-(a/2))
s = int(a/2)

n = int(a)
p = list(map(int, b.split()))

m2 = sorted(p)[m]
s2 = nsmallest(s, p)[-1]

print(m2-s2)

Submission status: Runtime Error

Solution code:
n = int(input())
d = list(map(int,input().split()))
p = 0
q = 0
d.sort(key=int)
if (len(d))%2 == 0:
  m = (d[(len(d)//2)-1]+d[len(d)//2])/2
else:
  m = d[(len(d)//2)]
for i in range(len(d)):
  if d[i]>=m:
    if d[i] == d[i+1]:
        p = d[i]
        q = d[i+1]
        break
    else:
      p = d[i]
      q = d[i-1]
      break
print(p-q)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import bisect

n = int(input())
d = list(int(x) for x in input().split())
d.sort()

ans = 0

for k in range(min(d), d[(n // 2) + 1]):
    idx = bisect.bisect_left(d, k)
    abc_num = idx
    arc_num = n - abc_num
    if arc_num == abc_num:
        ans += 1

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def quick_sort(arr):
    left = []
    right = []
    if len(arr) <= 1:
        return arr

    # データの状態に左右されないためにrandom.choice()を用いることもある。
    # ref = random.choice(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

n=input()
S=list(input().split())
for i in S:
    i=int(i)
S=quick_sort(S)
word=int(int(n)/2)
s=int(S[word])-int(S[word-1])
s2=int(S[word+1])-int(S[word])
print(s)

Submission status: Runtime Error

Solution code:
n = int(input())
d = list(map(int,input().split()))
p = 0
q = 0
d.sort(key=int)
if (len(d))%2 == 0:
  m = (d[(len(d)//2)-1]+d[len(d)//2])/2
else:
  m = d[(len(d)//2)]
for i in range(len(d)):
  if d[i]>=m:
    if d[i] == d[i+1]:
      break
    else:
      p = d[i]
      q = d[i-1]
      break
print(p-q)

Submission status: Runtime Error

Solution code:
def quick_sort(arr):
    left = []
    right = []
    if len(arr) <= 1:
        return arr

    # データの状態に左右されないためにrandom.choice()を用いることもある。
    # ref = random.choice(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

n=input()
S=list(input().split())
for i in S:
    i=int(i)
S=quick_sort(S)
word=int(int(n)/2)
print(S)
s=int(S[word])-int(S[word-1])
s2=int(S[word+1])-int(S[word])
print(s)

Submission status: Runtime Error

Solution code:
n = int(input())
d = list(map(int,input().split()))
p = 0
q = 0
d.sort(key=int)
if (len(d))%2 == 0:
  m = (d[(len(d)//2)-1]+d[len(d)//2])/2
else:
  m = d[(len(d)//2)]
for i in range(len(d)):
  if d[i]>=m:
    if d[i] == d[i+1]:
      break
    else:
      p = d[i]
      q = d[i-1]
      break
print(p-q)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from scipy.special import comb
n = int(input())
List = list(map(int, input().split()))
List.sort()
idx = n // 2
ans = List[idx]-List[idx-1]
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
d = [int(i) for i in input().split()]
d.sort()
s=0
N=int(n/2)
k=int(abs(d[N]-d[N-1]))
K=(d[N]+d[N-1])/2)
for i in range(n):
    if d[i]>=K:
        s=s+1
    else:
        s=s
if s==N:
    print(k)
else:
    print(0)

Submission status: Runtime Error

Solution code:
cnt = int(input())
in_str = [int(i) for i in input().split()]
in_str.sort()
print(in_str[cnt//2+1] - in_str[cnt // 2])

Submission status: Runtime Error

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

ans = 0

for k in range(min(d), d[(n // 2) + 1]):
    arc_num = 0
    abc_num = 0
    
    for i in range(n):
        if d[i] >= k:
            break
        else:
            abc_num += 1
    arc_num = n - abc_num
    if arc_num == abc_num:
        ans += 1

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

t = d.sort()

a = t[(n/2)-1]
b = t[(n/2)]

print(b-a)

Submission status: Runtime Error

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

l = int(a/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: Runtime Error

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

l = int(a/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: Runtime Error

Solution code:
n = int(input())
d = list(map(int,input().split()))
p = 0
q = 0
m = 0
a = 0
d.sort()
if (len(d))%2 == 0:
  m = int(((d[(len(d)//2)-1])+(d[len(d)//2]))/2)
else:
  m = int(d[(len(d)//2)])
for i in range(len(d)):
  if int(d[i])>=m:
    if int(d[i]) == int(d[i+1]):
      break
    else:
      p = int(d[i])
      q = int(d[i-1])
      break
  else:
    a = 0
print(p-q)

Submission status: Runtime Error

Solution code:
N = int(input())
if N % 2 == 1:
  print("0")
else:
  lis = input().split()
  lis.sort()
  if lis[int(N / 2 - 1)] == lis[int(N / 2)]:
    print("0")
  else:
    ans = []
    for i in range(int(lis[int(N / 2)]), int(lis[int(N / 2 + 1)])): 
      ans.append(i)
    print(len(ans))

Submission status: Runtime Error

Solution code:
N = int(input())
D = list(map(int, input().split()))
cnt = 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: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
D = list(map(int, input().split()))
 
D = sorted(D)
max_ = max(D)
min_ = min(D)
 
middle_idx = len(D)//2
print("mi", middle_idx)
diff = D[middle_idx+1] - D[middle_idx]
print(diff)

Submission status: Runtime Error

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

Submission status: Runtime Error

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+1]):
  if len([j for j in p if j > i]) == (n//2):
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
d = list(map(int,input().split()))
p = 0
q = 0
m = 0
a = 0
d.sort()
if (len(d))%2 == 0:
  m = ((d[(len(d)//2)-1])+(d[len(d)//2]))/2
else:
  m = d[(len(d)//2)]
for i in range(len(d)):
  if d[i]>=m:
    if d[i] == d[i+1]:
      break
    else:
      p = d[i]
      q = d[i-1]
      break
  else:
    a = 0
print(p-q)