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

Solution in C (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

void sort(long long* N, long long len)
{
    long long i,j;

    for(i=0; i<len; i++)
    {
        for(j=len-1; j>i; j--)
        {
            if(N[j] < N[j-1])
            {
                long long ti;
                long long temp;
                temp = N[j];
                N[j]   = N[j-1];
                N[j-1] = temp;
            }
        }
    }
}

int main(int argc, void **arg)
{
    long long n, n1, n2;
    long long d[100000];
    long long d1[100000];
    long long d2[100000];
    long long i, j, k;
    long long max = 0;
    long long half = 0;
    long long m1 = 0;
    long long m2 = 0;

    scanf("%lld", &n);

    for (i = 0; i < n; i++)
    {
        scanf("%lld", &d[i]);
        if( max < d[i] ) max = d[i];
    }

    half = max / 2;
    n1 = 0;
    n2 = 0;

    for (i = 0; i < n; i++)
    {
        if( half > d[i] ) {
            if( m1 > 0 ) {
                if( d[i] > d1[m1] ) m1 = n1;
            }
            else {
                m1 = n1;
            }
            d1[n1++] = d[i];
        }
        else {
            if( m2 > 0 ) {
                if( d[i] < d2[m2] ) m2 = n2;
            }
            else {
                m2 = n2;
            }
            d2[n2++] = d[i];
        }
    }

    if( n1 > n2 ) {
        k = (n1 - n2) / 2;
        for (i = 0; i < k ; i++)
        {
            d2[n2] = d1[m1];
            m2 = n2;
            n2++;
            d1[m1] = 0;
            for (j = 0; j < n1; j++)
            {
                if( d1[j] > d1[m1] ) m1 = j;
            }
        }
    }
    else {
        k = (n2 - n1) / 2;
        for (i = 0; i < k ; i++)
        {
            d1[n1] = d2[m2];
            m1 = n1;
            n1++;
            d2[m2] = max;
            for (j = 0; j < n2; j++)
            {
                if( d2[j] < d2[m2] ) m2 = j;
            }
        }
    }

    j = d2[m2] - d1[m1];
    printf("%lld\n", j);

    return 0;
}