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 math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

n = int(input())
ds = sorted(get_nums_l())

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
p=input().rstrip().split(' ')
p.sort(key=int)
print(int(p[len(p)//2]) - int(p[(len(p)//2)-1]))

Submission status: Accepted

Solution code:
N = int(input())
d = sorted([int(x) for x 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()
l = int(n/2)
print(d[l]-d[l-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 = list(map(int, input().split()))
d.sort()

dlow = d[N // 2 - 1]
dhieh = d[N // 2]

print(dhieh - dlow)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
ri = lambda: int(input())
#rl = lambda: [int(x) if x.isdecimal() else x for x in input().split()]
#rl = lambda: list(input().split()))
rl = lambda: map(int,input().split())
rr = lambda N: [list(l) for l in zip(*[rl() for _ in range(N)])]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18
MOD = 10**9+7

N = ri()
D = list(rl())
D.sort()
print(D[N//2]-D[N//2-1])

Submission status: Accepted

Solution code:
from collections import Counter


def solve(N, Ps):
    C = Counter(Ps)
    M = 10 ** 5 + 1
    counts = [0 for i in range(M)]
    for d, c in sorted([(d, c) for d, c in C.items()], key=lambda x: x[0]):
        counts[d] += c

    for i in range(1, M):
        counts[i] += counts[i - 1]

    return len([c for c in counts if c == N // 2])


if __name__ == "__main__":
    N = int(input())
    Ds = list(map(int, input().split(" ")))
    print(solve(N, Ds))

Submission status: Accepted

Solution code:
#!/usr/bin/env python

import sys

n= int(sys.stdin.readline())
d= [ int(x) for x in sys.stdin.readline().split() ]
d.sort()
#
nh= n//2
ans= d[nh] - d[nh-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-1) // 2])

Submission status: Accepted

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

l.sort()

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:
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 29 20:53:11 2019

@author: Yamazaki Kenichi
"""

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:
#!/usr/bin/env python3
import sys


def solve(N: int, d: "List[int]"):
    d.sort()
    print(d[N // 2] - d[N // 2 - 1])
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    d = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, d)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from heapq import heappush, heappop
import re
from collections import deque
import sys
input = sys.stdin.readline


def int_raw():
    return int(input())


def ss_raw():
    return input().split()


def ints_raw():
    return tuple(map(int, ss_raw()))


DIV = 10**9+7


def mod_invs(n, mod=DIV):
    inv = [0]*(n+1)
    inv[0] = 1
    inv[1] = 1
    for i in range(2, n+1):
        inv[i] = (-(mod//i)*inv[mod % i]) % mod
    return inv


def main():
    N = int_raw()
    ds = list(ints_raw())
    ds.sort()
    medi = ds[(N-1)//2]
    medi_h = ds[(N-1)//2+1]
    return medi_h-medi


print(main())

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:
# import bisect

N = int(input())
d = sorted([int(i) for i 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 = [int(item) for item in input().split()]
d.sort()

if len(d) % 2 == 1:
    print(0)
    exit()
print(d[len(d)//2] - d[len(d)//2-1])

Submission status: Accepted

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

dlist.sort()
#print(dlist)

min_arc=dlist[N//2]
max_abc=dlist[N//2-1]

print(min_arc-max_abc)

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


if __name__ == '__main__':
	main()

Submission status: Accepted

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

Submission status: Accepted

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

mid = N//2
# print(D)
print(D[mid] - D[mid-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()))

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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:
import sys

fin = sys.stdin.readline

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

d = sorted(d)

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

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

print(sorted(d)[n//2]-sorted(d)[0:n//2][-1])

Submission status: Accepted

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

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

d.sort()

abc_max, arc_min = d[len(d)//2 - 1], d[len(d)//2]

# print(arc_min, abc_max)
print(arc_min - abc_max)

Submission status: Accepted

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

def readInts():
  return [int(s) for s in input().split(" ")]

def main():
  N = readInts()[0]
  d = readInts()
  d.sort()

  l = N // 2 - 1
  r = N // 2

  print(d[r] - d[l])


if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:

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

d.sort()
t = N // 2

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
raw_input()
s = sorted(map(int, raw_input().split()))

i = len(s) / 2

print s[i] - s[i-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:
N = int(input())
D = list(map(int, input().split()))

D.sort()
print(D[len(D)//2]-D[len(D)//2-1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Solution code:
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
import heapq
INF = float("inf")
sys.setrecursionlimit(10**7)
# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def mi(): return map(int, input().split())
def ii(): return int(input())
###template###

N = ii()
Ds = sorted(list(mi())); #昇順

lo = Ds[N//2-1]
hi = Ds[N//2]

print(hi-lo)

Submission status: Accepted

Solution code:

n = int(input())

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

d_lst.sort()

center_p = len(d_lst) // 2
center_m = center_p - 1

ans = d_lst[center_p] - d_lst[center_m]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, d: "List[int]"):
    import bisect
    d.sort()
    if(N%2 == 1):
        print(0)
    else:
        print(d[int(N/2)] - d[int(N/2)-1])
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    d = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, d)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

dlist.sort()
min_ = dlist[N//2 - 1] + 1
max_ = dlist[N//2]

if max_ >= min_:
    print(max_ - min_ + 1)
else:
    print(0)

Submission status: Accepted

Solution code:
import sys
from collections import deque  # 双方向キュー
from collections import defaultdict  # 初期化済み辞書
from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー
from bisect import bisect_left, bisect_right  # 二分探索
#import numpy as np  # 1.8.2
#import scipy  # 0.13.3
#sys.setrecursionlimit(int(1e+6))
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
MOD = int(1e+9) + 7

def main():
    N = i2n()
    D = i2nn()
    D.sort()
    a = D[(N//2)-1]
    b = D[N//2]
    print(b-a)

main()

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
d = Counter(list(map(int, input().split())))
ans = 0
l, r = 0, N

for K in range(10**5+1):
    if l == r:
        ans += 1
    l += d[K]
    r -= d[K]

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

count = d[int(n/2)] - d[int(n/2)-1]




print(str(count))

Submission status: Accepted

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

D = sorted(D)


ind = N//2-1

ans = D[ind+1] - D[ind]

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, D):
    D.sort()
    return D[N//2] - D[N//2-1]


def main():
    N = read_int()
    D = read_int_n()
    print(slv(N, D))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

if __name__=="__main__": main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
from operator import itemgetter
import math
import copy
import collections
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
d = IL()
d.sort()
num = N//2

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

Submission status: Accepted

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

ds = sorted(ds)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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:
#!/usr/bin/python3
# -*- coding: utf-8 -*-



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

Dn = sorted(Dn)
K = Dn[(N-1)//2+1] - Dn[(N-1)//2]
print(K)

Submission status: Accepted

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

Submission status: Accepted

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

d.sort()

m = (n-1) // 2
l = d[m]
r = d[m+1]

print(r-l)

Submission status: Accepted

Solution code:
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

# import numpy as np
# from scipy.special import perm
# from scipy.special import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

########

N = i_inpl()
d = l_inpl()
d.sort()
# print(N//2)
# print(d[N//2 - 1])
ans = d[N//2]-d[N//2 - 1]

if ans <= 0:
    print(0)
else:
    print(ans)
# n = i_inpl()
# p = l_inpl()

# cnt = 0
# for i in range(n-2):
#     G = [p[i], p[i+1], p[i+2]]
#     G.sort()
#     if G[1] == p[i+1]:
#         cnt += 1

# print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
d_list = list(map(int, input().strip().split()))
d_list.sort()
l = len(d_list) // 2
d1 = d_list[:l]
d2 = d_list[l:]

print(d2[0] - d1[-1])

Submission status: Accepted

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

Submission status: Accepted

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

d.sort()

div = n//2

ans = d[div]-d[div-1]

print(ans)

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:
from bisect import bisect_right
n = int(input())
d = list(map(int,input().split()))
d = sorted(d)
cnt = 0
for i in range(max(d)):
    if bisect_right(d,i)==n//2:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())

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


half = n//2
left = arr[half-1]
right = arr[half]

print(int(right-left))

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007
dire4 = [(1,0), (0,1), (-1,0), (0,-1)]
dire8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]

N = I()
d = LI()
d = sorted(d)

left = d[len(d)//2 - 1]
right = d[len(d)//2]

print(right - left)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env pypy
from __future__ import division, print_function

import os
import sys
from __builtin__ import xrange as range
from cStringIO import StringIO
from future_builtins import ascii, filter, hex, map, oct, zip
from io import IOBase

import __pypy__


def main():
    n = int(input())
    d = [int(di) for di in input().split()]
    d.sort()

    n >>= 1
    x = d[n] - d[n - 1]
    print(x)


# region fastio

BUFSIZE = 8192


class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

    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):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count("\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()


class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()


def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


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

# endregion

if __name__ == "__main__":
    main()

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

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:
def main():
    import sys
    input = sys.stdin.readline
    
    n = int(input())
    arr = sorted(map(int, input().split()))
    
    # print(arr)
    print(arr[n // 2] - arr[n // 2 - 1])
    
    return 0

main()

Submission status: Accepted

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

d.sort()

s = d[N//2-1]
t = d[N//2]

print(t-s)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
dlist = list(map(int, input().split()))
answer=0

dlist=sorted(dlist)
#print(dlist)

manaka=int(n/2)

sho=dlist[manaka-1]
dai=dlist[manaka]

#print(sho, dai)
if sho==dai:
    print(0)
else:
    print(dai-sho)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def find(A):
    A=sorted(A)
    N=len(A)
    left=A[:N//2]
    right=A[N//2:]
    a=left[-1]
    b=right[0]
    return b-a
input()
A=list(map(int,input().strip().split(' ')))
print(find(A))

Submission status: Accepted

Solution code:
N = int(input())
*D, = 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:
N = int(input())
d = sorted(list(map(int, input().split())))
print(max(0, d[N // 2] - d[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())
prob=list(map(int,input().split()))
prob.sort(reverse=True)
print(-prob[n//2]+prob[(n//2)-1])

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
d = sorted(list(map(int, input().split())))
c2 = N // 2
c1 = c2 - 1
print(d[c2] - d[c1])

Submission status: Accepted

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

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())
A = [int(x) for x in input().split()]
A.sort()
print(A[n//2]-A[n//2 - 1])

Submission status: Accepted

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

Submission status: Accepted

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

a = d[N//2-1]
b = d[N//2]
print(b-a)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

abc_last = ds[n//2-1]
arc_first = ds[n//2]

k = arc_first - abc_last
print(k)

Submission status: Accepted

Solution code:
n = int(input())
d = list(map(int, input().split()))
d = sorted(d)
print(max(0, abs(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-1
print(D[n+1]-D[n])

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


n = ni()
d = list(li())
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)
min_ans = d[n//2-1]
max_ans = d[n//2]

print(max_ans - min_ans)

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(max(r-l,0))

Submission status: Accepted

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

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

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

p.sort()
print(max(p[n//2] - p[n//2-1], 0))

Submission status: Accepted

Solution code:
import numpy as np
from collections import defaultdict
from functools import reduce

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
from collections import Counter
N = int(input())
D = sorted(inpl())
print(D[N//2] - D[N//2-1])

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
d = LIST()

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

Submission status: Accepted

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

# find the range of mid-point
mid1 = arr[(n//2) - 1]
mid2 = arr[(n//2)]

print(mid2 - mid1)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#C問題
N = int(input())
D = list(map(int,input().split()))
D.sort()
d = D[(N//2)]-D[(N//2)-1]
print(d)

Submission status: Accepted

Solution code:
N = int(input())
d = [int(s) for s in 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()
# print(d)
print(d[n//2] - d[n//2-1])

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

n=int(input())
l=list(map(int,input().split()))
flg=0
l.sort()
if n%2!=0:
    flg=1
ans=l[n//2]-l[n//2-1]
if flg==0:
    print(ans)
else:
    print(0)