#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
double dot(complex<double> a, complex<double> b) {
	return a.real() * b.real() + a.imag() * b.imag();
}
double gyaku_dot(complex<double> a, complex<double> b) {
	return a.real() * b.imag() - a.imag() * b.real();
}
double leng(complex<double> a) {
	return sqrt(a.real() * a.real() + a.imag() * a.imag());
}
double angles(complex<double> a, complex<double> b) {
	double cosine = dot(a, b) / (leng(a) * leng(b));
	double sine = gyaku_dot(a, b) / (leng(a) * leng(b));
	double kaku = acos(cosine);
	if (sine <= 0) {
		kaku = 2 * Ma_PI - kaku;
	}
	return kaku;
}
vector<int> convex_hull(vector<complex<double>> a) {
	vector<int> ans;
	double now_minnest = a[0].real();
	int now_itr = 0;
	REP(i, a.size()) {
		if (now_minnest > a[i].real()) {
			now_minnest = a[i].real();
			now_itr = i;
		}
	}
	ans.push_back(now_itr);
	complex<double> ba(0, 1);
	while (true) {
		int now_go = 0;
		double now_min = 0;
		int starter = ans[ans.size() - 1];
		for (int i = 0; i < a.size(); ++i) {
			if (i != starter) {
				double goa = angles(ba, a[i] - a[starter]);
				if (goa > now_min) {
					now_min = goa;
					now_go = i;
				}
			}
		}
		if (now_go == ans[0]) break;
		ans.push_back(now_go);
		ba = complex<double>(a[now_go] - a[starter]);
	}
	return ans;
}
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
#define int long long
pair<long long,long long> seg_tree[2][seg_size * 2+1];
pair<long long, long long> seg_find(int now, int w_l, int w_r, int n_l, int n_r,int setting) {
	if (w_l <= n_l && n_r <= w_r) return seg_tree[setting][now];
	if (w_r <= n_l || n_r <= w_l) return make_pair(LONG_INF, -1);
	pair<long long, long long> a = seg_find(now * 2, w_l, w_r, n_l, (n_l + n_r) / 2, setting);
	pair<long long, long long> b = seg_find(now * 2 + 1, w_l, w_r, (n_l + n_r) / 2, n_r, setting);
	if (a.first < b.first) return a;
	else return b;
}
void seg_set(int now) {
	REP(q, 2) {
		if (seg_tree[q][now * 2].first < seg_tree[q][now * 2 + 1].first) {
			seg_tree[q][now] = seg_tree[q][now * 2];
		}
		else {
			seg_tree[q][now] = seg_tree[q][now * 2 + 1];
		}
	}
	if (now != 1) seg_set(now / 2);
	return;
}
vector<tuple<int, int, int>> edges;
int union_find[300000] = {};
int union_search(int a) {
	if (union_find[a] == a) return a;
	return union_find[a] = union_search(union_find[a]);
}
int union_merge(int a, int b) {
	a = union_search(a);
	b = union_search(b);
	union_find[a] = b;
	return 0;
}
#undef int
int main(){
	iostream::sync_with_stdio(false);
#define int long long
	int n, d;
	cin >> n >> d;
	vector<long long> inputs;
	vector<pair<long long, long long>> sortings;
	REP(i, n) {
		long long a;
		cin >> a;
		inputs.push_back(a);
		sortings.push_back(make_pair(a, i));
	}
	REP(i, 2) {
		REP(q, seg_size*2+1) {
			seg_tree[i][q] = make_pair(LONG_INF, -1);
		}
	}
	sort(sortings.begin(), sortings.end());
	for (int tea = 0; tea < n; ++tea) {
		int i = sortings[tea].second;
		//right connections
		if (i != n-1) {
			pair<long long, long long> now = seg_find(1, i + 1, seg_size, 0, seg_size, 0);
			if (now.second != -1) {
				long long costs = now.second - i;
				costs *= d;
				costs += inputs[i];
				costs += inputs[now.second];
				edges.push_back(make_tuple(costs, i, now.second));
			}
		}
		if (i != 0) {
			pair<long long, long long> now = seg_find(1, 0, i, 0, seg_size, 1);
			if (now.second != -1) {
				long long costs = i - now.second;
				costs *= d;
				costs += inputs[i];
				costs += inputs[now.second];
				edges.push_back(make_tuple(costs, i, now.second));
			}
		}
		seg_tree[0][i + seg_size] = make_pair(inputs[i] + i * d, i);
		seg_tree[1][i + seg_size] = make_pair(inputs[i] - i * d, i);
		seg_set((i + seg_size) / 2);
	}
	sort(edges.begin(), edges.end());
	long long ans = 0;
	for (int i = 0; i < 300000; ++i) {
		union_find[i] = i;
	}
	for (int i = 0; i < edges.size(); ++i) {
		int a = get<1>(edges[i]);
		int b = get<2>(edges[i]);
		if (union_search(a) != union_search(b)) {
			union_merge(a, b);
			ans += get<0>(edges[i]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 57948