#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2e5;
const pair<long long int, int> INF = {1e18, -1};
template <typename T>
class RMQ {
 public:
  int n;
  vector<T> dat;
  void init(int _n) {
    n = 1;
    while (n < _n) {
      n <<= 1;
    }
    dat.reserve(2 * n - 1);
    fill(dat.begin(), dat.end(), INF);
  }
  void update(int k, T a) {
    k += n - 1;
    dat[k] = a;
    while (k > 0) {
      k = (k - 1) / 2;
      dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }
  T query(int a, int b) { return query(a, b, 0, 0, n); }

 private:
  T query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) {
      return INF;
    }
    if (a <= l && r <= b) {
      return dat[k];
    }
    return min(query(a, b, k * 2 + 1, l, (l + r) / 2),
               query(a, b, k * 2 + 2, (l + r) / 2, r));
  }
};
class UnionFind {
 public:
  vector<int> data;
  UnionFind(int size) : data(size, -1) {}
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) {
      return false;
    }
    if (data[y] < data[x]) {
      swap(x, y);
    }
    data[x] += data[y];
    data[y] = x;
    return true;
  }
  bool same(int x, int y) { return root(x) == root(y); }
  int root(int x) { return data[x] < 0 ? x : (data[x] = root(data[x])); }
  int size(int x) { return -data[root(x)]; }
};
int N;
long long int D;
long long int A[MAX_N];
RMQ<pair<long long int, int>> tl, tr;
long long int solve() {
  tl.init(N);
  tr.init(N);
  for (int i = 0; i < N; i++) {
    tl.update(i, {A[i] - i * D, i});
    tr.update(i, {A[i] + i * D, i});
  }
  priority_queue<pair<long long int, pair<int, int>>,
                 vector<pair<long long int, pair<int, int>>>,
                 greater<pair<long long int, pair<int, int>>>>
      q;
  for (int i = 0; i < N; i++) {
    if (i > 0) {
      pair<long long int, int> ci = tl.query(0, i);
      pair<long long int, pair<int, int>> e = {ci.first + A[i] + i * D,
                                               {ci.second, i}};
      q.push(e);
    }
    if (i < N - 1) {
      pair<long long int, int> ci = tr.query(i, N);
      pair<long long int, pair<int, int>> e = {ci.first + A[i] - i * D,
                                               {ci.second, i}};
      q.push(e);
    }
  }
  long long int ans = 0;
  UnionFind uf(N);
  while (!q.empty()) {
    pair<long long int, pair<int, int>> e = q.top();
    q.pop();
    int u = e.second.first, v = e.second.second;
    if (!uf.same(u, v)) {
      ans += e.first;
      uf.unite(u, v);
    }
  }
  return ans;
}
int main() {
  cin >> N >> D;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  cout << solve() << endl;
  return 0;
}
