#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N = 2e5 + 7;
int par[N];
int get(int v) {
  if (v == par[v]) {
    return v;
  } else {
    return par[v] = get(par[v]);
  }
}
void uni(int u, int v) { par[get(u)] = get(v); }
const long long inf = 1e18 + 7;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, d;
  cin >> n >> d;
  vector<int> a(n);
  vector<int> ind(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    ind[i] = i;
  }
  for (int i = 0; i < n; i++) {
    par[i] = i;
  }
  int comp = n;
  long long ans = 0;
  while (comp > 1) {
    vector<long long> best(n, inf);
    vector<int> him(n, -1);
    auto rlx = [&]() {
      vector<pair<long long, int> > arr;
      for (int i = 0; i < n; i++) {
        int real_ind = ind[i];
        long long value = -i * (long long)d + a[real_ind];
        int who = get(real_ind);
        arr.push_back({value, who});
        sort(arr.begin(), arr.end());
        vector<pair<long long, int> > now;
        for (int i = 0; i < (int)arr.size(); i++) {
          if (now.empty() || now.back().second != arr[i].second) {
            now.push_back(arr[i]);
          }
        }
        while (now.size() > 2) now.pop_back();
        for (auto c : now) {
          if (c.second != who) {
            long long relax_cur = i * (long long)d + a[real_ind] + c.first;
            int relax_who = c.second;
            if (relax_cur < best[who]) {
              best[who] = relax_cur;
              him[who] = relax_who;
            }
          }
        }
      }
    };
    rlx();
    reverse(ind.begin(), ind.end());
    rlx();
    for (int i = 0; i < n; i++) {
      if (get(i) == i) {
        if (get(him[i]) != i) {
          uni(him[i], i);
          ans += best[i];
          comp--;
        }
      }
    }
  }
  cout << ans << '\n';
}
