#include <bits/stdc++.h>
using namespace std;
using vi = vector<long long>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vp = vector<pair<long long, long long>>;
using vvp = vector<vp>;
using vb = vector<bool>;
using vvb = vector<vb>;
const long long inf = 1001001001001001001;
const int INF = 1001001001;
const int mod = 1000000007;
const double eps = 1e-10;
template <class T>
bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
void out(T a) {
  cout << a << '\n';
}
template <class T>
void outp(T a) {
  cout << '(' << a.first << ',' << a.second << ')' << '\n';
}
template <class T>
void outvp(T v) {
  for (long long i = 0; i < (long long)(v.size()); i++)
    cout << '(' << v[i].first << ',' << v[i].second << ')';
  cout << '\n';
}
template <class T>
void outvvp(T v) {
  for (long long i = 0; i < (long long)(v.size()); i++) outvp(v[i]);
}
template <class T>
void outv(T v) {
  for (long long i = 0; i < (long long)(v.size()); i++) {
    if (i) cout << ' ';
    cout << v[i];
  }
  cout << '\n';
}
template <class T>
void outvv(T v) {
  for (long long i = 0; i < (long long)(v.size()); i++) outv(v[i]);
}
template <class T>
bool isin(T x, T l, T r) {
  return (l) <= (x) && (x) <= (r);
}
template <class T>
void yesno(T b) {
  if (b)
    out("yes");
  else
    out("no");
}
template <class T>
void YesNo(T b) {
  if (b)
    out("Yes");
  else
    out("No");
}
template <class T>
void YESNO(T b) {
  if (b)
    out("YES");
  else
    out("NO");
}
template <class T>
void noyes(T b) {
  if (b)
    out("no");
  else
    out("yes");
}
template <class T>
void NoYes(T b) {
  if (b)
    out("No");
  else
    out("Yes");
}
template <class T>
void NOYES(T b) {
  if (b)
    out("NO");
  else
    out("YES");
}
void outs(long long a, long long b) {
  if (a >= inf - 100)
    out(b);
  else
    out(a);
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long modpow(long long a, long long b) {
  a %= mod;
  if (b == 0) return 1;
  if (b & 1) return a * modpow(a, b - 1) % mod;
  long long k = modpow(a, b / 2);
  return k * k % mod;
}
vp sega;
long long N = 1;
void inita(vi v) {
  while (N < v.size()) N *= 2;
  sega = vp(N * 2 - 1, pair<long long, long long>(inf, -1));
  for (long long i = 0; i < (long long)(v.size()); i++)
    sega[i + N - 1] = pair<long long, long long>(v[i], i);
  for (int i = N - 2; i >= 0; i--)
    sega[i] = min(sega[i * 2 + 1], sega[i * 2 + 2]);
}
void updatea(long long i, long long x) {
  i = N + i - 1;
  sega[i].first = x;
  while (i > 0) {
    i = (i - 1) / 2;
    sega[i] = min(sega[i * 2 + 1], sega[i * 2 + 2]);
  }
}
pair<long long, long long> getmia(long long a, long long b, long long k,
                                  long long l, long long r) {
  if (r <= a || b <= l) return pair<long long, long long>(inf, -1);
  if (a <= l && r <= b) return sega[k];
  pair<long long, long long> c1 = getmia(a, b, k * 2 + 1, l, (l + r) / 2);
  pair<long long, long long> c2 = getmia(a, b, k * 2 + 2, (l + r) / 2, r);
  return min(c1, c2);
}
vp segb;
void initb(vi v) {
  segb = vp(N * 2 - 1, pair<long long, long long>(inf, -1));
  for (long long i = 0; i < (long long)(v.size()); i++)
    segb[i + N - 1] = pair<long long, long long>(v[i], i);
  for (int i = N - 2; i >= 0; i--)
    segb[i] = min(segb[i * 2 + 1], segb[i * 2 + 2]);
}
void updateb(long long i, long long x) {
  i = N + i - 1;
  segb[i].first = x;
  while (i > 0) {
    i = (i - 1) / 2;
    segb[i] = min(segb[i * 2 + 1], segb[i * 2 + 2]);
  }
}
pair<long long, long long> getmib(long long a, long long b, long long k,
                                  long long l, long long r) {
  if (r <= a || b <= l) return pair<long long, long long>(inf, -1);
  if (a <= l && r <= b) return segb[k];
  pair<long long, long long> c1 = getmib(a, b, k * 2 + 1, l, (l + r) / 2);
  pair<long long, long long> c2 = getmib(a, b, k * 2 + 2, (l + r) / 2, r);
  return min(c1, c2);
}
int main() {
  long long n, d;
  cin >> n >> d;
  vi v(n);
  for (long long i = 0; i < (long long)(n); i++) cin >> v[i];
  vi a(n, inf), b(n, inf);
  for (long long i = 1; i < (long long)(n); i++) a[i] = d * i + v[i];
  for (long long i = 1; i < (long long)(n); i++) b[i] = d * (n - 1 - i) + v[i];
  inita(a);
  initb(b);
  priority_queue<tuple<long long, long long, long long>,
                 vector<tuple<long long, long long, long long>>,
                 greater<tuple<long long, long long, long long>>>
      pq;
  pq.push(
      {getmia(1, N, 0, 0, N).first + v[0], getmia(1, N, 0, 0, N).second, 0ll});
  long long ans = 0, cnt = 0;
  while (cnt < n - 1) {
    auto t = pq.top();
    pq.pop();
    long long cost = get<0>(t), i = get<1>(t), p = get<2>(t);
    bool done = false;
    if (sega[i + N - 1].first == inf) done = true;
    updatea(i, inf);
    updateb(i, inf);
    if (p != -1) {
      pair<long long, long long> x = getmia(p + 1, N, 0, 0, N),
                                 y = getmib(0, p, 0, 0, N);
      x.first -= p * d;
      y.first -= (n - p - 1) * d;
      pq.push({min(x, y).first + v[p], min(x, y).second, p});
    }
    if (done) continue;
    ans += cost;
    cnt++;
    pair<long long, long long> x = getmia(i + 1, N, 0, 0, N),
                               y = getmib(0, i, 0, 0, N);
    x.first -= i * d;
    y.first -= (n - i - 1) * d;
    pq.push({min(x, y).first + v[i], min(x, y).second, i});
  }
  out(ans);
}
