#include <bits/stdc++.h>
using namespace std;
using ld = double;
using ll = long long;
using ull = unsigned long long;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int SZ = 1 << 13;
char buff[SZ], *pos = buff + SZ - 1;
inline ll read() {
  ll x = 0;
  int f = 1,
      c = (++pos == buff + SZ ? fread(pos = buff, 1, SZ, stdin), *pos : *pos);
  for (; !isdigit(c);
       c = (++pos == buff + SZ ? fread(pos = buff, 1, SZ, stdin), *pos : *pos))
    if (c == '-') f = -f;
  for (; isdigit(c);
       c = (++pos == buff + SZ ? fread(pos = buff, 1, SZ, stdin), *pos : *pos))
    x = (x << 3) + (x << 1) + (c ^ 48);
  return x * f;
}
const int N = 1 << 24;
int n, D;
int a[N];
ll e[N][3];
int m;
int id[N];
int idL[N];
int idR[N];
int par[N];
void init() {
  for (int i = 0; i < N; ++i) par[i] = i;
}
int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); }
void merge(int x, int y) {
  x = find(x), y = find(y);
  par[x] = y;
}
bool same(int x, int y) { return find(x) == find(y); }
int main() {
  init();
  n = read(), D = read();
  for (int i = 0; i < n; ++i) a[i] = read();
  for (int i = 0; i < n; ++i) idL[i] = idR[i] = i;
  sort(idL, idL + n,
       [&](int x, int y) { return 1LL * x * D + a[x] < 1LL * y * D + a[y]; });
  sort(idR, idR + n,
       [&](int x, int y) { return -1LL * x * D + a[x] < -1LL * y * D + a[y]; });
  for (int i = 0, j = 0; i < n; ++i) {
    while (j < n && idL[j] <= i) ++j;
    if (j == n) break;
    e[m][0] = i, e[m][1] = idL[j],
    e[m][2] = 1LL * (idL[j] - i) * D + a[i] + a[idL[j]], id[m] = m++;
  }
  for (int i = n - 1, j = 0; ~i; --i) {
    while (j < n && idR[j] >= i) ++j;
    if (j == n) break;
    e[m][0] = i, e[m][1] = idR[j],
    e[m][2] = 1LL * (i - idR[j]) * D + a[i] + a[idR[j]], id[m] = m++;
  }
  sort(id, id + m, [&](int a, int b) { return e[a][2] < e[b][2]; });
  ll ans = 0;
  for (int ii = 0; ii < m; ++ii) {
    int i = id[ii];
    if (!same(e[i][0], e[i][1])) {
      merge(e[i][0], e[i][1]);
      ans += e[i][2];
    }
  }
  printf("%lld\n", ans);
  return 0;
}
