import java.io.PrintWriter

fun main(args: Array<String>) {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val n = readInteger()
    val dList = readIntegerList()
    val countMap = elementCountMap(dList)
    var sum = n
    var ABCSum = 0
    var min = -1
    var max = -1
    for (key in countMap.keys.sorted()) {
        ABCSum += countMap[key]!!

        if (min == -1 && ABCSum == sum - ABCSum) {
            min = key
        }

        if (max == -1 && ABCSum > sum - ABCSum) {
            max = key
        }
    }

    if (min != -1) {
        println(max - min)
    } else {
        println(0)
    }
}

/**
 * O(n)
 */
fun <T>elementCountMap(list: List<T>): Map<T, Int> {
    val countMap = mutableMapOf<T, Int>()
    for (e in list) {
        countMap[e] = (countMap[e] ?: 0) + 1
    }
    return countMap
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)
