There are N cities in Republic of AtCoder. The size of the i-th city is A_{i}. Takahashi would like to build N-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 i-th city and the j-th city is |i-j| \times D + A_{i} + A_{j}. For Takahashi, find the minimum possible total cost to achieve the objective.

Constraints

* 1 \leq N \leq 2 \times 10^5
* 1 \leq D \leq 10^9
* 1 \leq A_{i} \leq 10^9
* A_{i} and D are integers.

Input

Input is given from Standard Input in the following format:


N D
A_1 A_2 ... A_N


Output

Print the minimum possible total cost.

Examples

Input

3 1
1 100 1


Output

106


Input

3 1000
1 100 1


Output

2202


Input

6 14
25 171 7 1 17 162


Output

497


Input

12 5
43 94 27 3 69 99 56 25 8 15 46 8


Output

658
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

struct UnionFind {
	vector<int> par, rank;
	
	UnionFind(int n) {
		par.resize(n);
		rank.resize(n);
		REP(i, n) {
		 par[i] = i;
		 rank[i] = 0;
		}
	}
	
	int operator[] (int x) {
		return find(x);
	}
	
	int find(int x) {
		if (x == par[x]) return x;
		return par[x] = find(par[x]);
	}
	
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		
		if (rank[x] < rank[y]) swap(x, y);
		
		par[y] = x;
		if (rank[x] == rank[y]) rank[x]++;
	}
	
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	
};


using pll = pair<ll, ll>;
using ll3 = tuple<ll, ll, ll>;
int N, D;
vector<int> A;

void dfs(int l, int r, vector<ll3> &edge) {
	if (r - l <= 1) return;
	int m = (l + r) / 2;
	
	pll mn(longINF, -1);
	FOR(i, m, r) chmin(mn, pll(A[i] + (ll)i * D, i));
	FOR(i, l, m) edge.emplace_back(A[i] - (ll)i * D + mn.fi, i, mn.se);
	
	mn = pll(longINF, -1);
	FOR(i, l, m) chmin(mn, pll(A[i] - (ll)i * D, i));
	FOR(i, m, r) edge.emplace_back(A[i] + (ll)i * D + mn.fi, i, mn.se);
	
	dfs(l, m, edge);
	dfs(m, r, edge);
}

int main() {
	cin >> N >> D;
	A.resize(N);
	REP(i, N) scanf("%d", &A[i]);
	
	vector<ll3> edge;
	dfs(0, N, edge);
	sort(ALL(edge));
	
	UnionFind uf(N);
	ll ans = 0;
	for (ll3 &cur : edge) {
		ll cost, x, y;
		tie(cost, x, y) = cur;
		if (uf.same(x, y)) continue;
		uf.unite(x, y);
		ans += cost;
	}
	
	cout << ans << endl;
}