#include <bits/stdc++.h>
using namespace std;
long long N, D, A[1 << 18];
bool used[1 << 18];
class UnionFind {
 public:
  vector<int> par;
  void init(int sz) { par.resize(sz, -1); }
  int root(int pos) {
    if (par[pos] == -1) return pos;
    par[pos] = root(par[pos]);
    return par[pos];
  }
  void unite(int u, int v) {
    u = root(u);
    v = root(v);
    if (u == v) return;
    par[u] = v;
  }
  bool same(int u, int v) {
    if (root(u) == root(v)) return true;
    return false;
  }
};
long long getdist(int u, int v) { return A[u] + A[v] + 1LL * abs(v - u) * D; }
int main() {
  cin >> N >> D;
  for (int i = 1; i <= N; i++) cin >> A[i];
  vector<pair<long long, int>> E;
  for (int i = 1; i <= N; i++) E.push_back(make_pair(A[i], i));
  sort(E.begin(), E.end());
  vector<tuple<long long, int, int>> V;
  for (int i = 0; i < E.size(); i++) {
    int pos = E[i].second;
    if (used[pos] == true) continue;
    for (int j = pos - 1; j >= 1; j--) {
      V.push_back(make_tuple(getdist(pos, j), pos, j));
      long long cost1 = A[pos] + 1LL * pos * D;
      long long cost2 = A[j] + 1LL * j * D;
      if (cost1 >= cost2) break;
      used[j + 1] = true;
    }
    for (int j = pos + 1; j <= N; j++) {
      V.push_back(make_tuple(getdist(pos, j), pos, j));
      long long cost1 = A[pos] - 1LL * pos * D;
      long long cost2 = A[j] - 1LL * j * D;
      if (cost1 >= cost2) break;
      used[j - 1] = true;
    }
  }
  sort(V.begin(), V.end());
  UnionFind UF;
  long long ans = 0;
  UF.init(N + 2);
  for (int i = 0; i < V.size(); i++) {
    long long cost = get<0>(V[i]);
    int v1 = get<1>(V[i]), v2 = get<2>(V[i]);
    if (UF.same(v1, v2) == false) {
      UF.unite(v1, v2);
      ans += cost;
    }
  }
  cout << ans << endl;
  return 0;
}
