#include <bits/stdc++.h>
using namespace std;
const int Maxn = 200010;
const long long inf = (1LL << 61);
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
  return x * f;
}
int n, a[Maxn];
long long d, v[3][Maxn];
struct Node {
  int x, y;
  Node(int _x, int _y) { x = _x, y = _y; }
};
struct Seg {
  int l, r, lc, rc, pos, pos1;
} tr[3][Maxn << 1];
int tot[3];
void up(int o, int x) {
  int lc = tr[o][x].lc, rc = tr[o][x].rc;
  if (v[o][tr[o][lc].pos] < v[o][tr[o][rc].pos])
    tr[o][x].pos = tr[o][lc].pos, tr[o][x].pos1 = tr[o][lc].pos1;
  else
    tr[o][x].pos = tr[o][rc].pos, tr[o][x].pos1 = tr[o][rc].pos1;
}
void build(int o, int l, int r) {
  int x = ++tot[o];
  tr[o][x].l = l;
  tr[o][x].r = r;
  if (l == r) {
    tr[o][x].pos = l;
    tr[o][x].pos1 = l;
    return;
  }
  int mid = l + r >> 1;
  tr[o][x].lc = ++tot[o], build(o, l, mid);
  tr[o][x].rc = ++tot[o], build(o, mid + 1, r);
  up(o, x);
}
int O;
void modify(int o, int x, int p) {
  if (tr[o][x].l == tr[o][x].r) {
    if (o == 0) tr[o][x].pos1 = O;
    return;
  }
  int mid = tr[o][x].l + tr[o][x].r >> 1, lc = tr[o][x].lc, rc = tr[o][x].rc;
  if (p <= mid)
    modify(o, lc, p);
  else
    modify(o, rc, p);
  up(o, x);
}
int query(int o, int x, int l, int r) {
  if (l > r) return 0;
  if (tr[o][x].l == l && tr[o][x].r == r) {
    if (o == 0) O = tr[o][x].pos1;
    return tr[o][x].pos;
  }
  int mid = tr[o][x].l + tr[o][x].r >> 1, lc = tr[o][x].lc, rc = tr[o][x].rc;
  if (r <= mid) return query(o, lc, l, r);
  if (l > mid) return query(o, rc, l, r);
  int t1 = query(o, lc, l, mid), t2 = query(o, rc, mid + 1, r);
  if (v[o][t1] < v[o][t2]) return t1;
  return t2;
}
void Del(int Y2) {
  v[2][Y2] = inf;
  modify(2, 1, Y2);
  v[1][Y2] = inf;
  modify(1, 1, Y2);
}
void Ins(int Y2) {
  int t1 = query(1, 1, 1, Y2 - 1), t2 = query(2, 1, Y2 + 1, n);
  if (v[1][t1] + a[Y2] - (long long)Y2 * d <
      v[2][t2] + a[Y2] + (long long)Y2 * d) {
    O = t1;
    v[0][Y2] = v[1][t1] + a[Y2] - (long long)Y2 * d;
    modify(0, 1, Y2);
  } else {
    O = t2;
    v[0][Y2] = v[2][t2] + a[Y2] + (long long)Y2 * d;
    modify(0, 1, Y2);
  }
}
int main() {
  n = read(), d = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  v[0][0] = v[1][0] = v[2][0] = inf;
  for (int i = 1; i <= n; i++) v[0][i] = inf;
  for (int i = 1; i <= n; i++) v[1][i] = a[i] + (long long)i * d;
  for (int i = 1; i <= n; i++) v[2][i] = a[i] - (long long)i * d;
  build(0, 1, n), build(1, 1, n), build(2, 1, n);
  long long ans = 0, tmp = a[n] + (long long)n * d, mn = inf;
  int xx, Y1 = n;
  for (int i = n - 1; i; i--) {
    if (a[i] - (long long)i * d + tmp < mn)
      mn = a[i] - (long long)i * d + tmp, xx = i;
    if (a[i] + (long long)i * d < tmp) tmp = a[i] + (long long)i * d, Y1 = i;
  }
  tmp = a[1] - d;
  int Y2 = 1;
  bool flag = false;
  for (int i = 2; i <= n; i++) {
    if (a[i] + (long long)i * d + tmp < mn)
      mn = a[i] + (long long)i * d + tmp, xx = i, flag = true;
    if (a[i] - (long long)i * d < tmp) tmp = a[i] - (long long)i * d, Y2 = i;
  }
  ans += mn;
  Del(xx);
  if (flag)
    Del(Y2);
  else
    Del(Y1);
  Ins(xx);
  if (flag)
    Ins(Y2);
  else
    Ins(Y1);
  int m = n - 1;
  while (m--) {
    int t = query(0, 1, 1, n);
    ans += v[0][t];
    Del(O);
    Ins(O);
  }
  printf("%lld", ans);
}
