#include <bits/stdc++.h>
using namespace std;
struct Unionfind {
  vector<int> par;
  Unionfind(int n = 1) : par(n, -1) {}
  int root(int x) {
    if (par[x] < 0) return x;
    return par[x] = root(par[x]);
  }
  bool issame(int x, int y) { return root(x) == root(y); }
  bool uni(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return 0;
    if (par[x] > par[y]) swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return 1;
  }
  int size(int x) { return -par[root(x)]; }
};
struct dat {
  long long cost, x, y;
  bool operator<(const dat &r) const { return cost > r.cost; }
};
long long n, d;
vector<long long> a, pre, suf;
priority_queue<dat> pq;
long long solve();
int main() {
  cin >> n >> d;
  a.resize(n);
  for (auto &p : a) cin >> p;
  cout << solve() << endl;
  return 0;
}
long long solve() {
  for (int i = 1, id = 0; i < n; ++i) {
    pq.push({(i - id) * d + a[id] + a[i], id, i});
    if (-id * d + a[id] > -i * d + a[i]) id = i;
  }
  for (int i = n - 2, id = n - 1; i >= 0; --i) {
    pq.push({(id - i) * d + a[id] + a[i], id, i});
    if (id * d + a[id] > i * d + a[i]) id = i;
  }
  long long res = 0;
  Unionfind uf(n);
  while (pq.size()) {
    dat now = pq.top();
    pq.pop();
    if (!uf.issame(now.x, now.y)) {
      res += now.cost;
      uf.uni(now.x, now.y);
    }
  }
  return res;
}
