#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

template <class T>
void chmin(T& a, T b) {
  if (b < a) a = b;
}

struct UnionFind {
  vector<int> parent;  // parent[root] is the negative of the size.
  UnionFind(int n)
      : parent(n, -1){};
  bool unite(int u, int v) {
    u = root(u);
    v = root(v);
    if (u == v) return false;
    if (parent[u] > parent[v]) swap(u, v);
    parent[u] += parent[v];
    parent[v] = u;
    return true;
  }
  bool find(int u, int v) {
    return root(u) == root(v);
  }
  int root(int u) {
    return parent[u] < 0 ? u : parent[u] = root(parent[u]);
  }
  int size(int u) {
    return -parent[root(u)];
  }
};

using P = pair<ll, int>;

struct Edge {
  int x, y;
  ll w;

  bool operator<(const Edge& rhs) const {
    return w < rhs.w;
  }
};

void push(vector<P>& ps, P x) {
  bool found = false;
  for (auto& y : ps) {
    if (y.snd == x.snd) {
      y = min(y, x);
      found = true;
    }
  }
  if (!found) ps.push_back(x);
  sort(ps.begin(), ps.end());
  if (ps.size() > 2)
    ps.resize(2);
}

const ll INF = 1ll << 60;

int main() {
  int N;
  ll D;
  while (cin >> N >> D) {
    vector<ll> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    UnionFind uf(N);
    int components = N;
    ll res = 0;
    while (components >= 2) {
      vector<Edge> edges(N, Edge{-1, -1, INF});
      vector<P> L, R;
      for (int i = 0; i < N; i++) {
        for (auto p : L) {
          if (uf.root(p.snd) != uf.root(i))
            chmin(edges[uf.root(i)], Edge{i, p.snd, p.fst + i * D + A[i]});
        }
        push(L, P(-i * D + A[i], i));
      }
      for (int i = N - 1; i >= 0; i--) {
        for (auto p : R) {
          if (uf.root(p.snd) != uf.root(i))
            chmin(edges[uf.root(i)], Edge{i, p.snd, p.fst - i * D + A[i]});
        }
        push(R, P(+i * D + A[i], i));
      }
      for (auto& e : edges) {
        if (e.w >= INF)
          continue;
        if (uf.unite(e.x, e.y)) {
          res += e.w;
          --components;
        }
      }
    }
    cout << res << endl;
  }
  return 0;
}
