#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;
template <typename T1, typename T2>
inline void chmin(T1 &a, const T2 &b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a, const T2 &b) {
  if (a < b) a = b;
}
template <typename T, typename E, typename F, typename G>
struct SegmentTree {
  int n;
  F f;
  G g;
  T ti;
  vector<T> dat;
  SegmentTree(){};
  SegmentTree(F f, G g, T ti) : f(f), g(g), ti(ti) {}
  void init(int n_) {
    n = 1;
    while (n < n_) n <<= 1;
    dat.assign(n << 1, ti);
  }
  void build(const vector<T> &v) {
    int n_ = v.size();
    init(n_);
    for (int i = 0; i < n_; i++) dat[n + i] = v[i];
    for (int i = n - 1; i; i--)
      dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
  }
  void update(int k, const E &x) {
    k += n;
    dat[k] = g(dat[k], x);
    while (k >>= 1) dat[k] = f(dat[(k << 1) | 0], dat[(k << 1) | 1]);
  }
  T operator[](int k) const { return dat[k + n]; }
  T query(int a, int b) const {
    T vl = ti, vr = ti;
    for (int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) vl = f(vl, dat[l++]);
      if (r & 1) vr = f(dat[--r], vr);
    }
    return f(vl, vr);
  }
};
template <typename T>
T prim(vector<vector<pair<int, T>>> &g) {
  int n = (int)g.size();
  T ret = 0;
  vector<bool> used(n, false);
  using P = pair<T, int>;
  priority_queue<P, vector<P>, greater<P>> que;
  que.push({0, 0});
  while (!que.empty()) {
    auto p = que.top();
    que.pop();
    if (used[p.second]) continue;
    used[p.second] = true;
    ret += p.first;
    for (auto &e : g[p.second]) {
      que.push({e.second, e.first});
    }
  }
  return ret;
}
int main() {
  using T = pair<lint, lint>;
  using E = lint;
  auto f = [](T a, T b) { return min(a, b); };
  auto g = [](T a, E b) { return make_pair(b, a.second); };
  T ti = {INF, -1};
  int n, D;
  cin >> n >> D;
  vector<pair<lint, lint>> dat(n);
  for (int i = 0; i < n; i++) {
    dat[i] = {INF, i};
  }
  SegmentTree<T, E, decltype(f), decltype(g)> sg1(f, g, ti);
  sg1.build(dat);
  SegmentTree<T, E, decltype(f), decltype(g)> sg2(f, g, ti);
  sg2.build(dat);
  vector<vector<pair<int, lint>>> graph(n);
  vector<lint> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    sg1.update(i, -i * D + a[i]);
    sg2.update(i, i * D + a[i]);
  }
  vector<pair<int, int>> pv(n);
  for (int i = 0; i < n; i++) pv[i] = {a[i], i};
  sort(pv.rbegin(), pv.rend());
  for (int i = 0; i < n; i++) {
    lint id = pv[i].second;
    lint id1 = sg1.query(0, id).second;
    lint id2 = sg2.query(id + 1, n).second;
    if (id1 != -1) {
      graph[id].push_back({id1, a[id] + a[id1] + (int)abs(id - id1) * D});
      graph[id1].push_back({id, a[id] + a[id1] + (int)abs(id - id1) * D});
    }
    if (id2 != -1) {
      graph[id].push_back({id2, a[id] + a[id2] + (int)abs(id - id2) * D});
      graph[id2].push_back({id, a[id] + a[id2] + (int)abs(id - id2) * D});
    }
  }
  cout << prim(graph) << endl;
  return 0;
}
