#pragma GCC optimize(2)
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)

const ll linf = 4e18 + 9;

struct segment_tree_min {
	static const int maxn = 1 << 18;
	ll mn[maxn << 1];
	void init() {
		for (int i = 1; i < (maxn << 1); ++ i)
			mn[i] = (ll)(1e18);
	}
	void upd(int x, ll v) {
		for (x += maxn; x; x >>= 1)
			mn[x] = min(mn[x], v);
	}
	ll qry(int l, int r) {
		ll ans = linf;
		for (l += maxn, r += maxn; l < r; l >>= 1, r >>= 1) {
			if (l & 1) ans = min(ans, mn[l ++]);
			if (r & 1) ans = min(ans, mn[-- r]);
		}
		return ans;
	}
} seg0_min, seg1_min;

struct segment_tree_fill {
	static const int maxn = 1 << 18;
	ll add[maxn << 1];
	pair <ll, int> mn[maxn << 1];
	void init() {
		for (int i = 1; i < (maxn << 1); ++ i)
			add[i] = 0;
		for (int i = 0; i < maxn; ++ i)
			mn[i + maxn] = mp(0, i);
		for (int i = maxn - 1; i; -- i)
			mn[i] = min(mn[i << 1], mn[i << 1 | 1]);
	}
	void pushdown(int x) {
		if (add[x]) {
			mn[x].first = min(mn[x].first + add[x], linf);
			if (x < maxn) {
				add[x << 1] += add[x];
				add[x << 1 | 1] += add[x];
			}
			add[x] = 0;
		}
	}
	void upd(int l, int r, ll v, int i = 1, int a = 0, int b = maxn) {
		if (l <= a && b <= r) {
			add[i] += v;
			pushdown(i);
			return ;
		}
		pushdown(i);
		if (r <= a || b <= l) return ;
		int m = (a + b) >> 1;
		upd(l, r, v, i << 1, a, m);
		upd(l, r, v, i << 1 | 1, m, b);
		mn[i] = min(mn[i << 1], mn[i << 1 | 1]);
	}
	pair <ll, int> qry(int l, int r, int i = 1, int a = 0, int b = maxn) {
		pushdown(i);
		if (l <= a && b <= r) return mn[i];
		if (r <= a || b <= l) return mp(linf, -1);
		int m = (a + b) >> 1;
		pair <ll, int> ans = mp(linf, -1);
		ans = min(ans, qry(l, r, i << 1, a, m));
		ans = min(ans, qry(l, r, i << 1 | 1, m, b));
		return ans;
	}
} seg0_fill, seg1_fill;

const int maxn = 2e5 + 5;
int n, d;
int a[maxn];
ll u[maxn], v[maxn];

int main() {
	scanf("%d %d", &n, &d);
	for (int i = 0; i < n; ++ i) {
		scanf("%d", &a[i]);
		u[i] = a[i] + 1LL * d * i;
		v[i] = a[i] - 1LL * d * i;
	}
	seg0_min.init(); seg1_min.init();
	seg0_fill.init(); seg1_fill.init();
	seg0_min.upd(0, v[0]); seg1_min.upd(0, u[0]);
	for (int i = 0; i < n; ++ i) {
		seg0_fill.upd(i, i + 1, i == 0 ? linf : u[i] + v[0]);
		seg1_fill.upd(i, i + 1, (ll)(1e18) + v[i]);
	}
	ll ans = 0;
	for (int i = 1; i < n; ++ i) {
//		for (int j = 0; j < n; ++ j)
//			eprintf("%lld ", seg0_fill.qry(j, j + 1).first);
//		eprintf("\n");
//		for (int j = 0; j < n; ++ j)
//			eprintf("%lld ", seg1_fill.qry(j, j + 1).first);
//		eprintf("\n");
		pair <ll, int> p = min(seg0_fill.qry(0, n), seg1_fill.qry(0, n));
		int x = p.second; ans += p.first;
//		eprintf(" -> %d \n", x);
		seg0_fill.upd(x, x + 1, linf); seg1_fill.upd(x, x + 1, linf);
		int cur = x + 1;
		while (cur < n && seg0_min.qry(0, cur) >= v[x]) {
			int lb = cur, rb = n;
			while (lb < rb) {
				int md = (lb + rb + 1) >> 1;
				if (seg0_min.qry(0, md) == seg0_min.qry(0, cur))
					lb = md;
				else
					rb = md - 1;
			}
			seg0_fill.upd(cur, lb, v[x] - seg0_min.qry(0, lb));
			cur = lb + 1;
		}
//		for (int i = x; i < n; ++ i) {
//			if (seg0_min.qry(0, i) >= v[x])
//				seg0_fill.upd(i, i + 1, v[x] - seg0_min.qry(0, i));
//		}
		cur = x;
		while (cur && seg1_min.qry(cur, n) >= u[x]) {
			int lb = 0, rb = cur;
			while (lb < rb) {
				int md = (lb + rb) >> 1;
				if (seg1_min.qry(md, n) == seg1_min.qry(cur, n))
					rb = md;
				else
					lb = md + 1;
			}
			seg1_fill.upd(lb, cur, u[x] - seg1_min.qry(lb, n));
			cur = lb - 1;
		}
//		for (int i = x; ~i; -- i) {
//			if (seg1_min.qry(i, n) >= u[x])
//				seg1_fill.upd(i, i + 1, u[x] - seg1_min.qry(i, n));
//		}
		seg0_min.upd(x, v[x]); seg1_min.upd(x, u[x]);
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 36864