#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
template <class T>
inline bool MX(T &l, const T &r) {
  return l < r ? l = r, 1 : 0;
}
template <class T>
inline bool MN(T &l, const T &r) {
  return l > r ? l = r, 1 : 0;
}
const long long INF = 1LL << 61;
int N;
int size;
long long D;
long long A[214514];
pair<long long, long long> seg1[1 << 23];
pair<long long, long long> seg2[1 << 23];
void Update(pair<long long, long long> *seg, int k,
            pair<long long, long long> x) {
  k += size - 1;
  seg[k] = x;
  while (k > 0) {
    k = (k - 1) / 2;
    seg[k] = min(seg[k * 2 + 1], seg[k * 2 + 2]);
  }
}
pair<long long, long long> GetMin(pair<long long, long long> *seg, int wishl,
                                  int wishr, int k, int watchl, int watchr) {
  int mid;
  pair<long long, long long> lval, rval;
  if (wishr <= watchl || watchr <= wishl)
    return pair<long long, long long>(INF, INF);
  if (wishl <= watchl && watchr <= wishr) return seg[k];
  mid = (watchl + watchr) / 2;
  lval = GetMin(seg, wishl, wishr, k * 2 + 1, watchl, mid);
  rval = GetMin(seg, wishl, wishr, k * 2 + 2, mid, watchr);
  return min(lval, rval);
}
vector<int> belong;
vector<vector<int>> grps;
signed main() {
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(0);
  cin >> N >> D;
  size = 1;
  while (size < N) size <<= 1;
  belong.resize(N);
  for (int(i) = 0; (i) < (N); ++(i)) {
    cin >> A[i];
    Update(seg1, i, pair<long long, long long>(A[i] + i * D, i));
    Update(seg2, i, pair<long long, long long>(A[i] + (N - i) * D, i));
    grps.emplace_back(vector<int>(1, i));
    belong[i] = i;
  }
  long long ans = 0;
  using Edge = pair<long long, pair<int, int>>;
  for (int(_) = 0; (_) < (18); ++(_)) {
    vector<Edge> mines;
    for (auto &grp : grps) {
      vector<pair<long long, long long>> restore1, restore2;
      for (int v : grp) {
        restore1.emplace_back(seg1[size - 1 + v]);
        Update(seg1, v, pair<long long, long long>(INF, INF));
        restore2.emplace_back(seg2[size - 1 + v]);
        Update(seg2, v, pair<long long, long long>(INF, INF));
      }
      Edge mine(INF, pair<int, int>(-1, -1));
      for (int v : grp) {
        pair<long long, long long> p = GetMin(seg1, v + 1, N, 0, 0, size);
        if (p.first != INF) {
          MN(mine, Edge(A[v] + A[p.second] + abs(v - p.second) * D,
                        pair<int, int>(v, p.second)));
        }
        pair<long long, long long> q = GetMin(seg2, 0, v, 0, 0, size);
        if (q.first != INF) {
          MN(mine, Edge(A[v] + A[q.second] + abs(v - q.second) * D,
                        pair<int, int>(v, q.second)));
        }
      }
      for (auto &p : restore1) {
        Update(seg1, p.second, p);
      }
      for (auto &p : restore2) {
        Update(seg2, p.second, p);
      }
      mines.emplace_back(mine);
    }
    bool all = false;
    for (auto &e : mines) {
      long long c = e.first;
      int u, v;
      tie(u, v) = e.second;
      if (belong[u] == belong[v]) continue;
      ans += c;
      u = belong[u];
      v = belong[v];
      if (grps[u].size() > grps[v].size()) swap(u, v);
      for (int w : grps[u]) {
        belong[w] = v;
        grps[v].emplace_back(w);
      }
      grps[u].clear();
      if (grps[v].size() == N) all = true;
    }
    if (all) break;
  }
  cout << ans << "\n";
}
