There are $n$ apple trees planted along a cyclic road, which is $L$ metres long. Your storehouse is built at position $0$ on that cyclic road.
The $i$th tree is planted at position $x_i$, clockwise from position $0$. There are $a_i$ delicious apple(s) on the $i$th tree.
You only have a basket which can contain at most $K$ apple(s). You are to start from your storehouse, pick all the apples and carry them back to your storehouse using your basket. What is your minimum distance travelled?
$1\le n,k\le 10^5, a_i\ge 1, a_1+a_2+...+a_n\le 10^5$
$1\le L\le 10^9$
$0\le x[i]\le L$
There are less than 20 huge testcases, and less than 500 small testcases.