#include <bits/stdc++.h>
using namespace std;
long long M = 998244353;
const double PI = 2 * acos(0.0);
const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";
template <class T0, class T1>
inline ostream &operator<<(ostream &out, pair<T0, T1> &a) {
  return out << "{" << a.first << ", " << a.second << "}";
}
template <class T0, class T1, class T2>
inline ostream &operator<<(ostream &out, tuple<T0, T1, T2> &a) {
  return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a)
             << "}";
}
template <class T0, class T1, class T2, class T3>
inline ostream &operator<<(ostream &out, tuple<T0, T1, T2, T3> &a) {
  return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a)
             << ", " << get<3>(a) << "}";
}
template <class T>
inline ostream &operator<<(ostream &out, vector<T> &a) {
  out << "[";
  for (long long i = 0; i < long long(a.size()); ++i)
    out << a[i] << vector<string>{", ", "]  "}[i + 1 == a.size()];
  return out;
}
void smain();
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << setprecision(12) << fixed;
  smain();
}
const long long oo = (long long)1e18 + 100;
pair<long long, long long> t[2][4 * 20010];
long long a[20010];
long long n, d;
void upd(long long u, long long v, long long tl, long long tr, long long ps,
         long long vector<long long>) {
  if (tl == tr) {
    t[u][v] = {ps, vector<long long>};
  } else {
    long long tm = tl + tr >> 1;
    if (ps <= tm)
      upd(u, v << 1, tl, tm, ps, vector<long long>);
    else
      upd(u, v << 1 | 1, tm + 1, tr, ps, vector<long long>);
    if (t[u][v << 1].second < t[u][v << 1 | 1].second)
      t[u][v] = t[u][v << 1];
    else
      t[u][v] = t[u][v << 1 | 1];
  }
}
void init() {
  for (long long i = 0; i < 4 * 20010; i++) {
    t[0][i] = {oo, oo};
    t[1][i] = {oo, oo};
  }
}
pair<long long, long long> get(long long u, long long v, long long tl,
                               long long tr, long long l, long long r) {
  if (l > r) return {oo, oo};
  if (tl == l && tr == r) return t[u][v];
  long long tm = tl + tr >> 1;
  pair<long long, long long> p1 = get(u, v << 1, tl, tm, l, min(tm, r));
  pair<long long, long long> p2 =
      get(u, v << 1 | 1, tm + 1, tr, max(tm + 1, l), r);
  if (p1.second < p2.second)
    return p1;
  else
    return p2;
}
set<tuple<long long, long long, long long> > st;
void prec(long long i) {
  pair<long long, long long> pr1 = get(0, 1, 0, n - 1, i + 1, n - 1);
  pair<long long, long long> pr2 = get(1, 1, 0, n - 1, 0, i - 1);
  long long p1 = pr1.first, p2 = pr2.first, s1 = pr1.second, s2 = pr2.second;
  long long lol = oo, fr = oo, sc = oo;
  if (s1 != oo) {
    long long y = abs(i - p1) * d + a[i] + a[p1];
    if (y < lol) {
      lol = y;
      fr = i;
      sc = p1;
    }
  }
  if (s2 != oo) {
    long long y = abs(i - p2) * d + a[i] + a[p2];
    if (y < lol) {
      lol = y;
      fr = i;
      sc = p2;
    }
  }
  st.insert(make_tuple(lol, fr, sc));
}
void smain() {
  init();
  cin >> n >> d;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    upd(0, 1, 0, n - 1, i, a[i] + (i + 1) * d);
    upd(1, 1, 0, n - 1, i, a[i] + (n - i) * d);
  }
  long long ans = 0;
  prec(0);
  vector<long long> used(n);
  used[0] = 1;
  for (long long i = 1; i < n; i++) {
    auto kek = *st.begin();
    st.erase(st.begin());
    long long fr, sc, sum;
    tie(sum, fr, sc) = kek;
    while (used[fr] && used[sc]) {
      prec(fr);
      kek = *st.begin();
      st.erase(st.begin());
      tie(sum, fr, sc) = kek;
    }
    ans += abs(fr - sc) * d + a[fr] + a[sc];
    used[sc] = 1;
    upd(0, 1, 0, n - 1, fr, oo);
    upd(1, 1, 0, n - 1, fr, oo);
    upd(0, 1, 0, n - 1, sc, oo);
    upd(1, 1, 0, n - 1, sc, oo);
    prec(fr);
    prec(sc);
  }
  cout << ans;
}
