#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long

const int N = 2e5 + 7;
const int INF = 1e18 + 239;

namespace DSU {
	int n;
	int cnt;
	int p[N];
	int rank[N];

	int get(int v) {
		if (p[v] != v) {
			p[v] = get(p[v]);
		}
		return p[v];
	}

	int merge(int a, int b) {
		a = get(a);
		b = get(b);
		if (a == b) {
			return 0;
		} else {
			if (rank[a] < rank[b]) {
				swap(a, b);
			}
			cnt--;
			p[b] = a;
			if (rank[a] == rank[b]) {
				rank[a]++;
			}
			return 1;
		}
	}

	void init(int n_) {
		n = n_;
		cnt = n;
		for (int i = 0; i < n; i++) {
			p[i] = i;
			rank[i] = 0;
		}
	}
}

struct SegmentTree {
	int n;
	pair<int, int> t[4 * N];

	void pull(int v) {
		t[v] = min(t[2 * v + 1], t[2 * v + 2]);
	}

	void build(int v, int l, int r, vector<int> &a) {
		if (l + 1 == r) {
			t[v] = {a[l], l};
		} else {
			int m = (r + l) >> 1;
			build(2 * v + 1, l, m, a);
			build(2 * v + 2, m, r, a);
			pull(v);
		}
	}

	SegmentTree() {}

	void init(vector<int> &a) {
		n = (int)a.size();
		build(0, 0, n, a);
	}

	void set(int v, int l, int r, int pos, int val) {
		if (l + 1 == r) {
			t[v] = {val, pos};
		} else {
			int m = (r + l) >> 1;
			if (pos < m) {
				set(2 * v + 1, l, m, pos, val);
			} else {
				set(2 * v + 2, m, r, pos, val);
			}
			pull(v);
		}
	}

	void set(int pos, int val) {
		set(0, 0, n, pos, val);
	}

	void query(int v, int l, int r, int ql, int qr, pair<int, int> &ans) {
		if (qr <= l || r <= ql) {
			return;
		} else if (ql <= l && r <= qr) {
			ans = min(ans, t[v]);
		} else {
			int m = (r + l) >> 1;
			query(2 * v + 1, l, m, ql, qr, ans);
			query(2 * v + 2, m, r, ql, qr, ans);
		}
	}

	int min_ind(int l, int r) {
		if (l >= r) {
			return -1;
		} else {
			pair<int, int> ans = {INF, -1};
			query(0, 0, n, l, r, ans);
			return ans.second;
		}
	}
};

int n, D;
int a[N];
int comp[N];
vector<int> by_comp[N];

SegmentTree L;
SegmentTree R;

int ans = 0;

void it() {
	for (int i = 0; i < n; i++) {
		by_comp[i].clear();
	}
	for (int i = 0; i < n; i++) {
		comp[i] = DSU::get(i);
		by_comp[comp[i]].push_back(i);
	}
	vector<int> li(n);
	vector<int> ri(n);
	for (int i = 0; i < n; i++) {
		li[i] = -(i * D) + a[i];
		ri[i] = (i * D) + a[i];
	}
	{	
		L.init(li);
		R.init(ri);
	}
	for (int some = 0; some < n; some++) {
		if (by_comp[some].empty()) continue;
		for (auto i : by_comp[some]) {
			L.set(i, INF);
			R.set(i, INF);
		}
		int best = INF;
		int best_j = -1;
		int best_i = -1;
		for (auto i : by_comp[some]) {
			int minl = L.min_ind(0, i);
			if (minl != -1 && best > (i * D) + a[i] + li[minl]) {
				best = (i * D) + a[i] + li[minl];
				best_j = minl;
				best_i = i;
			}
			int minr = R.min_ind(i + 1, n);
			if (minr != -1 && best > -(i * D) + a[i] + ri[minr]) {
				best =  -(i * D) + a[i] + ri[minr];
				best_j = minr;
				best_i = i;
			}
		}
		if (DSU::merge(best_i, best_j)) {
			ans += best;
		}
		for (auto i : by_comp[some]) {
			L.set(i, li[i]);
			R.set(i, ri[i]);
		}	
	}
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	cin >> n >> D;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	DSU::init(n);
	while (DSU::cnt > 1) {
		it();
	}
	cout << ans << '\n';
}



Measured memory_bytes: 67168