#include <bits/stdc++.h>
using namespace std;
struct segtree {
  size_t n;
  vector<pair<long long, long long>> val;
  segtree(vector<long long>& mot) : n(mot.size()), val(mot.size() * 2 + 1) {
    for (size_t i = 0; i < n; ++i) {
      val[i + n + 1] = pair<long long, long long>({mot[i], i});
    }
    for (size_t i = n; i > 0; --i) {
      val[i] = min(val[2 * i], val[2 * i + 1]);
    }
  }
  long long ask(size_t L, size_t R) {
    pair<long long, long long> ret(
        pair<long long, long long>(numeric_limits<long long>::max() / 3, -1));
    ++L;
    ++R;
    L += n;
    R += n;
    while (L < R) {
      if (L & 1) {
        ret = min(ret, val[L]);
        ++L;
      }
      if (R & 1) {
        ret = min(ret, val[R - 1]);
        --R;
      }
      L /= 2;
      R /= 2;
    }
    return ret.second;
  }
};
int main() {
  long long N, D;
  scanf("%lld%lld", &N, &D);
  vector<long long> A(N);
  for (auto& i : A) scanf("%lld", &i);
  vector<long long> RA(N), LA(N);
  for (int i = 0; i < N; ++i) {
    RA[i] = A[i] + i * D;
    LA[i] = A[i] - i * D;
  }
  segtree rs(RA), ls(LA);
  vector<pair<long long, long long>> AC;
  priority_queue<pair<long long, pair<long long, long long>>> pq;
  for (int i = 0; i < N - 1; ++i) {
    pq.emplace(-(A[i] + A[i + 1] + D), pair<long long, long long>(i, i + 1));
  }
  while (!pq.empty()) {
    auto t = pq.top();
    pq.pop();
    auto k = t.second.first, l = t.second.second;
    auto m = rs.ask(k + 1, N), n = ls.ask(0, l), o = ls.ask(0, k),
         p = ls.ask(l + 1, N);
    auto rrc = A[k] + A[m] + D * abs(m - k), lrc = A[k] + A[o] + D * abs(k - o),
         rlc = A[l] + A[p] + D * abs(p - l), llc = A[l] + A[n] + D * abs(l - n);
    if (m >= 0 && t.first + rrc < 0) {
      pq.emplace(-rrc, pair<long long, long long>(m, k));
    } else if (p >= 0 && t.first + rlc < 0) {
      pq.emplace(-rlc, pair<long long, long long>(p, l));
    } else if (o >= 0 && t.first + lrc < 0) {
      pq.emplace(-lrc, pair<long long, long long>(k, o));
    } else if (n >= 0 && t.first + llc < 0) {
      pq.emplace(-llc, pair<long long, long long>(l, n));
    } else {
      AC.emplace_back(k, l);
    }
  }
  long long ans(0);
  for (auto i : AC) {
    ans += A[i.first] + A[i.second] + D * abs(i.first - i.second);
  }
  printf("%lld\n", ans);
  return 0;
}
