#include <bits/stdc++.h>
using namespace std;
const int inf = 1025352128;
int n, d;
int a[200005];
int f[200005];
int rk[200005];
vector<pair<long long, pair<int, int> > > vec;
int find(int x) {
  if (f[x] == x) {
    return x;
  } else {
    rk[x] = 1;
    return f[x] = find(f[x]);
  }
}
void merge(int x, int y) {
  x = find(x);
  y = find(y);
  if (rk[x] == rk[y]) {
    if (rand() & 1) {
      rk[x]++;
      f[y] = x;
    } else {
      rk[y]++;
      f[x] = y;
    }
    return;
  }
  if (rk[x] > rk[y]) {
    f[y] = x;
    return;
  }
  if (rk[y] > rk[x]) {
    f[x] = y;
    return;
  }
}
void init() {
  for (int i = 0; i < n; i++) {
    f[i] = i;
    rk[i] = 1;
  }
}
inline long long cost(int i, int j) { return a[i] + a[j] + (j - i) * d; }
void add(int l, int r) {
  if (r - l <= 1) return;
  int m = l + r >> 1;
  int minx = inf, tl, tr;
  for (int i = l; i < m; i++) {
    if (a[i] - i * d < minx) {
      minx = a[i] - i * d;
      tl = i;
    }
  }
  minx = inf;
  for (int i = m; i < r; i++) {
    if (a[i] + i * d < minx) {
      minx = a[i] + i * d;
      tr = i;
    }
  }
  for (int i = l; i < m; i++) {
    vec.push_back(make_pair(cost(i, tr), make_pair(i, tr)));
  }
  for (int i = m; i < r; i++) {
    vec.push_back(make_pair(cost(tl, i), make_pair(tl, i)));
  }
  add(l, m);
  add(m, r);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> d;
  init();
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  add(0, n);
  sort(vec.begin(), vec.end());
  long long res = 0;
  int s = 1;
  for (auto x : vec) {
    if (find(x.second.first) == find(x.second.second)) continue;
    merge(x.second.first, x.second.second);
    s++;
    res += x.first;
    if (s == n) break;
  }
  cout << res << endl;
  return 0;
}
