#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <tuple>
#include <random>
#include <cmath>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SZ = 2e5 + 10, INF = 1e9 * 1e9 + 10;

ll n, d;
pair<ll, ll> dist[SZ];
vector<ll> vec;
bool used[SZ];

vector<pair<ll, ll>> edges;
vector<vector<ll>> gr;

ll stresses() {
	edges.clear();

	for (int i = 0; i < n; i++) {
		dist[i] = { INF, INF };
		used[i] = 0;
	}
	dist[0] = { 0, 0 };

	ll ans = 0;
	for (int i = 0; i < n; i++) {
		pair<ll, ll> mn = { INF, INF };
		for (int j = 0; j < n; j++) {
			if (!used[j]) mn = min(mn, { dist[j].first, j });
		}

		if (i != 0) {
			edges.push_back({ dist[mn.second].second, mn.second });
		}
		used[mn.second] = 1;
		ans += mn.first;

		for (int j = 0; j < n; j++) {
			dist[j] = min(dist[j], make_pair(abs(mn.second - j) * d + vec[j] + vec[mn.second], mn.second));
		}
	}

	return ans;
}

bool check_pillar() {
	for (int i = 0; i < n; i++) {
		ll cnt = 0;
		for (auto to : gr[i]) {
			if (gr[to].size() >= 3) cnt++;
		}
		if (cnt >= 3) return false;
	}

	return true;
}

void input() {
	cin >> n >> d;
	vec.resize(n);
	for (int i = 0; i < n; i++) cin >> vec[i];
}

void rand_test() {
	n = 500, d = rand() % 500 + 1;
	vec.resize(n);
	for (int i = 0; i < n; i++) vec[i] = rand() % 500 + 1;
}

vector<vector<ll>> g;
vector<ll> good;

ll dst(int i, int j) {
	return vec[i] + vec[j] + d * abs(i - j);
}

ll sol() {
	g.clear();
	good.clear();
	set<pair<ll, ll>> s;
	s.insert({ vec[0], 0 });
	ll curAdd = 0;
	g.resize(n);
	for (int i = 1; i < n; i++) {
		curAdd += d;

		pair<ll, ll> v = *(s.begin());
		g[i].push_back(v.second);
		g[v.second].push_back(i);
		v.first += d;

		s.insert({ vec[i] - curAdd, i });
	}

	ll cur = 0;
	vector<bool> used(n);
	while (true) {
		good.push_back(cur);
		bool fl = false;
		used[cur] = 1;

		ll mx = -1;
		for (auto to : g[cur]) {
			if (!used[to] && g[to].size() >= 2) {
				fl = true;
				mx = max(mx, to);
			}
		}

		if (mx != -1) cur = mx;
		if (fl == false) {
			ll mx = -1;
			for (auto to : g[cur]) {
				if (!used[to]) {
					mx = max(mx, to);
				}
			}

			if (mx != -1) good.push_back(mx);
			break;
		}
	}

	sort(good.begin(), good.end());
	vector<ll> nw = good;
	good.clear();
	for (int i = 0; i < nw.size(); i++) {
		while (good.size() >= 2) {
			if (dst(good[good.size() - 2], good.back()) >= dst(good[good.size() - 2], nw[i])) {
				good.pop_back();
			}
			else {
				break;
			}
		}
		good.push_back(nw[i]);
	}
	ll ans = 0;
	for (int i = 0; i < good.size() - 1; i++) {
		ll v = good[i], u = good[i + 1];
		ans += (vec[v] + vec[u] + d * abs(u - v));
		for (int j = v + 1; j <= u - 1; j++) {
			ans += min(vec[v] + vec[j] + d * abs(v - j), vec[u] + vec[j] + d * abs(u - j));
		}
	}

	return ans;
}

int main()
{
	fastInp;

	input();
	cout << sol();
	return 0;

	ll cnt = 1000;
	while (cnt--) {
		rand_test();

		ll q = stresses();
		ll q2 = sol();

		gr.clear();
		gr.resize(n);
		if (q != q2) {
			for (auto cur : edges) {
				gr[cur.first].push_back(cur.second);
				gr[cur.second].push_back(cur.first);
				cout << cur.first << " " << cur.second << "\n";
			}
			cout << q << " " << q2 << "\n";
			cout << "";
		}

	}

	return 0;
}

Measured memory_bytes: 31484