#include <bits/stdc++.h>
using namespace std;
const double pi = 3.14159265358979323846;
#pragma GCC optimize("-O2")
template <class T>
using min_heap = priority_queue<T, std::vector<T>, std::greater<T> >;
const int LM = 1e5;
long long n, d, a[LM + 2];
int sz[LM + 2], p[LM + 2];
vector<pair<long long, pair<int, int> > > edges;
int find(int x) {
  while (p[x] != x) x = p[x];
  return x;
}
void unite(int a, int b) {
  a = find(a);
  b = find(b);
  if (sz[a] < sz[b]) swap(a, b);
  p[b] = a;
  sz[a] += sz[b];
}
long long w(int i, int j) { return d * (abs(i - j)) + a[i] + a[j]; }
int main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  cin >> n >> d;
  for (int i = 1; i <= n; i++) cin >> a[i];
  long long m = 1e18;
  int is = -1;
  for (int i = 1; i <= n; i++) {
    if (i != 1) {
      edges.push_back(make_pair(w(i, is), make_pair(i, is)));
    }
    if (a[i] - d * i < m) {
      m = a[i] - d * i;
      is = i;
    }
  }
  m = 1e18, is = -1;
  for (int i = n; i >= 1; i--) {
    if (i != n) {
      edges.push_back(make_pair(w(i, is), make_pair(i, is)));
    }
    if (a[i] + d * i < m) {
      m = a[i] + d * i;
      is = i;
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) p[i] = i;
  for (int i = 1; i <= n; i++) sz[i] = 1;
  sort(edges.begin(), edges.end());
  for (auto u : edges) {
    if (find(u.second.first) == find(u.second.second))
      continue;
    else {
      unite(u.second.first, u.second.second);
      ans += u.first;
    }
  }
  cout << ans << endl;
}
