#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1e9;
const long long N = 200005;
long long n, d;
long long a[N];
struct qt {
  long long c, id;
  qt(){};
  qt(long long _c, long long _id) {
    c = _c;
    id = _id;
  }
};
struct qq {
  long long l, r;
  qt c[2];
  long long s1, s2;
} tr[N * 2];
long long num;
qt Merge(qt x, qt y) { return x.c < y.c ? x : y; }
void bt(long long l, long long r) {
  long long now = ++num;
  tr[now].l = l;
  tr[now].r = r;
  if (l == r) {
    tr[now].c[0].c = a[l] - l * d;
    tr[now].c[1].c = a[l] + l * d;
    tr[now].c[0].id = l;
    tr[now].c[1].id = l;
    return;
  }
  long long mid = (l + r) >> 1;
  tr[now].s1 = num + 1;
  bt(l, mid);
  tr[now].s2 = num + 1;
  bt(mid + 1, r);
  tr[now].c[0] = Merge(tr[tr[now].s1].c[0], tr[tr[now].s2].c[0]);
  tr[now].c[1] = Merge(tr[tr[now].s1].c[1], tr[tr[now].s2].c[1]);
}
vector<int> vec[N];
qt t[N];
long long tot = 0;
long long fa[N];
long long find_fa(long long x) {
  return fa[x] == x ? x : fa[x] = find_fa(fa[x]);
}
qt get(long long now, long long l, long long r, long long o) {
  if (l > r) return qt(MAX, MAX);
  if (tr[now].l == l && tr[now].r == r) return tr[now].c[o];
  long long s1 = tr[now].s1, s2 = tr[now].s2;
  long long mid = (tr[now].l + tr[now].r) >> 1;
  if (r <= mid)
    return get(s1, l, r, o);
  else if (l > mid)
    return get(s2, l, r, o);
  else
    return Merge(get(s1, l, mid, o), get(s2, mid + 1, r, o));
}
int main() {
  scanf("%lld%lld", &n, &d);
  for (long long u = 1; u <= n; u++) scanf("%lld", &a[u]);
  bt(1, n);
  tot = n;
  for (long long u = 1; u <= n; u++) {
    vec[u].push_back(u);
    qt x = get(1, 1, u - 1, 0), y = get(1, u + 1, n, 1);
    x.c = x.c + a[u] + u * d;
    y.c = y.c + a[u] - u * d;
    t[u] = Merge(x, y);
    fa[u] = u;
  }
  long long ans = 0;
  while (tot != 1) {
    for (long long i = 1; i <= n; i++) {
      if (find_fa(i) != i) continue;
      long long x = find_fa(t[i].id);
      if (x == i) continue;
      ans = ans + t[i].c;
      fa[i] = x;
      long long siz = vec[i].size();
      for (long long j = 0; j < siz; j++) vec[x].push_back(vec[i][j]);
    }
    tot = 0;
    for (long long i = 1; i <= n; i++) {
      if (find_fa(i) != i) continue;
      tot++;
      long long siz = vec[i].size();
      sort(vec[i].begin(), vec[i].end());
      long long lst = 0, j = 0;
      qt now = qt(MAX, MAX), x, y;
      t[i] = qt(MAX, MAX);
      for (long long u = 0; u < siz; u++) {
        if (u == siz - 1 || vec[i][u + 1] != vec[i][u] + 1) {
          x = get(1, lst + 1, vec[i][j] - 1, 0);
          y = get(1, vec[i][j], vec[i][u], 1);
          now = Merge(now, x);
          qt lalal;
          lalal.id = now.id;
          lalal.c = y.c + now.c;
          t[i] = Merge(t[i], lalal);
          j = u + 1;
          lst = vec[i][u];
        }
      }
      now = qt(MAX, MAX);
      lst = n + 1;
      j = siz - 1;
      for (long long u = siz - 1; u >= 0; u--) {
        if (u == 0 || vec[i][u - 1] != vec[i][u] - 1) {
          x = get(1, vec[i][j] + 1, lst - 1, 1);
          y = get(1, vec[i][u], vec[i][j], 0);
          now = Merge(now, x);
          qt lalal;
          lalal.id = now.id;
          lalal.c = y.c + now.c;
          t[i] = Merge(t[i], lalal);
          j = u - 1;
          lst = vec[i][u];
        }
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
