#include <bits/stdc++.h>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
template <ostream& out = cout, class... T>
void prints(T&&...) {}
template <ostream& out = cout, class... T>
void printw(T&&...) {}
template <ostream& out = cout, class... T>
void printwe(T&&...) {}
template <ostream& out = cout, class... T>
void printb(T&&...) {}
template <ostream& out = cout, class... T>
void printbe(T&&...) {}
template <ostream& out = cout, class... T>
void printd(T&&...) {}
template <ostream& out = cout, class... T>
void printde(T&&...) {}
template <ostream& out = cout, class... T>
void printdu(T&&...){};
template <class S, class T>
istream& operator>>(istream& in, pair<S, T>& p) {
  return in >> p.first >> p.second;
}
template <class T>
istream& operator>>(istream& in, vector<T>& v) {
  for (auto& e : v) {
    in >> e;
  }
  return in;
}
struct UnionFind {
  vector<int> elems;
  UnionFind(int n) : elems(n) {
    for (int i = 0; i < n; i++) {
      elems[i] = i;
    }
  }
  bool same(int a, int b) { return parent(a) == parent(b); }
  void unite(int a, int b) { elems[parent(a)] = parent(b); }
  int parent(int a) {
    if (a == elems[a]) {
      return a;
    }
    return elems[a] = parent(elems[a]);
  }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, d;
  cin >> n >> d;
  vector<ll> as(n);
  cin >> as;
  auto ls = as, rs = as;
  for (int i = 0; i < n; i++) {
    ls[i] += d * (n - i - 1);
    rs[i] += d * i;
  }
  vector<pair<ll, ll>> lsMins(n), rsMins(n);
  ll mini = MLL, mini0 = MLL;
  int idx = M, idx0 = M;
  for (int i = 1; i < n; i++) {
    if (ls[i - 1] < mini) {
      mini = ls[i - 1];
      idx = i - 1;
    }
    if (mini < mini0) {
      swap(mini, mini0);
      swap(idx, idx0);
    }
    lsMins[i] = {idx0, idx};
  }
  mini = MLL;
  mini0 = MLL;
  idx = M;
  idx0 = M;
  for (int i = n - 2; i >= 0; i--) {
    if (rs[i + 1] < mini) {
      mini = rs[i + 1];
      idx = i + 1;
    }
    if (mini < mini0) {
      swap(mini, mini0);
      swap(idx, idx0);
    }
    rsMins[i] = {idx0, idx};
  }
  printde(as);
  printde(ls, rs);
  printde(lsMins, rsMins);
  UnionFind uf(n);
  vector<ll> costs;
  vector<pair<ll, pair<int, int>>> cands;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 2; j++) {
      int i1 = (j ? lsMins[i].first : lsMins[i].second),
          i2 = (j ? rsMins[i].first : rsMins[i].second);
      if (i1 != M) {
        ll c1 = abs(i - i1) * d + as[i] + as[i1];
        cands.push_back({c1, pair<int, int>(i, i1)});
      }
      if (i2 != M) {
        ll c2 = abs(i - i2) * d + as[i] + as[i2];
        cands.push_back({c2, pair<int, int>(i, i2)});
      }
    }
  }
  ll ans = 0;
  sort(cands.begin(), cands.end());
  printde(cands);
  for (auto& cand : cands) {
    auto p = cand.second;
    if (uf.same(p.first, p.second)) {
      continue;
    }
    printde(p.first, p.second, cand.first);
    uf.unite(p.first, p.second);
    ans += cand.first;
  }
  cout << ans << '\n';
}
