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 = 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:
a=[]
i=1
k=0
l=0
rk=[]
bk=[]
a.append(int(x))
for x in input().split(" "):
    a.append(int(x))

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

Submission status: Runtime Error

Solution code:
n = 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 = 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]:
      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()))
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]:
      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)
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)
max_ = max(D)
min_ = min(D)

middle_idx = len(D)//2

diff = D[middle_idx+1] - D[middle_idx]
print(diff)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
N = int(input())
D = list(map(int, input().split()))
n = N // 2
_n = n - 1
n_ = n + 1
D.sort()
cnt = 0
for i in range(max(D)) :
  if(D[_n] < i and i < D[n_]) :
    if(D[_n] != D[n_]) :
      cnt += 1
    else :
      pass
  else :
    pass
print(cnt)

Submission status: Runtime Error

Solution code:
8
9 1 14 5 5 4 4 14

Submission status: Runtime Error

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

for i in range(len(d)):
		for j in range(len(d) - 1):
			if (d[j] > d[j+1]) :
				d[j], d[j+1] = d[j+1], d[j]

h = int(len(d) / 2)
k = 0
if (d[h] != d[h - 1]) :
	K = d[h] - d[h - 1]

print(K)

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)//4),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()))
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]:
      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()

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:
        cur += 1
        while D[cur - 1] == D[cur]:
            cur += 1
