#include <bits/stdc++.h>
using namespace std;
int n, l[200005], r[200005], p[200005], rk[200005];
long long d, a[200005], ans;
struct edg {
  int first, second;
  long long v;
};
int Par(int nod) {
  if (p[nod] == p[p[nod]]) return p[nod];
  p[nod] = Par(p[nod]);
  return p[nod];
}
void Unite(int first, int second) {
  first = Par(first);
  second = Par(second);
  if (first == second) return;
  if (rk[first] < rk[second]) swap(first, second);
  if (rk[first] == rk[second]) rk[first]++;
  p[second] = first;
}
vector<edg> g;
bool comp(edg a, edg b) { return a.v < b.v; }
int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  cin >> n >> d;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    p[i] = i;
  }
  long long mn = 1000000000000000005, id = n + 1;
  for (int i = n; i >= 1; i--) {
    r[i] = id;
    if (i != n) g.push_back({i, r[i], d * (r[i] - i) + a[i] + a[r[i]]});
    if (a[i] + i * d < mn) mn = a[i] + i * d, id = i;
  }
  mn = 1000000000000000005, id = 0;
  for (int i = 1; i <= n; i++) {
    l[i] = id;
    if (i != 1) g.push_back({l[i], i, d * (i - l[i]) + a[i] + a[l[i]]});
    if (a[i] - i * d < mn) mn = a[i] - i * d, id = i;
  }
  sort(g.begin(), g.end(), comp);
  for (edg i : g) {
    if (Par(i.first) == Par(i.second)) continue;
    Unite(i.first, i.second);
    ans += i.v;
  }
  cout << ans;
}
