#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 7;
const long long INF = 1e18 + 239;
namespace DSU {
long long n;
long long cnt;
long long p[N];
long long rank[N];
long long get(long long v) {
  if (p[v] != v) {
    p[v] = get(p[v]);
  }
  return p[v];
}
long long merge(long long a, long long b) {
  a = get(a);
  b = get(b);
  if (a == b) {
    return 0;
  } else {
    if (rank[a] < rank[b]) {
      swap(a, b);
    }
    cnt--;
    p[b] = a;
    if (rank[a] == rank[b]) {
      rank[a]++;
    }
    return 1;
  }
}
void init(long long n_) {
  n = n_;
  cnt = n;
  for (long long i = 0; i < n; i++) {
    p[i] = i;
    rank[i] = 0;
  }
}
}  // namespace DSU
struct SegmentTree {
  long long n;
  vector<pair<long long, long long>> t;
  void pull(long long v) { t[v] = min(t[2 * v + 1], t[2 * v + 2]); }
  void build(long long v, long long l, long long r, vector<long long> &a) {
    if (l + 1 == r) {
      t[v] = {a[l], l};
    } else {
      long long m = (r + l) >> 1;
      build(2 * v + 1, l, m, a);
      build(2 * v + 2, m, r, a);
      pull(v);
    }
  }
  SegmentTree() {}
  SegmentTree(vector<long long> &a) {
    t.clear();
    n = (long long)a.size();
    t.resize(4 * n);
    build(0, 0, n, a);
  }
  void set(long long v, long long l, long long r, long long pos,
           long long val) {
    if (l + 1 == r) {
      t[v] = {val, pos};
    } else {
      long long m = (r + l) >> 1;
      if (pos < m) {
        set(2 * v + 1, l, m, pos, val);
      } else {
        set(2 * v + 2, m, r, pos, val);
      }
      pull(v);
    }
  }
  void set(long long pos, long long val) { set(0, 0, n, pos, val); }
  void query(long long v, long long l, long long r, long long ql, long long qr,
             pair<long long, long long> &ans) {
    if (qr <= l || r <= ql) {
      return;
    } else if (ql <= l && r <= qr) {
      ans = min(ans, t[v]);
    } else {
      long long m = (r + l) >> 1;
      query(2 * v + 1, l, m, ql, qr, ans);
      query(2 * v + 2, m, r, ql, qr, ans);
    }
  }
  long long min_ind(long long l, long long r) {
    if (l >= r) {
      return -1;
    } else {
      pair<long long, long long> ans = {INF, -1};
      query(0, 0, n, l, r, ans);
      return ans.second;
    }
  }
};
long long n, D;
long long a[N];
long long comp[N];
vector<long long> by_comp[N];
SegmentTree L;
SegmentTree R;
long long ans = 0;
void it() {
  for (long long i = 0; i < n; i++) {
    comp[i] = DSU::get(i);
    by_comp[comp[i]].push_back(i);
  }
  vector<long long> li(n);
  vector<long long> ri(n);
  for (long long i = 0; i < n; i++) {
    li[i] = -(i * D) + a[i];
    ri[i] = (i * D) + a[i];
  }
  {
    L = SegmentTree(li);
    R = SegmentTree(ri);
  }
  for (long long some = 0; some < n; some++) {
    for (auto i : by_comp[some]) {
      L.set(i, INF);
      R.set(i, INF);
    }
    long long best = INF;
    long long best_j = -1;
    long long best_i = -1;
    for (auto i : by_comp[some]) {
      long long minl = L.min_ind(0, i);
      if (minl != -1 && best > (i * D) + a[i] + li[minl]) {
        best = (i * D) + a[i] + li[minl];
        best_j = minl;
        best_i = i;
      }
      long long minr = R.min_ind(i + 1, n);
      if (minr != -1 && best > -(i * D) + a[i] + ri[minr]) {
        best = -(i * D) + a[i] + ri[minr];
        best_j = minr;
        best_i = i;
      }
    }
    if (DSU::merge(best_i, best_j)) {
      ans += best;
    }
    for (auto i : by_comp[some]) {
      L.set(i, -(i * D) + a[i]);
      R.set(i, (i * D) + a[i]);
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> D;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  DSU::init(n);
  while (DSU::cnt > 1) {
    it();
  }
  cout << ans << '\n';
}
