#include <bits/stdc++.h>
using namespace std;
int par[200002];
int rk[200002];
void init(int n) {
  for (int i = 0; i < n; i++) {
    par[i] = i;
  }
}
int find(int x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}
void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) return;
  if (rk[x] < rk[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (rk[x] == rk[y]) rk[x]++;
  }
}
bool same(int x, int y) { return find(x) == find(y); }
int n;
long long int d;
long long int a[200001];
vector<pair<long long int, pair<int, int> > > e;
void solve(int l, int r) {
  if (l == r) return;
  int m = (l + r) / 2;
  vector<int> indl, indr;
  for (int i = l; i <= m; i++) indl.push_back(i);
  for (int i = m + 1; i <= r; i++) indr.push_back(i);
  sort(indl.begin(), indl.end(), [&](int i, int j) {
    return a[i] - (long long int)i * d < a[j] - (long long int)j * d;
  });
  sort(indr.begin(), indr.end(), [&](int i, int j) {
    return a[i] + (long long int)i * d < a[j] + (long long int)j * d;
  });
  int i1 = 0, i2 = 0;
  int n0 = r - l + 1;
  for (int i = 0; i < n0 - 1; i++) {
    int x = indl[i1], y = indr[i2];
    e.push_back(pair<long long int, pair<int, int> >(
        a[x] + a[y] + (long long int)(y - x) * d, pair<int, int>(x, y)));
    if (i1 == indl.size() - 1)
      i2++;
    else if (i2 == indr.size() - 1)
      i1++;
    else {
      int x1 = indl[i1 + 1], y1 = indr[i2 + 1];
      if (a[x1] + a[y] + (long long int)(y - x1) * d <
          a[x] + a[y1] + (long long int)(y1 - x) * d)
        i1++;
      else
        i2++;
    }
  }
  solve(l, m);
  solve(m + 1, r);
}
int main() {
  cin >> n >> d;
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
  }
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  solve(0, n - 1);
  long long int ans = 0;
  sort(e.begin(), e.end());
  init(n);
  for (int i = 0; i < e.size(); i++) {
    int x = e[i].second.first, y = e[i].second.second;
    if (!same(x, y)) {
      unite(x, y);
      ans += e[i].first;
    }
  }
  cout << ans << endl;
  return 0;
}
