# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7; //924844033 1000000000 + 9;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, p, q, last, first, cnt, sum, ans, dp[200000];
Pll a[220000], b[220000];
string str, ss;
bool f[200000];
char c[4000][4000];
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
struct Edge { LL to, cost; };
struct edge {
	LL from, to, cost;
};
vector<vector<Edge>>vec;
vector<edge>ed;
vector<LL>v;
map<string, LL>ma;
set<LL>st;

void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Seg {
	LL n;
	vector<Pll>node;
	Seg(LL n_) {
		n = 1; while (n < n_)n *= 2;
		node.resize(n * 2 - 1);
		rep(i, n)node[n + i - 1] = Pll(INF,-1);
		Rrep(i, n - 2)node[i] = Pll(INF,-1);
	}

	void update(LL i, LL x) {
		LL y = i;
		i = i + n - 1;
		node[i] = Pll(x, y);
		while (i > 0) {
			i = (i - 1) / 2;
			node[i] = (node[i * 2 + 1].fir < node[i * 2 + 2].fir ? node[i * 2 + 1] : node[i * 2 + 2]);
		}
	}
	Pll find(LL l, LL r) {
		return find(0, 0, n - 1, l, r);
	}
	Pll find(LL i, LL a, LL b, LL l, LL r) {
		if (b< l || r < a)return Pll(INF,-1);
		if (l <= a && b <= r)return node[i];
		Pll x = find(i * 2 + 1, a, (a + b) / 2, l, r), y = find(i * 2 + 2, (a + b + 1) / 2, b, l, r);
		return (x.first < y.first ? x : y);
	}
};

Seg l(220000), r(220000);
int  par[220000];  // リーダーの値を格納 

int find(int x) { if (par[x] == x)return x; par[x] = find(par[x]); return par[x]; }
void unite(int x, int y) { x = find(x); y = find(y); if (x == y)return; par[x] = y; }
bool same(int x, int y) { return find(x) == find(y); }

int main() {
	cin >> n >> m;
	rep(i, n) {
		LL x;
		cin >> x;
		l.update(i, x - m * i);
		r.update(i, x + m * i);
		a[i] = Pll(x, i);
	}
	for (int i = 0; i<n; i++)par[i] = i;  // このように初期化
	sort(a, a + n, [](Pll x, Pll y) {return x.first > y.first; });
	rep(i, n) {
		LL p = a[i].sec; Pll x = l.find(0, p - 1), y = r.find(p + 1, n - 1);
		if (p - 1 >= 0 && x.fir != INF / 2)
			ed.push_back(edge{ p,x.sec,x.fir + m * p + a[i].fir });
		if (p + 1 <= n - 1&&y.fir!=INF/2)
			ed.push_back(edge{ p,y.sec,y.fir - m * p + a[i].fir });
		l.update(p, INF/2);
		r.update(p, INF/2);
	}
	sort(ed.begin(), ed.end(), [](edge x, edge y) {return x.cost < y.cost; });
	rep(i, ed.size()) {
		edge e = ed[i];
		if (!same(e.from, e.to)) {
			ans += e.cost;
			unite(e.from, e.to);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 40044