#include <bits/stdc++.h>
using namespace std;
using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;
const double eps = 1e-10;
template <typename A, typename B>
inline void chmin(A &a, B b) {
  if (a > b) a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b) {
  if (a < b) a = b;
}
class UnionFind {
 private:
  ::std::vector<int_fast32_t> par;
  size_t n;

 public:
  UnionFind() {}
  UnionFind(size_t n) : n(n) { par.resize(n, -1); }
  int_fast32_t find(int_fast32_t x) {
    if (x < 0) return -1;
    return par[x] < 0 ? x : par[x] = find(par[x]);
  }
  size_t size(uint_fast32_t x) { return -par[find(x)]; }
  bool unite(uint_fast32_t x, uint_fast32_t y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    if (size(x) < size(y)) std::swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }
  bool same(uint_fast32_t x, uint_fast32_t y) { return find(x) == find(y); }
};
int64 N, D;
vector<int64> A;
int64 dis(int64 a, int64 b) { return A[a] + A[b] + abs(a - b) * D; }
int64 Boruvka() {
  UnionFind uf(N);
  int64 res = 0;
  bool updated = 1;
  while (updated) {
    updated = 0;
    map<int64, PLL> match;
    int64 top[2] = {-1, -1};
    for (int64 i = 0; i < (N); i++) {
      int64 v = uf.find(i);
      for (int64 j = 0; j < (2); j++) {
        if (top[j] == -1) break;
        if (uf.find(top[j]) != v &&
            (match.count(v) == 0 || match[v].first > dis(top[j], i))) {
          match[v] = PLL(dis(top[j], i), top[j]);
          break;
        }
      }
      for (int64 j = 0; j < (2); j++) {
        if (top[j] == -1 || A[top[j]] - D * top[j] > A[i] - i * D) {
          if (j == 0 && uf.find(top[j]) != v) {
            top[1] = top[0];
          }
          top[j] = i;
          break;
        }
      }
    }
    top[0] = -1;
    top[1] = -1;
    for (int32 i = N - 1; i >= 0; i--) {
      int64 v = uf.find(i);
      for (int64 j = 0; j < (2); j++) {
        if (top[j] == -1) break;
        if (uf.find(top[j]) != v &&
            (match.count(v) == 0 || match[v].first > dis(top[j], i))) {
          match[v] = PLL(dis(top[j], i), top[j]);
          break;
        }
      }
      for (int64 j = 0; j < (2); j++) {
        if (top[j] == -1 || A[top[j]] + D * top[j] > A[i] + i * D) {
          if (j == 0 && uf.find(top[j]) != v) {
            top[1] = top[0];
          }
          top[j] = i;
          break;
        }
      }
    }
    for (auto x : match) {
      if (uf.unite(x.first, x.second.second)) {
        res += x.second.first;
        updated = 1;
      }
    }
  }
  for (int64 i = 0; i < (N); i++) {
    assert(uf.find(i) == uf.find(0));
  }
  return res;
}
int main(void) {
  cin >> N >> D;
  A.resize(N);
  for (int64 i = 0; i < (N); i++) cin >> A[i];
  cout << Boruvka() << endl;
}
