#include <bits/stdc++.h>
using namespace std;
long long gcd_(long long a, long long b) {
  if (a % b == 0) return b;
  return gcd_(b, a % b);
}
long long lcm_(long long a, long long b) {
  long long c = gcd_(a, b);
  return ((a / c) * b);
}
const long long INF = long long(1e16) + long long(7);
const long long MOD = 1000000007LL;
long long keta(long long a) {
  long long r = 0;
  while (a) {
    a /= 10;
    r++;
  }
  return r;
}
class UnionFind {
  vector<int> par, siz;
  void init(int n) {
    component = n;
    par.resize(n);
    for (int i = 0; i < n; ++i) par[i] = i;
    siz.resize(n, 1);
    msiz = 1;
  }

 public:
  int msiz, component;
  UnionFind(int n_) { init(n_); }
  int root(int x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;
    siz[y] += siz[x];
    siz[x] = 0;
    par[x] = y;
    msiz = max(msiz, siz[y]);
    component--;
  }
  int size(int x) { return siz[root(x)]; }
  bool same(int x, int y) { return root(x) == root(y); }
};
int main() {
  long long N, D;
  cin >> N >> D;
  vector<long long> A(N);
  for (long long i = long long(0); i < long long(N); ++i) cin >> A[i];
  if (N == 1) {
    cout << 0 << endl;
    return 0;
  } else if (N == 2) {
    cout << A[0] + A[1] + D << endl;
    return 0;
  }
  vector<long long> u, v, c;
  vector<int> index(N);
  for (long long i = long long(0); i < long long(N); ++i) index[i] = i;
  stack<vector<int>> Q;
  Q.push(index);
  while (Q.size()) {
    vector<int> s1, s0;
    int k1 = Q.top().size() / 2;
    int k0 = Q.top().size() - k1;
    for (long long i = long long(0); i < long long(k0); ++i)
      s0.push_back(Q.top()[i]);
    for (long long i = long long(k0); i < long long(k1 + k0); ++i)
      s1.push_back(Q.top()[i]);
    Q.pop();
    if (s1.size() == 0) continue;
    long long min_cost_0 = INF, i0;
    long long min_cost_1 = INF, i1;
    for (long long i = long long(0); i < long long(s0.size()); ++i) {
      if (min_cost_0 > A[s0[i]] - D * s0[i]) {
        min_cost_0 = A[s0[i]] - D * s0[i];
        i0 = s0[i];
      }
    }
    for (long long i = long long(0); i < long long(s1.size()); ++i) {
      if (min_cost_1 > A[s1[i]] + D * s1[i]) {
        min_cost_1 = A[s1[i]] + D * s1[i];
        i1 = s1[i];
      }
    }
    u.push_back(i0);
    v.push_back(i1);
    c.push_back(A[i0] + A[i1] + D * (i1 - i0));
    if (s0.size() > 2) {
      Q.push(s0);
    } else if (s0.size() == 2) {
      u.push_back(s0[0]);
      v.push_back(s0[1]);
      c.push_back(abs(s0[0] - s0[1]) * D + A[s0[0]] + A[s0[1]]);
    }
    if (s1.size() > 2) {
      Q.push(s1);
    } else if (s1.size() == 2) {
      u.push_back(s1[0]);
      v.push_back(s1[1]);
      c.push_back(abs(s1[0] - s1[1]) * D + A[s1[0]] + A[s1[1]]);
    }
  }
  vector<pair<long long, pair<int, int>>> X;
  for (long long i = long long(0); i < long long(u.size()); ++i) {
    X.push_back({c[i], {u[i], v[i]}});
  }
  (sort(X.begin(), X.end()));
  UnionFind uf(N);
  long long ans = 0;
  for (long long i = long long(0); i < long long(X.size()); ++i) {
    int a = X[i].second.first;
    int b = X[i].second.second;
    long long add_ = X[i].first;
    if (not uf.same(a, b)) {
      uf.unite(a, b);
      ans += add_;
    }
  }
  cout << ans << endl;
}
