#2394. A 鸭子与按钮

A 鸭子与按钮

Duck Button Game

Background

Qiqi and her friends are playing a game on a one-dimensional grid consisting of nn cells numbered from 11 to nn left to right.

Problem Description

Each cell has a button. If at any moment there are at least a[i]a[i] ducks on cell ii, the button on that cell is permanently pressed. Once pressed, it stays pressed even if the ducks leave. To win the game, all nn buttons must be pressed.

Initially, there are dd ducks on cell 11. In each move, a single duck may move one cell to the left or to the right.

Determine the minimum total number of moves required to win the game. It is guaranteed that there exists a way to win the game.

Input Format

The input is given from standard input in the following format.

nn dd a[1]a[1] a[2]a[n]a[2]\dots a[n]

Output Format

Print a single integer, the minimum total number of moves to win the game.

Sample

2 199
175 42
42
5 3
1 1 0 1 0
3
5 7
2 2 2 2 2
8
7 5
1 3 3 4 5 5 5
30
8 9
7 6 6 6 3 3 3 1
28
8 5
2 3 5 1 4 2 1 0
21
4 1000000000
1 1 1 999999999
2999999997

Constraints

nn up to 200,000200,000.

dd up to 10910^{9}.

0a[i]d0 \le a[i] \le d for all 1in1 \le i \le n.

It is guaranteed that there exists a way to win the game.