#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:8809999999")
using namespace std;
typedef vector<vector<pair<long long, long long>>> gosh;
const long long mod = 1e9 + 7;
const long double eps = 1e-9;
const long long settled = 400007;
vector<long long> a;
gosh ed;
long long co = 0;
void DnC(long long d, long long le = 0, long long ri = a.size()) {
  co++;
  if (le >= ri - 1) return;
  DnC(d, le, (ri + le) / 2);
  DnC(d, (ri + le) / 2, ri);
  long long lem = 0, rim = (ri + le) / 2;
  for (long long i = le; i < (ri + le) / 2; i++) {
    long long cost1, cost2;
    cost1 = a[lem] - d * lem;
    cost2 = a[i] - d * i;
    if (cost2 < cost1) lem = i;
  }
  for (long long i = (ri + le) / 2; i < ri; i++) {
    long long cost1, cost2;
    cost1 = a[rim] + d * rim;
    cost2 = a[i] + d * i;
    if (cost2 < cost1) rim = i;
  }
  for (long long i = le; i < (ri + le) / 2; i++) {
    long long cle, cri;
    cle = a[i] - d * i;
    cri = a[rim] + d * rim;
    long long cost = cle + cri;
    ed[i].push_back(make_pair(cost, rim));
    if (i != lem) ed[rim].push_back(make_pair(cost, i));
  }
  for (long long i = (ri + le) / 2; i < ri; i++) {
    long long cle, cri;
    cle = a[lem] - d * lem;
    cri = a[i] + d * i;
    long long cost = cle + cri;
    ed[i].push_back(make_pair(cost, lem));
    if (i != rim) ed[lem].push_back(make_pair(cost, i));
  }
}
long long MSTcost() {
  long long ret = 0;
  set<pair<long long, long long>> pile;
  vector<long long> used(ed.size(), 0);
  long long cost = 0, sum = 0;
  pile.insert(make_pair(0, 0));
  while (pile.size()) {
    pair<long long, long long> cur;
    cur = *pile.begin();
    pile.erase(pile.begin());
    if (used[cur.second]) continue;
    used[cur.second] = 1;
    cost += cur.first;
    for (pair<long long, long long> edge : ed[cur.second]) {
      if (used[edge.second]) continue;
      pile.insert(edge);
    }
  }
  ret = cost;
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(NULL);
  long long n, d;
  cin >> n >> d;
  a.resize(n, 0);
  ed.resize(n);
  for (long long i = 0; i < ed.size(); i++) ed[i].reserve(20);
  for (long long i = 0; i < n; i++) cin >> a[i];
  DnC(d);
  long long val = MSTcost();
  vector<long long> test;
  cout << val;
  return 0;
}
