#include <bits/stdc++.h>
using namespace std;
struct SimpleSegTree {
  int segn2;
  pair<long long, int> initVal;
  vector<pair<long long, int> > data;
  function<pair<long long, int>(pair<long long, int>, pair<long long, int>)>
      merge;
  SimpleSegTree(
      int n, pair<long long, int> initVal,
      function<pair<long long, int>(pair<long long, int>, pair<long long, int>)>
          merge)
      : initVal(initVal), merge(merge) {
    for (segn2 = 1; segn2 < n; segn2 *= 2)
      ;
    data.assign(segn2 * 2, initVal);
  }
  SimpleSegTree(int n)
      : SimpleSegTree(n, {2000000000000000000LL, -1},
                      [](pair<long long, int> a, pair<long long, int> b) {
                        return min(a, b);
                      }) {}
  SimpleSegTree(int n, pair<long long, int> initVal)
      : SimpleSegTree(n, initVal,
                      [](pair<long long, int> a, pair<long long, int> b) {
                        return min(a, b);
                      }) {}
  pair<long long, int> query(int a, int b, int l = 0, int r = -1, int k = 0) {
    if (r == -1) r = segn2;
    if (a <= l && r <= b) return data[k];
    if (r <= a || b <= l) return initVal;
    return merge(query(a, b, l, (l + r) / 2, k * 2 + 1),
                 query(a, b, (l + r) / 2, r, k * 2 + 2));
  }
  void set(int k, pair<long long, int> x) {
    k += segn2 - 1;
    data[k] = x;
    while (k > 0) {
      k = (k - 1) / 2;
      data[k] = merge(data[k * 2 + 1], data[k * 2 + 2]);
    }
  }
};
struct UnionFind {
  vector<int> data;
  UnionFind(int s) : data(s, -1) {}
  int root(int x) {
    if (data[x] < 0) return x;
    return data[x] = root(data[x]);
  }
  bool set(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    data[x] += data[y];
    data[y] = x;
    return true;
  }
  bool check(int x, int y) { return root(x) == root(y); }
  int size(int x) { return -data[root(x)]; }
};
int main() {
  long long n, d, a[200010];
  scanf("%lld%lld\n", &n, &d);
  vector<pair<long long, int> > L, R;
  for (int i = 0; i < n; i++) {
    scanf("%lld", a + i);
    L.push_back({i * d + a[i], i});
    R.push_back({-i * d + a[i], i});
  }
  sort(L.begin(), L.end());
  sort(R.begin(), R.end());
  long long ans = 0;
  vector<pair<long long, pair<int, int> > > vec;
  int prevL = 0;
  for (int i = 0; i < n; i++) {
    int lp = L[i].second;
    for (int j = prevL; j < lp; j++) {
      vec.push_back({abs(lp - j) * d + a[lp] + a[j], {lp, j}});
      prevL = j + 1;
    }
  }
  int prevR = n - 1;
  for (int i = 0; i < n; i++) {
    int rp = R[i].second;
    for (int j = prevR; j > rp; j--) {
      vec.push_back({abs(rp - j) * d + a[rp] + a[j], {rp, j}});
      prevR = j - 1;
    }
  }
  sort(vec.begin(), vec.end());
  UnionFind uf(n);
  for (int i = 0; i < vec.size(); i++) {
    if (uf.set(vec[i].second.first, vec[i].second.second)) ans += vec[i].first;
    ;
    ;
  }
  cout << ans << endl;
  return 0;
}
