#include <bits/stdc++.h>
using namespace std;
using P = pair<long long, long long>;
template <typename T>
T &chmin(T &a, const T &b) {
  return a = min(a, b);
}
template <typename T>
T &chmax(T &a, const T &b) {
  return a = max(a, b);
}
const long long INF = 1e+18;
const double EPS = 1e-9;
const long long MOD = 1000000007;
const long long dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
struct QuickFind {
  vector<long long> par;
  vector<vector<long long>> group;
  QuickFind(long long n) : par(n), group(n) {
    for (long long i = 0; i < n; i++) {
      par[i] = i;
      group[i].push_back(i);
    }
  }
  long long find(long long x) { return par[x]; }
  void unite(long long x, long long y) {
    x = par[x], y = par[y];
    if (x == y) return;
    if (group[x].size() < group[y].size()) swap(x, y);
    for (long long v : group[y]) par[v] = x;
    group[x].insert(group[x].end(), group[y].begin(), group[y].end());
    group[y].clear();
    par[y] = x;
  }
  bool same(long long x, long long y) { return par[x] == par[y]; }
};
struct RMQIndex {
  using P = pair<long long, long long>;
  long long seg, init;
  vector<P> dat;
  RMQIndex(long long n, long long init) : init(init), seg(1) {
    while (seg < n) seg *= 2;
    dat.resize(seg * 2 - 1);
    for (long long i = 0; i < seg; i++) dat[i + seg - 1] = make_pair(init, i);
    for (long long i = seg - 2; i >= 0; i--)
      dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]);
  }
  void update(long long i, long long x) {
    dat[i + seg - 1] = make_pair(x, i);
    i += seg - 1;
    while (i) {
      i = (i - 1) / 2;
      dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]);
    }
  }
  P get(long long a = 0, long long b = -1, long long k = 0, long long l = 0,
        long long r = -1) {
    if (b == -1) b = seg;
    if (r == -1) r = seg;
    if (b <= l || r <= a) return make_pair(init, a);
    if (a <= l && r <= b) return dat[k];
    return min(get(a, b, k * 2 + 1, l, (l + r) / 2),
               get(a, b, k * 2 + 2, (l + r) / 2, r));
  }
};
signed main() {
  long long n, d, a[200010], ans = 0;
  cin >> n >> d;
  for (long long i = 0; i < n; i++) cin >> a[i];
  QuickFind qf(n);
  vector<RMQIndex> rmq(2, RMQIndex(n, INF));
  for (long long i = 0; i < n; i++) {
    rmq[0].update(i, a[i] - d * i);
    rmq[1].update(i, a[i] + d * i);
  }
  while (1) {
    bool update = false;
    for (long long i = 0; i < n; i++) {
      if (qf.group[i].empty()) continue;
      P mi(INF, INF);
      for (long long v : qf.group[i]) {
        rmq[0].update(v, INF);
        rmq[1].update(v, INF);
      }
      for (long long v : qf.group[i]) {
        P p = rmq[0].get(0, v), q = rmq[1].get(v + 1);
        chmin(mi, min(P(p.first + d * v + a[v], p.second),
                      P(q.first - d * v + a[v], q.second)));
      }
      if (mi.second < n && !qf.same(i, mi.second)) {
        qf.unite(i, mi.second);
        ans += mi.first;
        update = true;
      }
      for (long long v : qf.group[i]) {
        rmq[0].update(v, a[v] - d * v);
        rmq[1].update(v, a[v] + d * v);
      }
    }
    if (!update) break;
  }
  cout << ans << endl;
}
