#KEYENCE2019E. Connecting Cities

Connecting Cities

Score : 600600 points

Problem Statement

There are NN cities in Republic of AtCoder. The size of the ii-th city is AiA_{i}. Takahashi would like to build N1N-1 bidirectional roads connecting two cities so that any city can be reached from any other city by using these roads.

Assume that the cost of building a road connecting the ii-th city and the jj-th city is ij×D+Ai+Aj|i-j| \times D + A_{i} + A_{j}. For Takahashi, find the minimum possible total cost to achieve the objective.

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 1D1091 \leq D \leq 10^9
  • 1Ai1091 \leq A_{i} \leq 10^9
  • AiA_{i} and DD are integers.

Input

Input is given from Standard Input in the following format:

NN DD

A1A_1 A2A_2 ...... ANA_N

Output

Print the minimum possible total cost.

3 1
1 100 1
106

This cost can be achieved by, for example, building roads connecting City 11, 22 and City 11, 33.

3 1000
1 100 1
2202
6 14
25 171 7 1 17 162
497
12 5
43 94 27 3 69 99 56 25 8 15 46 8
658