#include <bits/stdc++.h>
using namespace std;
bool vis[200005];
int main() {
  long long n, d;
  cin >> n >> d;
  int i;
  long long a[n + 1];
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  long long l[n + 1], r[n + 1];
  l[n] = 1e18;
  r[1] = 1e18;
  multiset<pair<long long, long long> > s;
  for (i = 1; i <= n; i++) {
    s.insert(make_pair(((i - 1) * d + a[i]), i));
  }
  for (i = 1; i <= n - 1; i++) {
    s.erase(s.find(make_pair(((i - 1) * d + a[i]), i)));
    auto it = s.begin();
    if (vis[i] == 1) {
      continue;
    }
    vis[it->second] = 1;
    l[i] = a[i] + it->first - d * (i - 1);
    l[it->second] = l[i];
  }
  for (i = 1; i <= n; i++) {
    s.insert(make_pair(((n - i) * d + a[i]), i));
  }
  memset(vis, 0, sizeof(vis));
  for (i = n; i >= 2; i--) {
    s.erase(s.find(make_pair(((n - i) * d + a[i]), i)));
    auto it = s.begin();
    if (vis[i] == 1) {
      continue;
    }
    vis[it->second] = 1;
    r[i] = a[i] + it->first - d * (n - i);
    r[it->second] = r[i];
  }
  vector<long long> vv;
  for (i = 1; i <= n; i++) {
    vv.push_back(min(l[i], r[i]));
  }
  long long ans = 0;
  sort(vv.begin(), vv.end());
  for (i = 0; i < vv.size() - 1; i++) {
    ans += vv[i];
  }
  cout << ans << endl;
}
