#include <bits/stdc++.h>
using namespace std;
const int max_n = 300011, max_m = 500011, inf = 1000111222;
const long long inff = 1000111222333444;
struct dsu {
  int p[max_n], sz[max_n];
  dsu() {
    for (int i = 0; i < max_n; ++i) {
      p[i] = i;
      sz[i] = 1;
    }
  }
  int find_set(int x) {
    if (p[x] == x) return x;
    return p[x] = find_set(p[x]);
  }
  void union_set(int x, int y) {
    x = find_set(x);
    y = find_set(y);
    if (x != y) {
      if (sz[x] < sz[y]) swap(x, y);
      p[y] = x;
      sz[x] += sz[y];
    }
  }
};
int n, a[max_n], d;
vector<pair<long long, pair<int, int> > > edges;
dsu dd;
long long dist(int i, int q) { return 1LL * abs(i - q) * d + a[i] + a[q]; }
void dev(int l, int r) {
  if (l + 1 == r) {
    return;
  }
  int mid = (l + r) / 2;
  pair<long long, int> cv1, cv2;
  cv1 = cv2 = {inff, 0};
  for (int i = l; i < mid; ++i) {
    cv1 = min(cv1, {a[i] - 1LL * d * i, i});
  }
  for (int i = mid; i < r; ++i) {
    cv2 = min(cv1, {a[i] + 1LL * d * i, i});
  }
  for (int i = l; i < mid; ++i)
    edges.push_back({dist(i, cv2.second), {i, cv2.second}});
  for (int i = mid; i < r; ++i)
    edges.push_back({dist(i, cv1.second), {i, cv1.second}});
  dev(l, mid);
  dev(mid, r);
}
int main() {
  cin >> n >> d;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  dev(0, n);
  sort(edges.begin(), edges.end());
  long long ans = 0;
  for (int i = 0; i < edges.size(); ++i) {
    if (dd.find_set(edges[i].second.first) !=
        dd.find_set(edges[i].second.second)) {
      dd.union_set(edges[i].second.first, edges[i].second.second);
      ans += edges[i].first;
    }
  }
  cout << ans << endl;
  return 0;
}
