#include <bits/stdc++.h>
class disjoint_set {
 private:
  std::size_t n, *par, *sz;

 public:
  disjoint_set() : n(0){};
  disjoint_set(std::size_t n_) : n(n_) {
    par = new std::size_t[n];
    sz = new std::size_t[n];
    for (std::size_t i = 0; i < n; ++i) par[i] = i, sz[i] = 1;
  }
  ~disjoint_set() { delete par, sz; }
  disjoint_set& operator=(const disjoint_set& ds) {
    n = ds.n;
    par = new std::size_t[n];
    sz = new std::size_t[n];
    for (std::size_t i = 0; i < n; ++i) par[i] = ds.par[i], sz[i] = ds.sz[i];
  }
  std::size_t size() const { return n; }
  std::size_t root(std::size_t vert) {
    if (vert == par[vert]) return vert;
    return par[vert] = root(par[vert]);
  }
  void link(std::size_t vertx, std::size_t verty) {
    vertx = root(vertx);
    verty = root(verty);
    if (vertx == verty) return;
    if (sz[vertx] > sz[verty])
      sz[vertx] += sz[verty], sz[verty] = 0, par[verty] = vertx;
    else
      sz[verty] += sz[vertx], sz[vertx] = 0, par[vertx] = verty;
  }
  bool connected(std::size_t vertx, std::size_t verty) {
    return root(vertx) == root(verty);
  }
};
using namespace std;
struct edge {
  int a, b;
  long long cost;
};
int main() {
  int N;
  long long D;
  cin >> N >> D;
  vector<long long> L(N), R(N);
  for (int i = 0; i < N; ++i) {
    long long x;
    cin >> x;
    L[i] = x - i * D;
    R[i] = x + i * D;
  }
  vector<edge> G;
  int ptr = -1;
  for (int i = 0; i < N; ++i) {
    if (ptr != -1) G.push_back(edge{ptr, i, L[ptr] + R[i]});
    if (ptr == -1 || L[ptr] > L[i]) ptr = i;
  }
  ptr = -1;
  for (int i = N - 1; i >= 0; --i) {
    if (ptr != -1) G.push_back(edge{ptr, i, R[ptr] + L[i]});
    if (ptr == -1 || R[ptr] > R[i]) ptr = i;
  }
  sort(G.begin(), G.end(), [&](edge e1, edge e2) { return e1.cost < e2.cost; });
  disjoint_set uf(N);
  long long cost = 0;
  for (edge e : G) {
    if (!uf.connected(e.a, e.b)) {
      uf.link(e.a, e.b);
      cost += e.cost;
    }
  }
  cout << cost << endl;
  return 0;
}
