#include <bits/stdc++.h>
using namespace std;
int N, p, t;
long long D, A[200000], res;
vector<pair<long long, int>> v;
priority_queue<pair<long long, int>, vector<pair<long long, int>>,
               greater<pair<long long, int>>>
    q;
long long func(long long x, long long y) {
  return abs(x - y) * D + A[x] + A[y];
}
int main() {
  cin >> N >> D;
  p = N - 1;
  for (int i = 0; i != N; ++i) {
    cin >> A[i];
    v.push_back({A[i] - D * i, i});
  }
  sort(v.begin(), v.end());
  t = N - 1;
  for (int i = 0; i != N; ++i) {
    if (v[i].second < p) {
      for (t; t != v[i].second; --t) q.push(make_pair(A[t] + D * t, t));
      res += func(v[i].second, q.top().second);
      for (int j = p - 1; j != v[i].second; --j) {
        res += func(v[i].second, j);
      }
      p = v[i].second;
    }
  }
  cout << res << endl;
  return 0;
}
