eolymp
bolt
Try our new interface for solving problems
Problems

Mountain Trek Route

Mountain Trek Route

In Almaty countryside a mountain cycle trek route (a route with a start and finish at one point) has been constructed. We will simulate the route in a way of stairs (not hills) of one and the same width each, each step i is horizontal and is marked by the sea level ai meters. Hegths of neighbor stairs may be equal. The difficulty of the route is a sum of ups and downs. More formaly

difficulty = |a1 - a2| + |a2 - a3| + ... + |an-1 - an| + |an - a1|

The first constructed trek route appeared to be too challenging for tourists. To decrease the route difficulty we can use k blocks. The block's width equals stair's width and the block's height equals one meter. We may put any block on any stair or on another block or does't use it at all. Dene the maximum possible decrease of the trek route difficulty.

Input

In the first line there are the following numbers n (2n106) and k (1k109). In the next line there are n non-negative integers which are the height of each of the stairs.

Output

Output one number, which is maximum possible decrease of the trek route difficulty.

Time limit 1 second
Memory limit 64 MiB
Input example #1
4 5
4 3 2 1
Output example #1
4
Input example #2
3 2
1 2 1
Output example #2
2
Input example #3
7 1000
4 3 3 2 3 2 1
Output example #3
8
Source 2012 VIII Zhautykov Olympiad Almaty, Kazakhstan, January 17