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: Accepted

Solution code:
import sys

n = int(input())
d = list(map(int, input().split()))
dic = {}
val = 0

for i in range(n):
    if d[i] in dic.keys():
        dic[d[i]] += 1
    else:
        dic[d[i]] = 1

dic = sorted(dic.items())

if len(dic) == 1:
    print(0)
    sys.exit() 

for i in range(len(dic) - 1):
    val += dic[i][1]
    if val == n//2:
        ans = (dic[i][0], dic[i+1][0])
        print(ans[1] - ans[0])
        break
    elif val > n//2:
        print(0)
        break

Submission status: Accepted

Solution code:
n = int(input())
l = sorted([int(i) for i in input().split()])
a = n//2
b = a -1

print(l[a]-l[b])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
A.sort()
print(A[N//2] - A[N//2 - 1])

Submission status: Accepted

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

if d[int(n/2)] != d[int(n/2) - 1]:
  print(d[int(n/2)] - d[int(n/2) - 1])
elif d[int(n/2)] == d[int(n/2) - 1]:
  print(0)

Submission status: Accepted

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

if len(li)%2 == 1:
    print(0)
elif len(li)%2 == 0:
    l = li[len(li)//2-1]
    r = li[len(li)//2]
    print(r-l)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n =  int(input())
strr = input()

if n &1:
	print(0)
else:
	arr = list(map(int, strr.split()))

	arr.sort()
	mr = arr[n//2]
	ml = arr[(n//2)-1]
	print(mr-ml)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
d_list = list(map(int, input().split()))
level_count_dic = {}
mid = int(n/2)
flag = True

for d in d_list:
    if d in level_count_dic:
        level_count_dic[d] += 1
    else:
        level_count_dic[d] = 1

sorted_level_count_dic = sorted(level_count_dic.items(), key=lambda x:x[0])

abc_count = 0
abc_max = 0

for k, v in sorted_level_count_dic:
    abc_count += v

    if abc_count == mid:
        abc_max = k+1
        break
    elif abc_count > mid:
        flag = False
        break


if flag:
    ans = 0
    while True:
        ans += 1
        if abc_max in level_count_dic:
            break
        abc_max += 1

    print(ans)
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
from copy import deepcopy
from collections import deque
sys.setrecursionlimit(20000000)


def main():
    S = int(input())
    nums = list(map(int, input().split()))
    nums.sort()

    print(nums[int(S/2)] - nums[int(S/2 - 1)])


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = d[int(N/2)] - d[int(N/2)-1]

print(ans)

Submission status: Accepted

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

d.sort()
ans = d[len(d) // 2] - d[len(d) // 2 - 1]
print(ans)

Submission status: Accepted

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

d = sorted(d)
l, r = d[n//2-1], d[n//2]
print(r-l)

Submission status: Accepted

Solution code:
import math
N = int( input() )
d = list( map( int, input().split() ) )
d = sorted(d)
c = N * 0.5
if math.ceil(c) != math.floor(c):
    print(0)
    exit()
print( d[int(c)] - d[int(c-1)] )

Submission status: Accepted

Solution code:
n = input()
a = sorted([int(x) for x in input().split(' ')])
d = int(len(a)/2)

print(len(range(a[d-1], a[d])))

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(e[n//2-1],e[n//2]+1):
  if e[n//2-1] < i and i <= e[n//2]:
    cnt = cnt + 1
  
print(cnt)

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)
ans = d[N//2]-d[N//2-1] 
print(ans)

Submission status: Accepted

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

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

if len(ds) % 2 == 0:
    ds.sort()

    mid = math.floor(len(ds)/2)

    print(ds[mid]-ds[mid-1])
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

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

d = sorted(d)
half = int(n / 2)
ans = d[half] - d[half - 1]
print(ans)

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())
d = list(map(int, input().split()))

d.sort()

abc = d[n//2 - 1]
agc = d[n//2]

if agc == abc:
    print(0)
else:
    print(agc-abc)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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: 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 = sorted(list(map(int, input().split())))

while len(d) != (N/2)+1:
    d.pop()

ans = 0
for i in range(d[-2], d[-1]):
    ans += 1
print(ans)

Submission status: Accepted

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

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
d = LI()
d.sort()
ans = d[n//2] - d[n//2 -1]
print(ans)

Submission status: Accepted

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

i = int(N / 2)
print(L[i] - (L[i - 1]))

Submission status: Accepted

Solution code:
n=int(input())
d=[int(i) for i in input().split()]
d=sorted(d)
if n%2==0:
    dmi=d[n//2-1]
    dma=d[n//2]
    ans=dma-dmi
else:
    ans=0
    
print(ans)

Submission status: Accepted

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

centerN=int(n/2)
if dList[centerN] == dList[centerN-1]:
	print(0)
else:
	print(dList[centerN] - dList[centerN-1])

Submission status: Accepted

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

halfN = N // 2
D.sort()

# print(D)
count = 0

left = D[halfN - 1]
right = D[halfN]

# print(left, right)

ans = right - left

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

if mr - ml < 1:
	print(0)
elif mr- ml ==1:
	print(1)
else:
	print(mr - ml)

Submission status: Accepted

Solution code:
import sys
from collections import Counter


n = int(input())
c = Counter(map(int, input().split()))
c = sorted(c.most_common(len(c)), key=lambda a: a[0])
total_cnt = 0
for i, (a, b) in enumerate(c):
    total_cnt += b
    if total_cnt == n // 2:
        print(c[i + 1][0] - c[i][0])
        sys.exit()
print(0)

Submission status: Accepted

Solution code:
n = int(input())
nums = sorted(map(int, input().split()))
low = nums[(n - 1) // 2]
high = nums[(n - 1) // 2 + 1]
print(high - low)

Submission status: Accepted

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

d.sort()

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = D_sorted[int(N/2)] - D_sorted[int(N/2-1)]
print(ans)

Submission status: Accepted

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

min_d=d[int(N/2-1)]
max_d=d[(int(N/2))]
ans = max_d - min_d
if ans == -1:
    ans = 0
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
r=sorted(list(map(int,input().split())))
print(0 if r[int(n/2-1)]==r[int(n/2)] else r[int(n/2)]-r[int(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])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import statistics as st
import math

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

d.sort()
#print(d)

mid = int(len(d)/2)

kmax = d[mid]
kmin = d[mid-1]

print(kmax - kmin)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
D = [int(x) for x in input().split()]
D.sort()
i = len(D) // 2
print(D[i] - D[i - 1])

Submission status: Accepted

Solution code:
import math
import copy
# import numpy as np

# ===FUNCTION===

def getInputNum():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

a = getInputNum()
b = getInputListInt()

c = sorted(b)

mean = c[int(a/2)-1]
next = c[int(a/2 + 1)-1]

ans = next - mean

print(ans)

Submission status: Accepted

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

l = int(-(-(n//2)))

print(int(d[l] - d[l-1]))

Submission status: Accepted

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

d.sort()

if d[int(N/2)]-d[int((N/2)-1)] == 0:
    print("0")
else:
    print(d[int(N/2)]-d[int((N/2)-1)])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
lst = list(map(int, input().split()))
mid = int(N/2 - 1)
lst = sorted(lst)
if lst[mid] == lst[mid+1]:
    print(0)
elif lst[mid] < lst[mid+1]:
    print(lst[mid+1]-lst[mid])

Submission status: Accepted

Solution code:
import sys

indata = sys.stdin.read().strip().splitlines()[1]
numbers = sorted(map(int, indata.split(" ")))
if len(numbers) % 2 != 0:
  print(0)
  sys.exit(0)

center = len(numbers) // 2
v1, v2 = numbers[center - 1], numbers[center]
if v1 == v2:
  print(0)
  sys.exit(0)
print(v2 - v1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

len = int(len(d))

print(d[int(len/2)] - d[int(len/2 - 1)])

Submission status: Accepted

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

Submission status: Accepted

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: Accepted

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

m = d[n // 2 - 1]
n = d[n // 2]

if m == n:
    print(0)
else:
    print(n - m)

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().strip())
D = sorted(list(map(int, input().strip().split(' '))))
print(D[int(N/2)] - D[int(N/2)-1])

Submission status: Accepted

Solution code:
n = int(input())
d = list(map(int, input().split()))
d_sort = sorted(d)
center = int(len(d) / 2)
count = 0
if d_sort[center] != d_sort[center - 1]:
  count += d_sort[center] - d_sort[center - 1]
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: UTF-8 -*-
# ABC132_C

import math

N = int(input())

inputV = input("")
arrayV = [int(n) for n in inputV.split()]
arrayV.sort()

ans = arrayV[int(N / 2)] - arrayV[int(N / 2 - 1)]

print(ans)

Submission status: Accepted

Solution code:
import bisect

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

list_d_sorted = sorted(list_d)
jugde_num = N/2

cnt =0

for i in range(1,max(list_d)+1):
    index = bisect.bisect_left(list_d_sorted,i,)
    if index ==jugde_num:
        cnt +=1
print(cnt)

Submission status: Accepted

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

d.sort()

ABCmax = d[N // 2 - 1]
ARCmin = d[N // 2]

print(ARCmin - ABCmax)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
d = [int(i) for i in input().split()]
d_dic = Counter(d)
count = 0
dp = 0
for i in range(1,max(d)+1):
    dp += d_dic[i]
    if dp == N / 2:
        count += 1
    elif dp > N / 2:
        break
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if dis ==0:
    print(0)
else:
    print(dis)

Submission status: Accepted

Solution code:
n=int(input())
readints = lambda: map(int,input().split(' '))
a=list(readints())
a.sort()
mid = n//2
x=a[mid-1]
y=a[mid]
print(y-x)

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())
d=list(map(int,input().split()))
d.sort()
if d[n//2]==d[(n//2)-1]:
  print(0)
else:
  print(d[n//2]-d[(n//2)-1])

Submission status: Accepted

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

first = a[n//2-1]
second = a[n//2]
print(max(0,second-first))

Submission status: Accepted

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

Submission status: Accepted

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

sorted_D = sorted(D)

print(len((range(sorted_D[N//2-1]+1, sorted_D[N//2]+1))))

Submission status: Accepted

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

d.sort()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding:utf-8
import numpy as np

n = int(input())
d = list(map(int, input().split()))
d.sort()
#print(d)


if n % 2 == 1:
    print(0)
else:
    i = n // 2
    border1 = d[i]
    border2 = d[i- 1]
    if (border1 - border2) == 0:
        print(0)
    else:
        print(border1 - border2)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
if b[(int(n/2)-1)]==b[int((n/2))]:
  print(0)
else:
  c=b[int((n/2)-1)]
  d=b[int((n/2))]
  e=len(list(range(c,d)))
  print(e)

Submission status: Accepted

Solution code:
def getlist():
    return list(map(int, input().split()))

N = int(input())
d = getlist()
d = sorted(d)
m = int(N // 2)

print(d[m] - d[m - 1])

Submission status: Accepted

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

if __name__ == '__main__':
    print(main())

Submission status: Accepted

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

Submission status: Accepted

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

d.sort() #ソートして、N/2-1とN/2の差を探す
print(d[N//2]-d[N//2-1])

Submission status: Accepted

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

Submission status: Accepted

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

t = int(n/2)
D.sort()

ans = D[t]-D[t-1]
print(ans)

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()

## 中間のインデックスを取得
half_D = int(N / 2)

"""場合分け
1.中間で区切った小さい方と大きい方の数字が異なる
OK
2.同じ数字
NG
"""

## 2.同じ数字
if D[half_D] == D[half_D-1]:
  print(0)
## 1.中間で区切った小さい方と大きい方の数字が異なる
else:
  print(D[half_D] - D[half_D-1])

Submission status: Accepted

Solution code:
import sys
N = int(sys.stdin.readline())
dlist = [int(d) for d in sys.stdin.readline().split()]

sorted_dlist = sorted(dlist)
half_i = int(N//2)
print(sorted_dlist[half_i]-sorted_dlist[half_i-1])

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

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

Submission status: Accepted

Solution code:
N = int(input())
D = [int(v) for v in input().split(' ')]

Ds = list(sorted(D))
p = int(len(D) / 2)
DsL = Ds[p - 1]
DsR = Ds[p]
Ks = DsL + 1
Ke = DsR

print(Ke - Ks + 1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
D=[int(s) for s in input().split()]

D=sorted(D)
sum=[]
count=0
for i in reversed(range(len(D))):
    sum.append(D.pop(i))
    if len(sum) == len(D):
        Ans=len(sum)
        break
for i in range(D[Ans-1],sum[Ans-1],1):
    count+=1
print(count)

Submission status: Accepted

Solution code:
#coding utf-8
N=int(input())
d=list(map(int,input().split())) 
ans=0
d.sort()
umed=int((N-1)/2)
omed=int((N+1)/2)
ans=d[omed]-d[umed]  

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
d_list = list(map(int, input().split()))
sorted_d_list = sorted(d_list)
half_n = n // 2

if sorted_d_list[half_n-1] == sorted_d_list[half_n]:
    print(0)
else:
    print(sorted_d_list[half_n]-sorted_d_list[half_n-1])

Submission status: Accepted

Solution code:
n = int(input())

ds = list(map(int, input().split()))
ds.sort()

max_abc = ds[int(n/2 - 1)]
min_arc = ds[int(n/2)]

print(min_arc - max_abc)

Submission status: Accepted

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

array.sort()

m = n//2

mae = array[m-1]
usiro = array[m]

print(usiro-mae)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# nは偶数である
n = int(input())
d = list(map(int, input().split()))

d.sort()

# インデックス center,center+1に格納されている値の差を出せばよい
center = len(d)//2

ans = d[center] - d[center-1]

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())
L = list(sorted(list(map(int, input().split()))))
print(L[N//2]-L[N//2-1])

Submission status: Accepted

Solution code:

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

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

Submission status: Accepted

Solution code:
def resolve():
    n = int(input())
    ds = map(int, input().split())

    sorted_ds = sorted(ds)
    mid_diff = sorted_ds[n // 2] - sorted_ds[n // 2 - 1]
    if mid_diff == 0:
        print(0)
    else:
        print(mid_diff)

resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(raw_input())
d = [int(i) for i in raw_input().split()]

d.sort()
start = d[N/2-1]
end = d[N/2]

if start == end:
    print 0
else:
    print (end - start)

Submission status: Accepted

Solution code:

n = int(input())
D = list(map(int, input().split()))
D.sort()

# 二分割した左側
mid_left = len(D)//2 -1
print(D[mid_left+1] - D[mid_left])

Submission status: Accepted

Solution code:

n = int(input())
D = list(map(int, input().split()))
D.sort()

# 二分割した左側
mid_left = len(D)//2 -1

if D[mid_left] == D[mid_left+1]:
    print(0)
else:
    print(D[mid_left+1] - D[mid_left])

Submission status: Accepted

Solution code:
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N = I()
d = III()

d.sort()
x1 = d[N//2-1]
x2 = d[N//2]

print(x2-x1)

Submission status: Accepted

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

num=0
ans=0
i=0
mid=len(d)/2
while num!=len(d):
    i+=1
    while d[num]<i:
        num+=1
        if(num==len(d)):
            break
    if(num==mid):
        ans+=1
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N=int( input() )
S=input().split(" ")

for i in range ( N ) :
    S[i] = int(S[i])

S.sort()

ini = S[int(N/2)-1]
fin = S[int(N/2)]

print ( fin - ini )

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 = sorted([int(x) for x in input().split()])

print(d[int(len(d)/2)]-d[int(len(d)/2-1)])

Submission status: Accepted

Solution code:
N = int(input())
d = list(map(int,input().split()))
d.sort()
#print(d)
c = [0] * N 
i = 0
tmp = d[0]
count = 1
 
for j in range(1,N):
    if tmp == d[j]:
        #print("yes",j)
        count += 1
    else:
        #print("no",j)
        tmp = d[j]   
        c[i] = count
        count = 1
        i += 1
#print(c)
 
hantei = 0
hantei1 = 0

for j in range(N):
    hantei += c[j]
    if len(d) / 2 == hantei:
        hantei1 = 1
        break
    elif len(d) / 2 < hantei:
        #hantei1 = 0
        break
 
if hantei1 == 1:
    print(d[len(d)//2] - d[len(d)//2-1])
else:
    print(0)

Submission status: Accepted

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

main()

Submission status: Accepted

Solution code:
from math import factorial, ceil, floor # 階乗/切り上げ/切り捨て
from operator import itemgetter as ig
from collections import defaultdict as dd
# 定数
INF = float("inf")
MOD = int(1e9 + 7)

def main():
    N = int(input())
    D = tuple(map(int, input().split()))

    d = tuple(sorted(D))
    print(d[N // 2] - d[N // 2 - 1])

main()

Submission status: Accepted

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: Accepted

Solution code:
n = input()
d = [int(i) for i in input().split()]
if len(d) % 2 == 1:
  ans = 0
else:
  d.sort()
  if d[len(d)//2-1] == d[len(d)//2]:
    ans = 0
  else:
    ans = d[len(d)//2] - d[len(d)//2-1]
    
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
half=n//2
numlist=[int(i) for i in input().split()]

numlist.sort()
a=numlist[half-1]
b=numlist[half]
print(b-a)

Submission status: Accepted

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

sorted_d = sorted(d)
h = n // 2
print(sorted_d[h] - sorted_d[h-1])

Submission status: Accepted

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

sorted_d = sorted(d)
h = n // 2
mid_left = sorted_d[h-1]
mid_right = sorted_d[h]

if mid_left == mid_right:
    print(0)
else:
    print(mid_right - mid_left)

Submission status: Accepted

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: Accepted

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

Submission status: Accepted

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

D = sorted(D, reverse=False)

if N%2 == 0:
    ans = D[N // 2] - D[N // 2 - 1]
else:
    ans = 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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: Accepted

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

Submission status: Accepted

Solution code:
# Divide the Problems
N = int(input())
d = list(map(int, input().split()))

d = sorted(d)

if N % 2 == 1: # 奇数個の場合は同じ数にならない
    print(0)
else:
    n = int(N / 2) #半分の数
    if d[n-1] == d[n]:
        print(0)
    else:
        ans = d[n] - d[n-1]
        print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

H = sorted(H)

print(H[int(N/2)]-H[int(N/2)-1])

Submission status: Accepted

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