#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, y;
  long long w;
  bool operator<(node a) const { return w < a.w; }
} dt[200020];
int fa[200020], n, a[200020], D, tot;
long long b[200020], c[200020], ans;
int getfa(int x) { return x == fa[x] ? x : fa[x] = getfa(fa[x]); }
int main() {
  scanf("%d %d", &n, &D);
  for (register int i = 1; i <= n; i++)
    scanf("%d", &a[i]), b[i] = a[i] + (long long)D * i,
                        c[i] = a[i] - (long long)D * i;
  long long mn = b[n];
  int id = n;
  for (register int i = n - 1; i >= 1; i--) {
    dt[++tot] = (node){i, id, mn + a[i] - (long long)D * i};
    if (b[i] < mn) {
      mn = b[i], id = i;
    }
  }
  mn = c[1], id = 1;
  for (register int i = 2; i <= n; i++) {
    dt[++tot] = (node){i, id, mn + a[i] + (long long)D * i};
    if (c[i] < mn) {
      mn = c[i], id = i;
    }
  }
  sort(dt + 1, dt + tot + 1);
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (register int i = 1; i <= tot; i++) {
    int x = dt[i].x, y = dt[i].y;
    int p = getfa(x), q = getfa(y);
    if (p != q) {
      ans += dt[i].w;
      fa[p] = q;
    }
  }
  cout << ans << endl;
}
