#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2e5 + 1;
const long long INF = 2e18;
int solve();
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
int n;
long long D;
long long a[MAX_N];
pair<long long, long long> t[2][4 * MAX_N];
void build(int v, int LG, int RG) {
  if (LG == RG) {
    t[0][v] = make_pair(a[LG] - LG * D, LG);
    t[1][v] = make_pair(a[LG] + LG * D, LG);
    return;
  }
  int MG = (LG + RG) / 2;
  build(v * 2, LG, MG);
  build(v * 2 + 1, MG + 1, RG);
  t[0][v] = min(t[0][v * 2], t[0][v * 2 + 1]);
  t[1][v] = min(t[1][v * 2], t[1][v * 2 + 1]);
}
void update(int v, int LG, int RG, int pos) {
  if (LG == RG) {
    t[0][v].first = t[1][v].first = INF;
    t[0][v].second = t[1][v].second = INF;
    return;
  }
  int MG = (LG + RG) / 2;
  if (pos <= MG) {
    update(v * 2, LG, MG, pos);
  } else {
    update(v * 2 + 1, MG + 1, RG, pos);
  }
  t[0][v] = min(t[0][v * 2], t[0][v * 2 + 1]);
  t[1][v] = min(t[1][v * 2], t[1][v * 2 + 1]);
}
pair<long long, long long> get(int v, int LG, int RG, int l, int r, int fl) {
  if (r < l) {
    pair<long long, long long> res = make_pair(INF, INF);
    return res;
  }
  if (LG == l && RG == r) {
    return t[fl][v];
  }
  int MG = (LG + RG) / 2;
  return min(get(v * 2, LG, MG, l, min(MG, r), fl),
             get(v * 2 + 1, MG + 1, RG, max(MG + 1, l), r, fl));
}
set<int> lv;
set<int> pref;
set<int> suf;
set<pair<long long, long long> > rv;
long long minCost[MAX_N];
long long ans = 0;
void updateSuf(int v) {
  pair<long long, long long> newV = get(1, 1, n, v + 1, n, 1);
  if (newV.second != INF &&
      -v * D + a[v] + a[newV.second] + newV.second * D < minCost[newV.second]) {
    rv.erase(make_pair(minCost[newV.second], newV.second));
    minCost[newV.second] = -v * D + a[v] + a[newV.second] + newV.second * D;
    rv.insert(make_pair(minCost[newV.second], newV.second));
  }
  set<int>::iterator it = suf.upper_bound(v);
  it--;
  int cur = *it;
  set<int>::iterator it1 = it;
  it1++;
  int r = n;
  if (it1 != suf.end()) {
    r = *it1 - 1;
  }
  newV = get(1, 1, n, *it + 1, r, 1);
  if (newV.second != INF &&
      -(*it) * D + a[(*it)] + a[newV.second] + newV.second * D <
          minCost[newV.second]) {
    rv.erase(make_pair(minCost[newV.second], newV.second));
    minCost[newV.second] =
        -(*it) * D + a[(*it)] + a[newV.second] + newV.second * D;
    rv.insert(make_pair(minCost[newV.second], newV.second));
  }
  if (-v * D + a[v] >= -cur * D + a[cur]) {
    return;
  }
  newV = get(1, 1, n, cur + 1, n, 1);
  if (newV.second != INF &&
      -cur * D + a[cur] + a[newV.second] + newV.second * D <
          minCost[newV.second]) {
    rv.erase(make_pair(minCost[newV.second], newV.second));
    minCost[newV.second] = -cur * D + a[cur] + a[newV.second] + newV.second * D;
    rv.insert(make_pair(minCost[newV.second], newV.second));
  }
  int l = v + 1;
  while (true) {
    it = suf.upper_bound(v);
    if (it == suf.end()) {
      break;
    }
    cur = *it;
    if (-v * D + a[v] <= -cur * D + a[cur]) {
      set<int>::iterator it1 = it;
      it1++;
      int r = n;
      if (it1 != suf.end()) {
        r = *it1 - 1;
      }
      pair<long long, long long> change = get(1, 1, n, l, r, 1);
      if (change.second != INF &&
          -v * D + a[v] + a[change.second] + change.second * D <
              minCost[change.second]) {
        rv.erase(make_pair(minCost[change.second], change.second));
        minCost[change.second] =
            -v * D + a[v] + a[change.second] + change.second * D;
        rv.insert(make_pair(minCost[change.second], change.second));
      }
      l = r + 2;
      suf.erase(cur);
    } else {
      break;
    }
  }
  it1 = suf.upper_bound(v);
  r = n;
  if (it1 != suf.end()) {
    r = *it1 - 1;
  }
  pair<long long, long long> change = get(1, 1, n, v + 1, r, 1);
  if (change.second != INF &&
      -v * D + a[v] + a[change.second] + change.second * D <
          minCost[change.second]) {
    rv.erase(make_pair(minCost[change.second], change.second));
    minCost[change.second] =
        -v * D + a[v] + a[change.second] + change.second * D;
    rv.insert(make_pair(minCost[change.second], change.second));
  }
  suf.insert(v);
}
void updatePref(int v) {
  pair<long long, long long> newV = get(1, 1, n, 1, v - 1, 1);
  if (newV.second != INF &&
      v * D + a[v] + a[newV.second] - newV.second * D < minCost[newV.second]) {
    rv.erase(make_pair(minCost[newV.second], newV.second));
    minCost[newV.second] = v * D + a[v] + a[newV.second] - newV.second * D;
    rv.insert(make_pair(minCost[newV.second], newV.second));
  }
  if (pref.empty()) {
    pair<long long, long long> newV = get(1, 1, n, 1, v - 1, 0);
    if (newV.second != INF && v * D + a[v] + a[newV.second] - newV.second * D <
                                  minCost[newV.second]) {
      rv.erase(make_pair(minCost[newV.second], newV.second));
      minCost[newV.second] = v * D + a[v] + a[newV.second] - newV.second * D;
      rv.insert(make_pair(minCost[newV.second], newV.second));
    }
    pref.insert(v);
    return;
  }
  set<int>::iterator it = pref.upper_bound(v);
  int cur;
  if (it != pref.end()) {
    cur = *it;
    set<int>::iterator it1 = it;
    int l = 1;
    if (it1 != pref.begin()) {
      it1--;
      l = *it1 + 1;
    }
    pair<long long, long long> newV = get(1, 1, n, l, *it - 1, 0);
    if (newV.second != INF &&
        (*it) * D + a[(*it)] + a[newV.second] - newV.second * D <
            minCost[newV.second]) {
      rv.erase(make_pair(minCost[newV.second], newV.second));
      minCost[newV.second] =
          (*it) * D + a[(*it)] + a[newV.second] - newV.second * D;
      rv.insert(make_pair(minCost[newV.second], newV.second));
    }
    if (v * D + a[v] >= cur * D + a[cur]) {
      return;
    }
    newV = get(1, 1, n, 1, cur - 1, 0);
    if (newV.second != INF &&
        cur * D + a[cur] + a[newV.second] - newV.second * D <
            minCost[newV.second]) {
      rv.erase(make_pair(minCost[newV.second], newV.second));
      minCost[newV.second] =
          cur * D + a[cur] + a[newV.second] - newV.second * D;
      rv.insert(make_pair(minCost[newV.second], newV.second));
    }
  }
  int r = v - 1;
  while (true) {
    it = pref.upper_bound(v);
    if (it == pref.begin()) {
      break;
    }
    it--;
    cur = *it;
    if (v * D + a[v] <= cur * D + a[cur]) {
      set<int>::iterator it1 = it;
      int l = 1;
      if (it1 != pref.begin()) {
        it--;
        l = *it1 + 1;
      }
      pair<long long, long long> change = get(1, 1, n, l, r, 0);
      if (change.second != INF &&
          v * D + a[v] + a[change.second] - change.second * D <
              minCost[change.second]) {
        rv.erase(make_pair(minCost[change.second], change.second));
        minCost[change.second] =
            v * D + a[v] + a[change.second] - change.second * D;
        rv.insert(make_pair(minCost[change.second], change.second));
      }
      r = l - 2;
      pref.erase(cur);
    } else {
      break;
    }
  }
  set<int>::iterator it1 = pref.upper_bound(v);
  int l = 1;
  if (it1 != pref.begin()) {
    it1--;
    l = *it1 + 1;
  }
  pair<long long, long long> change = get(1, 1, n, l, v - 1, 0);
  if (change.second != INF &&
      v * D + a[v] + a[change.second] - change.second * D <
          minCost[change.second]) {
    rv.erase(make_pair(minCost[change.second], change.second));
    minCost[change.second] =
        v * D + a[v] + a[change.second] - change.second * D;
    rv.insert(make_pair(minCost[change.second], change.second));
  }
  pref.insert(v);
}
int solve() {
  cin >> n >> D;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; ++i) {
    minCost[i] = INF;
  }
  build(1, 1, n);
  minCost[1] = 0;
  lv.insert(1);
  pref.insert(1);
  suf.insert(1);
  update(1, 1, n, 1);
  pair<long long, long long> cur = get(1, 1, n, 2, n, 1);
  rv.insert(make_pair(-1 * D + a[1] + cur.first, cur.second));
  minCost[cur.second] = -1 * D + a[1] + cur.first;
  while ((int)lv.size() < n) {
    pair<long long, long long> it = *rv.begin();
    rv.erase(it);
    ans += it.first;
    update(1, 1, n, it.second);
    updateSuf(it.second);
    updatePref(it.second);
    lv.insert(it.second);
  }
  cout << ans << '\n';
  return 0;
}
