#include <bits/stdc++.h>
using namespace std;
using Int = long long;
struct UnionFind {
  vector<int> A;
  UnionFind(int n) : A(n, -1) {}
  int find(int x) {
    if (A[x] < 0) return x;
    return A[x] = find(A[x]);
  }
  void unite(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return;
    if (A[x] > A[y]) swap(x, y);
    A[x] += A[y];
    A[y] = x;
  }
};
int main() {
  Int N, D;
  cin >> N >> D;
  vector<Int> A(N);
  for (auto &a : A) cin >> a;
  vector<Int> L(N), R(N);
  L[0] = 0, R[N - 1] = N - 1;
  auto f = [&](int i) { return -D * i + A[i]; };
  auto g = [&](int i) { return -D * (N - 1 - i) + A[i]; };
  for (int i = 1; i < N; i++) {
    L[i] = f(i - 1) < f(L[i - 1]) ? i - 1 : L[i - 1];
  }
  for (int i = N - 2; i >= 0; i--) {
    R[i] = g(i + 1) < g(R[i + 1]) ? i + 1 : R[i + 1];
  }
  vector<tuple<Int, int, int>> edges;
  for (int i = 0; i < N; i++) {
    int j = L[i];
    edges.emplace_back(abs(i - j) * D + A[i] + A[j], i, j);
    j = R[i];
    edges.emplace_back(abs(i - j) * D + A[i] + A[j], i, j);
  }
  sort(begin(edges), end(edges));
  UnionFind uf(N);
  Int ans = 0;
  for (auto &tup : edges) {
    Int cost, i, j;
    tie(cost, i, j) = tup;
    if (uf.find(i) != uf.find(j)) {
      ans += cost;
      uf.unite(i, j);
    }
  }
  cout << ans << '\n';
  return 0;
}
