#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long n, d, ans = 0;
long long a[200010], par[200010];
vector<pair<long long, pair<long long, long long> > > v;
long long FIND(long long pos) {
  if (par[pos] != pos) par[pos] = FIND(par[pos]);
  return par[pos];
}
void UNION(long long pos1, long long pos2) { par[FIND(pos1)] = FIND(pos2); }
void solve(long long lb, long long ub) {
  if (lb == ub) return;
  long long mid = (lb + ub) / 2, mn = 1e18, lbest, rbest;
  for (long long i = 0; i <= mid; i++) {
    if (a[i] - d * i < mn) {
      mn = a[i] - d * i;
      lbest = i;
    }
  }
  mn = 1e18;
  for (long long i = mid + 1; i <= ub; i++) {
    if (a[i] + d * i < mn) {
      mn = a[i] + d * i;
      rbest = i;
    }
  }
  for (long long i = 0; i <= mid; i++) {
    long long val1 = a[i] - d * i, val2 = a[rbest] + d * rbest;
    v.push_back({val1 + val2, {i, rbest}});
  }
  for (long long i = mid + 1; i <= ub; i++) {
    long long val1 = a[i] + d * i, val2 = a[lbest] - d * lbest;
    v.push_back({val1 + val2, {lbest, i}});
  }
  solve(lb, mid);
  solve(mid + 1, ub);
}
int main() {
  for (int i = 0; i < 200005; i++) par[i] = i;
  cin >> n >> d;
  for (int i = 0; i < n; i++) scanf("%I64d", &a[i]);
  solve(0, n - 1);
  sort(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++) {
    if (FIND(v[i].second.first) == FIND(v[i].second.second)) continue;
    UNION(v[i].second.first, v[i].second.second);
    ans += v[i].first;
  }
  cout << ans << endl;
  return 0;
}
