Mr. Little Z wants to live a healthy life, so he decided to eat exactly one tomato every day.

The price of tomatoes changes every day, so Mr. Little Z went to a fortune teller to get predictions for the prices of tomatoes for the next n days. Mr. Little will buy tomatoes the most optimal way, because he wants to save some money. However, he must make sure that the tomatoes do not go bad. To be more accurate, if you buy a tomato on the i-th day it will be healthy until the (i+d-1)th day. So, the lifespan of a tomato is d. Important: Mr. Little Z can buy as many tomatoes as he wants in one day!

For the given tomatoes' prices in the next n days and the lifespan of tomatoes d, calculate the minimum amount of money that Mr. Little Z has to spend in order to eat one tomato for each of the next n days.


The first line of the standard input contains two numbers, n and d. Each of the next n lines contains prices for tomatoes ci, where the maximum price for each tomato is 1000.


To the standard output write one number corresponding to the minimum amount of money Mr. Little Z has to spend in order to eat one tomato every day.


  • 1 ≤ n, d ≤ 200000
  • dn
  • 1 ≤ in

Example input:

8 3

Example output:



Mr. Little Z will buy 3 tomatoes on the 1st day, then he'll buy 2 tomatoes on the 4th day, and finally he will buy 3 tomatoes on the 6th day. Mr. Little Z can eat a tomato on the same day he bought it.

Time and memory limit:

  • 0.25 seconds
  • 64MB

Problem source: Z-Trening