#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
struct SegmentTree {
 private:
  long long n;
  vector<pair<long long, long long>> node;

 public:
  SegmentTree(vector<pair<long long, long long>> v) {
    long long sz = (long long)v.size();
    n = 1;
    while (n < sz) n *= 2;
    node.resize(2 * n - 1);
    for (long long i = (0); i < (sz); i++) node[i + n - 1] = v[i];
    for (long long i = (n - 1 - 1); i >= 0; i--)
      node[i] = min(node[i * 2 + 1], node[i * 2 + 2]);
  }
  void update(long long k, pair<long long, long long> a) {
    k += n - 1;
    node[k] = a;
    while (k > 0) {
      k = (k - 1) / 2;
      node[k] = min(node[k * 2 + 1], node[k * 2 + 2]);
    }
  }
  pair<long long, long long> query(long long a, long long b, long long k = 0,
                                   long long l = 0, long long r = -1) {
    if (r < 0) r = n;
    if (r <= a || b <= l) return pair<long long, long long>((1LL << 60), -1);
    if (a <= l && r <= b)
      return node[k];
    else {
      pair<long long, long long> vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
      pair<long long, long long> vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
      return min(vl, vr);
    }
  }
};
struct UnionFind {
 private:
  vector<long long> child, tree, sum;

 public:
  UnionFind(long long v) {
    tree.resize(v);
    sum.resize(v);
    for (long long i = (0); i < (v); i++) tree[i] = i, sum[i] = 1;
  }
  long long root(long long i) {
    if (i == tree[i]) {
      for (long long j = (0); j < (child.size()); j++) tree[child[j]] = i;
      child.clear();
      return i;
    } else {
      child.push_back(i);
      return i = root(tree[i]);
    }
  }
  long long size(long long i) { return sum[root(i)]; }
  long long unit(long long x, long long y) {
    x = root(x);
    y = root(y);
    sum[min(x, y)] += sum[max(x, y)];
    tree[max(x, y)] = min(x, y);
  }
  bool isUnit(long long x, long long y) { return root(x) == root(y); }
};
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, d;
  cin >> n >> d;
  vector<long long> a(n);
  for (long long i = (0); i < (n); i++) cin >> a[i];
  vector<pair<long long, long long>> tmp1(n), tmp2(n);
  for (long long i = (0); i < (n); i++)
    tmp1[i] = pair<long long, long long>(a[i] + d * i, i);
  for (long long i = (0); i < (n); i++)
    tmp2[n - 1 - i] =
        pair<long long, long long>(a[n - 1 - i] + d * i, n - 1 - i);
  SegmentTree segL(tmp1), segR(tmp2);
  vector<pair<long long, pair<long long, long long>>> edge;
  for (long long i = (0); i < (n); i++) {
    if (i != 0) {
      pair<long long, long long> tmp = segR.query(0, i);
      edge.push_back(make_pair(a[i] + tmp.first - (n - 1 - i) * d,
                               pair<long long, long long>(i, tmp.second)));
    }
    if (i != n - 1) {
      pair<long long, long long> tmp = segL.query(i + 1, n);
      edge.push_back(make_pair(a[i] + tmp.first - i * d,
                               pair<long long, long long>(i, tmp.second)));
    }
  }
  sort(edge.begin(), edge.end());
  UnionFind uf(n);
  long long ans = 0;
  for (long long i = (0); i < (edge.size()); i++) {
    long long x = edge[i].second.first, y = edge[i].second.second;
    if (uf.isUnit(x, y)) continue;
    uf.unit(x, y);
    ans += edge[i].first;
  }
  cout << ans << endl;
  return 0;
}
