#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8

struct union_find{
	typedef unsigned size_type;
	vector<int> par;
	size_type grs;
	explicit union_find(size_type n = 0){ init(n); }
	void init(size_type n){
		par.assign(n, -1);
		grs = n;
	}
	size_type find(size_type x){
		if(par[x] < 0){ return x; }
		return par[x] = find(par[x]);
	}
	size_type size(size_type x){
		return -par[find(x)];
	}
	size_type groups(){
		return grs;
	}
	bool unite(size_type x, size_type y){
		x = find(x);
		y = find(y);
		if(x == y){ return false; }
		if(par[x] < par[y]){ swap(x, y); }
		par[y] += par[x];
		par[x] = y;
		--grs;
		return true;
	}
	bool same(size_type x, size_type y){
		return find(x) == find(y);
	}
	bool is_root(size_type x){
		return find(x) == x;
	}
};

void mainmain(){
	const LL INF = 1LL << 60;

	int n;
	LL d;
	scanf("%d%lld", &n, &d);
	vector<LL> as(n);
	for(int i = 0; i < n; ++i){ scanf("%lld", &as[i]); }

	union_find uf(n);
	LL ans = 0;

	vector<pll> dp1, dp2;
	vector<pll> top2;
	vector<tuple<LL,int,int>> es;
	const pll def(INF, -1);
	while(uf.groups() > 1){
		dp1.assign(n, def);
		dp2.assign(n, def);

		top2.clear();
		for(int i = n - 1; i >= 0; --i){
			int u = uf.find(i);
			for(cauto t : top2){
				if(t.second != u){
					dp1[i] = pll(t.first + as[i] - i * d, t.second);
					break;
				}
			}
			pll p(as[i] + i * d, u);
			top2.insert(lower_bound(ALL(top2), p), p);
			for(int j = 0; j < (int)top2.size(); ++j){
				for(int k = j + 1; k < (int)top2.size(); ++k){
					if(top2[j].second == top2[k].second){
						top2[k] = def;
					}
				}
			}
			top2.erase(remove(ALL(top2), def), top2.end());
			if(top2.size() > 2){ top2.pop_back(); }
		}
		top2.clear();
		for(int i = 0; i < n; ++i){
			int u = uf.find(i);
			for(cauto t : top2){
				if(t.second != u){
					dp2[i] = pll(t.first + as[i] + i * d, t.second);
					break;
				}
			}
			pll p(as[i] - i * d, u);
			top2.insert(lower_bound(ALL(top2), p), p);
			for(int j = 0; j < (int)top2.size(); ++j){
				for(int k = j + 1; k < (int)top2.size(); ++k){
					if(top2[j].second == top2[k].second){
						top2[k] = def;
					}
				}
			}
			top2.erase(remove(ALL(top2), def), top2.end());
			if(top2.size() > 2){ top2.pop_back(); }
		}

		es.assign(n, def);
		for(int i = 0; i < n; ++i){
			pll p = min(dp1[i], dp2[i]);
			int u = uf.find(i);
			chmin(es[u], p);
		}
		sort(ALL(es));
		for(int i = 0; i < n; ++i){
			cauto t = es[i];
			if(t.second >= 0){
				if(uf.unite(i, t.second)){
					ans += t.first;
				}
			}
		}
	}
	printf("%lld\n", ans);
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}
