#include <bits/stdc++.h>
std::mt19937 rng(
    (int)std::chrono::steady_clock::now().time_since_epoch().count());
const int ms = 200200;
int par[ms];
std::pair<long long, int> best[ms];
int getPar(int x) { return x == par[x] ? x : par[x] = getPar(par[x]); }
bool makeUnion(int a, int b) {
  a = getPar(a), b = getPar(b);
  if (a == b) return false;
  par[a] = b;
  return true;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  int n;
  long long d;
  std::cin >> n >> d;
  std::vector<int> a(n);
  for (int i = 0; i < n; i++) {
    par[i] = i;
    a[i] = rng() % (int)(1e9) + 1;
    std::cin >> a[i];
  }
  int got = 0;
  long long ans = 0;
  const long long INF = 5e9;
  while (got < n - 1) {
    std::vector<std::pair<long long, int>> wtf;
    for (int i = 0; i < n; i++) {
      best[i] = std::pair<long long, int>(INF, -1);
    }
    for (int i = 0; i < n; i++) {
      int j = 0;
      while (j < (int)wtf.size() && wtf[j].second == getPar(i)) j++;
      if (j < (int)wtf.size()) {
        auto p = wtf[j];
        p.first += a[i] + i * d;
        best[getPar(i)] = std::min(best[getPar(i)], p);
      }
      while (j < (int)wtf.size() && wtf[j].second != getPar(i)) j++;
      if (j == (int)wtf.size()) {
        wtf.emplace_back(-i * d + a[i], getPar(i));
      } else {
        wtf[j] = std::min(wtf[j],
                          std::pair<long long, int>(-i * d + a[i], getPar(i)));
      }
      std::sort(wtf.begin(), wtf.end());
      if (wtf.size() > 2) {
        wtf.pop_back();
      }
    }
    wtf.clear();
    for (int i = n - 1; i >= 0; i--) {
      int j = 0;
      while (j < (int)wtf.size() && wtf[j].second == getPar(i)) j++;
      if (j < (int)wtf.size()) {
        auto p = wtf[j];
        p.first += a[i] - i * d;
        best[getPar(i)] = std::min(best[getPar(i)], p);
      }
      while (j < (int)wtf.size() && wtf[j].second != getPar(i)) j++;
      if (j == (int)wtf.size()) {
        wtf.emplace_back(i * d + a[i], getPar(i));
      } else {
        wtf[j] = std::min(wtf[j],
                          std::pair<long long, int>(i * d + a[i], getPar(i)));
      }
      std::sort(wtf.begin(), wtf.end());
      if (wtf.size() > 2) {
        wtf.pop_back();
      }
    }
    for (int i = 0; i < n; i++) {
      if (getPar(i) == i) {
        if (makeUnion(i, best[i].second)) {
          ans += best[i].first;
          got++;
        }
      }
    }
  }
  std::cout << ans << '\n';
}
