#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef unsigned long long ul;
struct edge {
	ll cost; int u,v;
	bool operator<(const edge &e)const {
		if (e.cost != cost)return cost < e.cost;
		if (e.u != u)return u < e.u;
		return v < e.v;
	}
};
vector<edge> e;
int n; ll d;
ll a[1 << 18];

struct SegT {
private:
	int n; vector<LP> node;
public:
	SegT(int n_) {
		n = 1;
		while (n < n_)n *= 2;
		node.resize(2 * n - 1, LP{INF,-1});
	}
	void update(int k, ll x) {
		k += n - 1;
		node[k] = { x,(k - n + 1) };
		while (k > 0) {
			k = (k - 1) / 2;
			if (node[k * 2 + 1].first < node[k * 2 + 2].first) {
				node[k] = node[k * 2 + 1];
			}
			else node[k] = node[k * 2 + 2];
		}
	}
	LP query(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0)r = n;
		if (r <= a || b <= l)return { INF,-1 };
		if (a <= l && r <= b)return node[k];
		else {
			LP vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
			LP vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
			if (vl.first < vr.first)return vl;
			else return vr;
		}
	}
};

vector<LP> vl, vr;
ll ax[1 << 18],ay[1<<18];


int par[200000];
int rank1[200000];
void init(int n) {
	for (int i = 0; i < n; i++) {
		par[i] = i;
		rank1[i] = 0;
	}
}
int find(int x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rank1[x] < rank1[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (rank1[x] == rank1[y])rank1[x]++;
	}
}
bool same(int x, int y) {
	return find(x) == find(y);
}
int main() {
	cin >> n >> d;
	rep(i, n) {
		cin >> a[i];
		vl.push_back({ a[i] + i * d,i });
		ax[i] = a[i] + i * d;
		vr.push_back({ a[i] - i * d,i });
		ay[i] = a[i] - i * d;
	}
	sort(vl.begin(), vl.end());
	sort(vr.begin(), vr.end());
	SegT sl(n), sr(n);
	rep(i, n) {
		int id = vl[i].second;
		LP q = sl.query(0, id);
		if (q.second >= 0) {
			e.push_back({ ay[q.second]+ax[id],id,(int)q.second });
		}
		sl.update(id, ay[id]);
	}
	rep(i, n) {
		int id = vr[i].second;
		LP q = sr.query(id + 1, n);
		if (q.second >= 0) {
			e.push_back({ ax[q.second] + ay[id],id,(int)q.second });
		}
		sr.update(id, ax[id]);
	}
	ll ans = 0;

	init(n);
	sort(e.begin(), e.end());
	rep(i, e.size()) {
		int u = e[i].u; int v = e[i].v;
		if (same(u, v))continue;
		unite(u, v);
		ans += e[i].cost;
		//cout << e[i].cost<<" "<<u << " " << v << endl;
	}
	cout << ans << endl;
	//stop
	return 0;
}

Measured memory_bytes: 40796