#include <bits/stdc++.h>
using namespace std;
class SegmentTree {
 public:
  int size_ = 1;
  vector<pair<long long, int>> dat;
  void init(int sz) {
    while (size_ <= sz) size_ *= 2;
    dat.resize(size_ * 2, make_pair(1LL << 60, 0));
    for (int i = size_; i < size_ * 2; i++) {
      int cx = i;
      dat[cx] = make_pair(1LL << 60, i - size_);
      while (cx >= 2) {
        cx >>= 1;
        dat[cx] = min(dat[cx * 2], dat[cx * 2 + 1]);
      }
    }
  }
  void update(int pos, long long x) {
    pos += size_;
    dat[pos] = make_pair(x, pos - size_);
    while (pos >= 2) {
      pos >>= 1;
      dat[pos] = min(dat[pos * 2], dat[pos * 2 + 1]);
    }
  }
  pair<long long, int> query_(int l, int r, int a, int b, int u) {
    if (l <= a && b <= r) return dat[u];
    if (r <= a || b <= l) return make_pair(1LL << 60, -1);
    pair<long long, int> v1 = query_(l, r, a, (a + b) >> 1, u * 2);
    pair<long long, int> v2 = query_(l, r, (a + b) >> 1, b, u * 2 + 1);
    return min(v1, v2);
  }
  pair<long long, int> query(int l, int r) { return query_(l, r, 0, size_, 1); }
};
long long N, D, A[1 << 18], group[1 << 18];
vector<int> G[1 << 18];
long long getdist(int u, int v) { return A[u] + A[v] + 1LL * D * abs(v - u); }
int main() {
  cin >> N >> D;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
    G[i].push_back(i);
    group[i] = i;
  }
  long long FinalAns = 0;
  while (true) {
    vector<int> B;
    for (int i = 1; i <= N; i++) {
      if (G[i].size() >= 1) B.push_back(i);
    }
    if (B.size() == 1) break;
    SegmentTree Z1;
    Z1.init(N + 2);
    for (int i = 1; i <= N; i++) Z1.update(i, A[i] - 1LL * D * i);
    SegmentTree Z2;
    Z2.init(N + 2);
    for (int i = 1; i <= N; i++) Z2.update(i, A[i] + 1LL * D * i);
    vector<pair<int, int>> L;
    for (int pos : B) {
      for (int j : G[pos]) {
        Z1.update(j, 1LL << 60);
        Z2.update(j, 1LL << 60);
      }
      for (int j : G[pos]) {
        pair<long long, int> v1 = Z1.query(1, j);
        v1.first += 1LL * D * j;
        pair<long long, int> v2 = Z2.query(j + 1, N + 1);
        v2.first -= 1LL * D * j;
        if (v1.first < v2.first)
          L.push_back(make_pair(v1.second, j));
        else
          L.push_back(make_pair(v2.second, j));
      }
      for (int j : G[pos]) {
        Z1.update(j, A[j] - 1LL * D * j);
        Z2.update(j, A[j] + 1LL * D * j);
      }
    }
    for (int j = 0; j < L.size(); j++) {
      if (L[j].first > L[j].second) swap(L[j].first, L[j].second);
    }
    sort(L.begin(), L.end());
    L.erase(unique(L.begin(), L.end()), L.end());
    for (int j = 0; j < L.size(); j++) {
      FinalAns += getdist(L[j].first, L[j].second);
      int ca = group[L[j].first], cb = group[L[j].second];
      if (G[ca].size() < G[cb].size()) swap(ca, cb);
      for (int j = 0; j < G[cb].size(); j++) {
        group[G[cb][j]] = ca;
        G[ca].push_back(G[cb][j]);
      }
      G[cb].clear();
    }
  }
  cout << FinalAns << endl;
  return 0;
}
