#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9;
const long long linf = 1e18;
const long long mod = 1e9 + 7;
const long long NMAX = 200000;
long long par[NMAX], rnk[NMAX];
long long n, d, a[NMAX];
void init(long long n) {
  for (long long i = 0; i < n; i++) {
    par[i] = i;
    rnk[i] = 0;
  }
}
long long find(long long x) {
  if (par[x] == x)
    return x;
  else
    return par[x] = find(par[x]);
}
void unite(long long x, long long y) {
  x = find(x);
  y = find(y);
  if (x == y) return;
  if (rnk[x] < rnk[y])
    par[x] = y;
  else {
    par[y] = x;
    if (rnk[x] == rnk[y]) rnk[x]++;
  }
}
bool same(long long x, long long y) { return find(x) == find(y); }
long long dist(long long x, long long y) {
  return abs(x - y) * d + a[x] + a[y];
}
signed main() {
  cin >> n >> d;
  for (long long i = 0; i < (long long)(n); i++) cin >> a[i];
  vector<pair<long long, pair<long long, long long> > > es;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < n; j++) {
      es.push_back(make_pair(dist(i, j), make_pair(i, j)));
    }
  }
  init(n);
  sort(es.begin(), es.end());
  long long ans = 0;
  for (long long i = 0; i < es.size(); i++) {
    pair<long long, pair<long long, long long> > e = es[i];
    if (!same(e.second.first, e.second.second)) {
      ans += e.first;
      unite(e.second.first, e.second.second);
    }
  }
  cout << ans << endl;
  return 0;
}
