#include <bits/stdc++.h>
using namespace std;
inline int in() {
  char c = getchar();
  int neg = 1, x = 0;
  while (!isdigit(c)) (c == '-') ? neg = -1, c = getchar() : c = getchar();
  while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  return neg * x;
}
const int MAX = 2e5 + 5;
long long A[MAX], D, N, ret;
vector<pair<int, pair<int, int> > > e;
namespace DSU {
int par[MAX];
inline void init() {
  for (register int i = 1; i <= MAX - 1; i++) par[i] = i;
}
inline int find(int x) { return x == par[x] ? x : par[x] = find(par[x]); }
inline bool unite(int x, int y) {
  x = find(x), y = find(y);
  if (x == y) return false;
  par[x] = y;
  return true;
}
}  // namespace DSU
inline void solve(int l, int r) {
  if (l == r) return;
  int m = l + r >> 1, pl = -1, pr = -1;
  long long mnl = 9e18, mnr = 9e18;
  for (int i = l; i <= m; i++) {
    long long vl = A[i] - 1LL * D * i;
    if (mnl > vl) mnl = vl, pl = i;
  }
  for (int i = m + 1; i <= r; i++) {
    long long vr = A[i] + 1LL * D * i;
    if (mnr > vr) mnr = vr, pr = i;
  }
  for (int i = l; i <= m; i++) {
    long long vl = A[i] - 1LL * D * i;
    e.push_back(make_pair(vl + mnr, make_pair(i, pr)));
  }
  for (int i = m + 1; i <= r; i++) {
    long long vr = A[i] + 1LL * D * i;
    e.push_back(make_pair(mnl + vr, make_pair(pl, i)));
  }
  solve(l, m);
  solve(m + 1, r);
}
int main() {
  DSU::init();
  N = in(), D = in();
  for (register int i = 1; i <= N; i++) A[i] = in();
  solve(1, N);
  sort((e).begin(), (e).end());
  for (__typeof((e).begin()) it = (e).begin(); it != (e).end(); it++)
    ret += DSU::unite(it->second.first, it->second.second) * it->first;
  printf("%lld\n", ret);
  return 0;
}
