Measuring the Median

No attempts yetTime limit1sMemory limit256 MB

Problem

Meteorology mainly uses the median as its representative value. The hint defines the median.

A machine reads the temperature once per second, and it needs software. The machine has one small digital display, and every second that display shows the median of the temperatures measured during the last KK seconds.

The software is tested on a computer first, before it is loaded onto the machine.

Given the temperatures measured over NN seconds, write a program that computes the sum of the medians shown on the display. In other words, given NN numbers, compute the sum of the medians of the NK+1N-K+1 contiguous subsequences of length KK.

Input

The first line contains NN and KK. (1N2500001 \le N \le 250000, 1K50001 \le K \le 5000, KNK \le N)

Each of the next NN lines contains one measured temperature, given in order. A temperature is an integer between 00 and 6553565535, inclusive.

Output

Print the sum of the medians of all NK+1N-K+1 contiguous subsequences of length KK.

Hint

The median of KK numbers is the (K+1)/2\lfloor (K+1)/2 \rfloor-th smallest of them. Counting starts at 1, and the added 1 makes the index land exactly in the middle when KK is odd.

For example, the median of (1,2,6,5,4,3)(1, 2, 6, 5, 4, 3) is 33, and the median of (11,13,12,14,15)(11, 13, 12, 14, 15) is 1313.