#include <bits/stdc++.h>
using namespace std;
void _main();
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  _main();
}
const int inf = INT_MAX / 2;
const long long infl = 1LL << 60;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
struct UnionFind {
  vector<int> par;
  UnionFind() {}
  UnionFind(int NV) { init(NV); }
  void init(int NV) {
    par.clear();
    for (int i = 0; i < NV; i++) par.push_back(i);
  }
  void reset() {
    for (int i = 0; i < par.size(); i++) par[i] = i;
  }
  int operator[](int x) {
    return par[x] == x ? x : par[x] = operator[](par[x]);
  }
  void operator()(int x, int y) {
    x = operator[](x);
    y = operator[](y);
    if (x != y) par[x] = y;
  }
};
template <class V, int NV>
struct SegTree {
  const V def = make_pair(infl, inf);
  V comp(V &l, V &r) { return min(l, r); };
  vector<V> val;
  SegTree() { val = vector<V>(NV * 2, def); }
  V get(int x, int y, int l = 0, int r = NV, int k = 1) {
    if (r <= x || y <= l) return def;
    if (x <= l && r <= y) return val[k];
    auto a = get(x, y, l, (l + r) / 2, k * 2);
    auto b = get(x, y, (l + r) / 2, r, k * 2 + 1);
    return comp(a, b);
  }
  void update(int i, V v) {
    i += NV;
    val[i] = v;
    while (i > 1) i >>= 1, val[i] = comp(val[i * 2], val[i * 2 + 1]);
  }
  void add(int i, V v) { update(i, val[i + NV] + v); }
  V operator[](int x) { return get(x, x + 1); }
};
int N, D, A[201010];
vector<int> uf[201010];
int cnt[201010];
int P[201010];
SegTree<pair<long long, int>, 1 << 18> ufst, lft, rht;
UnionFind u;
void _main() {
  cin >> N >> D;
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < N; i++) lft.update(i, {-1LL * i * D + A[i], i});
  for (int i = 0; i < N; i++) rht.update(i, {1LL * i * D + A[i], i});
  vector<pair<long long, pair<int, int>>> E;
  for (int i = 0; i < N; i++) {
    int opt = -1;
    long long mics = infl;
    auto p = lft.get(0, i);
    long long cst = p.first + 1LL * i * D + A[i];
    if (cst < mics) {
      mics = cst;
      opt = p.second;
    }
    if (0 <= opt and opt < N) E.push_back({mics, {i, opt}});
    opt = -1;
    mics = infl;
    p = rht.get(i + 1, N);
    cst = p.first - 1LL * i * D + A[i];
    if (cst < mics) {
      mics = cst;
      opt = p.second;
    }
    if (0 <= opt and opt < N) E.push_back({mics, {i, opt}});
  }
  sort((E).begin(), (E).end());
  long long ans = 0;
  u.init(N);
  for (auto &p : E) {
    if (u[p.second.first] != u[p.second.second]) {
      ans += p.first;
      u(p.second.first, p.second.second);
    }
  }
  cout << ans << endl;
}
