#include <bits/stdc++.h>
using namespace std;
int n, d;
const int N = (int)3e5;
int a[N];
long long tr[N * 8][2];
int nm[N * 8][2];
bool tp;
void build(int v, int l, int r) {
  if (l == r) {
    tr[v][0] = a[l] + 1ll * l * d;
    tr[v][1] = a[l] - 1ll * l * d;
    nm[v][0] = nm[v][1] = l;
    return;
  }
  int mid = (r + l) / 2;
  build(v * 2, l, mid);
  build(v * 2 + 1, mid + 1, r);
  for (int t = 0; t < 2; t++) {
    tr[v][t] = min(tr[v * 2][t], tr[v * 2 + 1][t]);
    if (tr[v][t] == tr[v * 2][t]) {
      nm[v][t] = nm[v * 2][t];
    } else {
      nm[v][t] = nm[v * 2 + 1][t];
    }
  }
}
void findMin(int v, int l, int r, int ll, int rr, int t, long long &mn,
             long long cur, int &p) {
  if (ll <= l && r <= rr) {
    if (tr[v][t] + cur < mn) {
      mn = tr[v][t] + cur;
      p = nm[v][t];
      if (t == 0) {
        tp = true;
      } else {
        tp = false;
      }
    }
    return;
  }
  int mid = (r + l) / 2;
  if (ll <= mid) findMin(v * 2, l, mid, ll, rr, t, mn, cur, p);
  if (rr > mid) findMin(v * 2 + 1, mid + 1, r, ll, rr, t, mn, cur, p);
}
long long solve(int l, int r, bool connected, long long curl, long long curr) {
  if (l == r) {
    return 0;
  }
  if (l + 1 == r) {
    if (connected) {
      return 0;
    }
  }
  long long mn = 1ll * a[l + 1] + a[l] + d;
  int p = l + 1;
  tp = true;
  findMin(1, 1, n, l + 1, r - connected, 0, mn, curl, p);
  findMin(1, 1, n, l + connected, r - 1, 1, mn, curr, p);
  long long ans = 0;
  ans += mn;
  if (tp) {
    ans += solve(l, p, true, curl, min(curr, 1ll * p * d + a[p])) +
           solve(p, r, false | connected, min(curl, a[p] - 1ll * p * d), curr);
  } else {
    ans += solve(l, p, false | connected, curl, min(curr, 1ll * p * d + a[p])) +
           solve(p, r, true, min(curl, a[p] - 1ll * p * d), curr);
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> d;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  build(1, 1, n);
  cout << solve(1, n, false, a[1] - d, a[n] + 1ll * n * d) << "\n";
  return 0;
}
