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 Go (1.6) (judge verdict: Accepted)

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

var isProduct = false

var dp [][][]bool
var N, K, M int

func dfs(p, q, r int) bool {
	return true
}

func main() {
	nextReader = newScanner()

	N = nextInt()

	s := make(Sorter, N)
	for i := 0; i < N; i++ {
		s[i] = S{i, nextInt()}
	}

	sort.Sort(s)

	fmt.Println(s[N/2].d - s[N/2-1].d)

	// dp = make([][][]bool, l)
	// for i := 0; i < l; i++ {
	// 	dp[i] = make([][]bool, l)
	// 	for j := 0; j < l; j++ {
	// 		dp[i][j] = make([]bool, l)
	// 	}
	// }

	// dfs(0, 0, 0)
	// fmt.Println(count)
}

/* --------------------------------------------------------------------------
 *  sort
 * ------------------------------------------------------------------------- */

type S struct {
	i int
	d int
}
type Sorter []S

func (a Sorter) Len() int           { return len(a) }
func (a Sorter) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a Sorter) Less(i, j int) bool { return a[i].d < a[j].d }

// type Sorter []Sortable

// func (a Sorter) Len() int           { return len(a) }
// func (a Sorter) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
// func (a Sorter) Less(i, j int) bool { return a[i].Axis < a[j].Axis }

/* --------------------------------------------------------------------------
 *  math
 * ------------------------------------------------------------------------- */
func lcm(x, y int) int {
	return x * y / gcd(x, y)
}

func gcd(x, y int) int {
	tmp := x % y
	if tmp > 0 {
		return gcd(y, tmp)
	} else {
		return y
	}
}

func abs(i int) int {
	return int(math.Abs(float64(i)))
}

//prime
type PrimeGenerator struct {
	Next func() uint32
}

func NewPrimeGenerator() *PrimeGenerator {
	primeGenerator := PrimeGenerator{}

	multiples := map[uint32]uint32{}
	var num uint32
	var d uint32 // ←ココ
	primeGenerator.Next = func() uint32 {
		if num == 0 {
			num = 1
			return 2
		}
		if d == 0 { // ←ココ
			d = 4
			return 3
		}

		for {
			num += d
			d = 6 - d
			var k uint32 = 2 // ←ココ

			factor, hasFactor := multiples[num]
			if hasFactor {
				delete(multiples, num)
				// ↓ココ
				if (num+factor)%3 == 0 {
					k = 1
				}
			} else {
				factor = num
			}

			// ↓ココ
			for newNum := num + (factor << k); ; newNum += factor << k {
				_, hasNewFactor := multiples[newNum]
				if !hasNewFactor {
					multiples[newNum] = factor
					break
				}
				k ^= 3 // ←ココ
			}

			if !hasFactor {
				return num
			}
		}
	}

	return &primeGenerator
}

/* --------------------------------------------------------------------------
 *  debug
 * ------------------------------------------------------------------------- */
func debugln(s ...interface{}) {
	if !isProduct {
		fmt.Println(s...)
	}
}

func debug(s ...interface{}) {
	if !isProduct {
		fmt.Print(s...)
	}
}
func debugf(f string, s ...interface{}) {
	if !isProduct {
		fmt.Printf(f, s...)
	}
}

/* --------------------------------------------------------------------------
 *  std.io
 * ------------------------------------------------------------------------- */
var nextReader func() string

func newScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}
func nextString() string {
	return nextReader()
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextInt64s(n int) []int64 {
	r := make([]int64, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt64()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(nextReader(), 64)
	return f
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

/* --------------------------------------------------------------------------
 *  memo
 * ------------------------------------------------------------------------- */