print(count)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
d = list(map(int,input().split()))
d.sort()
if (len(d))%2 == 0:
  m = (d[(len(d)//2)-1]+d[len(d)//2])/2
else:
  m = d[(len(d)//2)]
p = 0
q = 0
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.sort()
if (len(d))%2 == 0:
  m = (d[(len(d)//2)-1]+d[len(d)//2])/2
else:
  m = d[(len(d)//2)]
p = 0
q = 0
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())
ds = input().split()
ds = [int(i) for i in ds]
ds.sort()
#print(ds)
#if ds[int(N/2)] == ds[int(N/2)+1]:
#  print("0")
#else:
print(ds[int(N/2)+1]-ds[int(N/2)])

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep1(i,b) for(ll i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define vi vector<ll>
#define all(v) v.begin(), v.end()

int main() 
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll n = 0;
	cin >> n;
	ll arr[n];
	rep(i, n) {
		cin >> arr[i];
	}
	sort(arr, arr + n);
	
	ll mid1 = (n / 2) - 1;
	ll mid2 = mid1 + 1;
	
	cout << arr[mid2] - arr[mid1] << endl;
	
	//cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Submission status: Runtime Error

Solution code:
n = int(input())
d = list(map(int,input().split()))
d.sort()
if len(d)%2 == 0:
    m = (d[(len(d)//2)-1]+d[len(d)//2])/2
else:
    m = d[(len(d)//2)]
p = 0
q = 0
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())
ds = input().split()
ds = [int(i) for i in ds]
ds.sort()
#print(ds)
if ds[int(N/2)] == ds[int(N/2)+1]:
  print("0")
else:
  print("1")

Submission status: Runtime Error

Solution code:
import sys
from collections import Counter
from operator import itemgetter, attrgetter
n=0
 
n = input()
d_list= list(map(int, input().split()))
cou=sorted(Counter(d_list).most_common())
total=len(d_list)
# print(n)
# print(cou)
# print(total)
index=0
before=0
after=0
first=True
t=0
if n == 0:
    print(0)
for c in cou:
#     print(c)
    if first:
        before = c
        first=False
    before = after
    after = c
    t+=c[1]
    if t > total/2:
        break
    index+=1
# print(before)
# print(after)
# print(len(cou[index:]))
if not(len(cou[index:]) == total/2):
    print(0)
else:
    print(after[0]-before[0])

Submission status: Runtime Error

Solution code:
#ABC132 = 2*2*3*11

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

Submission status: Runtime Error

Solution code:
import sys
from collections import Counter
from operator import itemgetter, attrgetter
n=0
 
n = input()
d_list= list(map(int, input().split()))
cou=sorted(Counter(d_list).most_common())
total=len(d_list)
index=0
before=0
after=0
first=True
t=0
for c in cou:
    if first:
        before = c
        first=False
    before = after
    after = c
    t+=c[1]
    if t > total/2:
        break
    index+=1
if not(len(cou[index:]) == total/2):
    print(0)
else:
    print(after[0]-before[0])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

sd = sorted(d)
low = sd[N/2-1]
up = sd[N/2]
num = up - low
print(num)

Submission status: Runtime Error

Solution code:
import numpy as np


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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
D = input()
D =  D.split(' ')
D = [int(d) for d in D]
D_sort = np.sort(D)

k = int(N/2)
count = 0

low_d = D_sort[k-1]
hight_D = D_sort[k]
dis = hight_D - (low_d+1) + 1

print(dis)

Submission status: Runtime Error

Solution code:
import statistics
import math
#ABC132 = 2*2*3*11
n = int(input())
d = list(map(int,input().split()))
m = statistics.median(d)
ans = 0
p = 0
q = 0
d.sort()
for i in range(len(d)):
    if d[i]>=m:
        if d[i] == d[i+1]:
            ans += 0
            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()))
C=N//2
for x in range(0,N):
    for y in range(0,N-1):
        if d[y]<d[y+1]:
            t=d[y]
            d[y]=d[y+1]
            d[y+1]=t
    N=N-1
if d[C]==d[C-1]:
    print(0)
elif:
    print(d[C-1]-d[C])

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
import numpy as np

N, *arr = map(int, input().split())
arr = np.array(arr)
arr.sort()
m1 = arr[int(N / 2 - 1)]
m2 = arr[int(N / 2)]
print(m2 - m1)

Submission status: Runtime Error

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

abc = 0
arc = N

ans = 0
for k in range(1, 10 ** 5):
    while True:
        if d[abc] < k:
            abc += 1
            arc -= 1
        else:
            break
    if abc == arc:
        ans += 1
    elif abc > arc:
        break

print(ans)

Submission status: Runtime Error

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
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    s = S()
    b = list(set(s))
    a = len(list(set(s)))
    if a == 2 and s.count(b[0]) == s.count(b[1]) == 2:
        print("Yes")
    else:
        print("No")
    return

#B
def B():
    n = II()
    p = LI()
    ans = 0
    for i in range(1,n-1):
        if (p[i - 1] < p[i] and p[i] < p[i + 1]) or (p[i + 1] < p[i] and p[i] < p[i - 1]):
            ans += 1
    print(ans)
    return

#C
def C():
    n = II()
    d = LI()
    d.sort()
    ans = 0
    for i in range(10**5+1):
        if n // 2 == bisect_left(d, i):
            ans += 1
    print(ans)
    return


def combination_mod(n, k, mod):
    # power_funcを用いて(nCk) mod p を求める 
    # nCk = n!/((n-k)!k!)を使用

    from math import factorial
    if n < 0 or k < 0 or n < k: return 0
    if n == 0 or k == 0: return 1
    a = factorial(n) % mod
    b = factorial(k) % mod
    c = factorial(n - k) % mod
    return (a * power_func(b, mod - 2, mod) * power_func(c, mod - 2, mod)) % mod
    
def power_func(a, b, mod):
    # a^b mod p を求める
    # bを2進数分解して高速累乗

    if b == 0: return 1
    if b % 2 == 0:
        d = power_func(a, b // 2, mod)
        return d * d % mod
    if b % 2 == 1:
        return (a * power_func(a, b - 1, mod)) % mod

#D
def D():
    n, k = LI()
    ans = 0
    for i in range(1,k+1):
        a = combination_mod(n - k + 1, i, mod)
        b = combination_mod(k - 1, i - 1, mod)
        print(a*b)
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    D()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

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

X=sorted(x)
#print(X)

#print(X[n-1])
#print(X[n])

print(X[n]-X[n-1]