Wheels

Polycarp has $n$ wheels and a car with $m$ slots for wheels. The initial pressure in the $i$-th wheel is $a_i$.

Polycarp’s goal is to take exactly $m$ wheels among the given $n$ wheels and equalize the pressure in them (then he can put these wheels in a car and use it for driving). In one minute he can decrease or increase the pressure in any (single) wheel by $1$. He can increase the pressure no more than $k$ times in total because it is hard to pump up wheels.

Help Polycarp and say what is the minimum number of minutes he needs to spend to equalize the pressure of at least $m$ wheels among the given $n$ wheels.

Input

The first line of the input contains three integers $n, m$ and $k$ ($1 \le m \le n \le 2 \cdot 10^5, 0 \le k \le 10^9$) — the number of wheels, the number of slots for wheels in a car and the number of times Polycarp can increase by $1$ the pressure in a wheel.

The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the pressure in the $i$-th wheel.

Output

Print one integer — the minimum number of minutes Polycarp needs to spend to equalize the pressure in at least $m$ wheels among the given $n$ wheels.

Examples

input

6 6 7
6 15 16 20 1 5

output

39

input

6 3 1
4 8 15 16 23 42

output

8

input

5 4 0
5 5 5 4 5

output

0

Solution:

fun main(args: Array<String>) {
val (n, m, k) = readLine()!!.split(" ").map { it.toInt() }
var a = readLine()!!.split(" ").map { it.toInt() }
var b: MutableList<Int> = mutableListOf()
for (c in a) {
b.add(c)
}
b.sort()
var p: MutableList<Long> = mutableListOf(0)
for (c in b) {
p.add(p.last() + c)
}
var ans: Long = 1000000000000000000L
for (i in 0..n-m) {
var low = i
var high = i + (m / 2)
while (low < high) {
            var mid = (low + high + 1) shr 1
            var ups = b[mid].toLong() * (mid - i + 1) - (p[mid + 1] - p[i])
            if (ups > k) {
high = mid - 1
} else {
low = mid
}
}
var ups = b[low].toLong() * (low - i + 1) - (p[low + 1] - p[i])
var downs = (p[i + m] - p[low + 1]) - b[low].toLong() * (i + m - (low + 1))
var cur = ups + downs
var c0 = low - i + 1
var c1 = i + m - (low + 1)
if (c0 < c1) {
            var its = (k - ups) / c0
            cur -= (c1 - c0).toLong() * its
        }
        if (cur < ans) ans = cur
    }
    println(ans)
}