#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#define my_abs(x) ((x) < 0 ? -(x) : (x))
#define mp std::make_pair
#define pb push_back
using ll = long long;
struct segT
{
	ll mn[800005], mn2[800005];
	int col[800005], col2[800005];
	void push_up(int u)
	{
		int x = u << 1, y = u << 1 | 1;
		mn[u] = std::min(mn[x], mn[y]);
		col[u] = mn[x] < mn[y] ? col[x] : col[y];
		ll a = col[x] == col[u] ? mn2[x] : mn[x],
		   b = col[y] == col[u] ? mn2[y] : mn[y];
		mn2[u] = std::min(a, b);
		col2[u] = a < b ?
				  (col[x] == col[u] ? col2[x] : col[x]) :
				  (col[y] == col[u] ? col2[y] : col[y]);
	}
	void init(int u, int l, int r, int pos, ll val)
	{
		if (l == r)
		{
			mn[u] = val;
			col[u] = pos;
			mn2[u] = 1e18;
			col2[u] = -1;
			return;
		}
		int m = l + r >> 1;
		if (pos <= m)
			init(u << 1, l, m, pos, val);
		else
			init(u << 1 | 1, m + 1, r, pos, val);
		push_up(u);
	}
	void modify(int u, int l, int r, int pos, int x)
	{
		if (l == r)
		{
			col[u] = x;
			return;
		}
		int m = l + r >> 1;
		if (pos <= m)
			modify(u << 1, l, m, pos, x);
		else
			modify(u << 1 | 1, m + 1, r, pos, x);
		push_up(u);
	}
	std::pair<ll, int> query(int u, int l, int r, int L, int R, int c)
	{
		if (L > R)
			return {1e18, -1};
		if (L <= l && r <= R)
		{
			if (c == col[u])
				return {mn2[u], col2[u]};
			return {mn[u], col[u]};
		}
		int m = l + r >> 1;
		std::pair<ll, int> res = {1e18, -1};
		if (L <= m)
			res = std::min(res, query(u << 1, l, m, L, R, c));
		if (m < R)
			res = std::min(res, query(u << 1 | 1, m + 1, r, L, R, c));
		return res;
	}
} seg_l, seg_r;
int arr[200005], comp[200005], idx[200005], fa[200005];
std::pair<ll, int> mn[200005];
int getfa(int u) { return u == fa[u] ? u : fa[u] = getfa(fa[u]); }
inline bool same(int u, int v) { return getfa(u) == getfa(v); }
inline void unite(int u, int v) { fa[getfa(u)] = getfa(v); }
int main()
{
	// freopen("keyence2019-E.in", "r", stdin);
	int n, d;
	scanf("%d%d", &n, &d);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", arr + i);
		seg_l.init(1, 0, n - 1, i, arr[i] - (ll)i * d);
		seg_r.init(1, 0, n - 1, i, arr[i] + (ll)i * d);
		comp[i] = i;
	}
	int comp_cnt = n;
	ll ans = 0;
	while (comp_cnt != 1)
	{
		for (int i = 0; i < comp_cnt; i++)
			mn[i] = {1e18, -1};
		for (int i = 0; i < n; i++)
		{
			auto res = seg_l.query(1, 0, n - 1, 0, i - 1, comp[i]);
			res.first += arr[i] + (ll)i * d;
			mn[comp[i]] = std::min(mn[comp[i]], res);
			res = seg_r.query(1, 0, n - 1, i + 1, n - 1, comp[i]);
			res.first += arr[i] - (ll)i * d;
			mn[comp[i]] = std::min(mn[comp[i]], res);
		}
		for (int i = 0; i < comp_cnt; i++)
			fa[i] = i;
		for (int i = 0; i < comp_cnt; i++)
		{
			if (mn[i].second == -1)
				throw;
			if (same(i, mn[i].second))
				continue;
			ans += mn[i].first;
			unite(i, mn[i].second);
		}
		int nxt = 0;
		for (int i = 0; i < comp_cnt; i++)
		{
			if (i == fa[i])
				idx[i] = nxt++;
		}
		for (int i = 0; i < n; i++)
		{
			comp[i] = idx[getfa(comp[i])];
			seg_l.modify(1, 0, n - 1, i, comp[i]);
			seg_r.modify(1, 0, n - 1, i, comp[i]);
		}
		comp_cnt = nxt;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 43264