#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
template <class T>
inline bool MX(T &l, const T &r) {
  return l < r ? l = r, 1 : 0;
}
template <class T>
inline bool MN(T &l, const T &r) {
  return l > r ? l = r, 1 : 0;
}
const long long INF = 1LL << 61;
int N;
int size;
long long D;
long long A[214514];
pair<long long, long long> seg1[1 << 23];
pair<long long, long long> seg2[1 << 23];
template <class M>
struct MonoidSegTree {
  int n;
  int size;
  vector<M> seg;
  MonoidSegTree(const vector<M> A) {
    n = A.size();
    size = 1;
    while (size < n) size *= 2;
    seg.resize(size);
    seg.insert(seg.end(), A.begin(), A.end());
    seg.resize(size * 2);
    for (int(i) = (size)-1; (i) >= 0; --(i))
      seg[i] = seg[i * 2] * seg[i * 2 + 1];
  }
  void Update(int k, const M v) {
    k += size;
    seg[k] = v;
    while (k > 1) {
      k /= 2;
      seg[k] = seg[k * 2] * seg[k * 2 + 1];
    }
  }
  M Get(int l, int r) {
    M retl = M();
    M retr = M();
    l += size;
    r += size;
    for (; l < r; l >>= 1, r >>= 1) {
      if (r & 1) retr = seg[--r] * retr;
      if (l & 1) retl = retl * seg[l++];
    }
    return retl * retr;
  }
  M At(int k) { return seg[k + size]; }
};
struct Monoid {
  pair<long long, long long> p;
  Monoid() { p = pair<long long, long long>(INF, INF); }
  Monoid(const Monoid &m) : p(m.p) {}
  Monoid(pair<long long, long long> q) : p(q) {}
  Monoid operator*(Monoid m) { return min(p, m.p); }
};
using Seg = MonoidSegTree<Monoid>;
vector<int> belong;
vector<vector<int>> grps;
signed main() {
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(0);
  cin >> N >> D;
  size = 1;
  while (size < N) size <<= 1;
  belong.resize(N);
  grps.resize(N);
  vector<Monoid> v1, v2;
  for (int(i) = 0; (i) < (N); ++(i)) {
    cin >> A[i];
    v1.emplace_back(pair<long long, long long>(A[i] + i * D, i));
    v2.emplace_back(pair<long long, long long>(A[i] + (N - i) * D, i));
    grps[i].resize(1, i);
    belong[i] = i;
  }
  Seg seg1(v1);
  Seg seg2(v2);
  long long ans = 0;
  using Edge = pair<long long, pair<int, int>>;
  vector<Edge> mines;
  vector<pair<long long, long long>> restore1, restore2;
  for (int(_) = 0; (_) < (18); ++(_)) {
    mines.clear();
    for (auto &grp : grps) {
      restore1.clear();
      restore2.clear();
      for (int v : grp) {
        restore1.emplace_back(seg1.seg[size + v].p);
        seg1.Update(v, pair<long long, long long>(INF, INF));
        restore2.emplace_back(seg2.seg[size + v].p);
        seg2.Update(v, pair<long long, long long>(INF, INF));
      }
      Edge mine(INF, pair<int, int>(-1, -1));
      for (int v : grp) {
        pair<long long, long long> p = seg1.Get(v + 1, N).p;
        if (p.first != INF) {
          MN(mine, Edge(A[v] + A[p.second] + abs(v - p.second) * D,
                        pair<int, int>(v, p.second)));
        }
        pair<long long, long long> q = seg2.Get(0, v).p;
        if (q.first != INF) {
          MN(mine, Edge(A[v] + A[q.second] + abs(v - q.second) * D,
                        pair<int, int>(v, q.second)));
        }
      }
      for (auto &p : restore1) {
        seg1.Update(p.second, p);
      }
      for (auto &p : restore2) {
        seg2.Update(p.second, p);
      }
      mines.emplace_back(mine);
    }
    bool all = false;
    for (auto &e : mines) {
      long long c = e.first;
      int u, v;
      tie(u, v) = e.second;
      if (belong[u] == belong[v]) continue;
      ans += c;
      u = belong[u];
      v = belong[v];
      if (grps[u].size() > grps[v].size()) swap(u, v);
      grps[v].reserve(grps[v].size() + grps[u].size());
      for (int w : grps[u]) {
        belong[w] = v;
        grps[v].emplace_back(w);
      }
      grps[u].clear();
      if (grps[v].size() == N) all = true;
    }
    if (all) break;
  }
  cout << ans << "\n";
}
