#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, d;
  long long a[200000];
  long long dp[200000] = {};
  bool used[200000] = {};
  long long mx = 0, mp = 0, mn = (1e+16);
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] > mx) {
      mx = a[i];
      mp = i;
    }
    dp[i] = (1e+16);
  }
  long long ans = 0;
  dp[mp] = 0;
  int cnt = 0;
  long long p = mp;
  while (true) {
    mn = (1e+16);
    long long p = mp;
    ans += dp[p];
    used[p] = true;
    for (int i = 0; i < n; i++) {
      if (used[i]) continue;
      dp[i] = min(abs(p - i) * d + a[p] + a[i], dp[i]);
      if (dp[i] < mn) {
        mn = dp[i];
        mp = i;
      }
    }
    if (++cnt == n) break;
  }
  cout << ans << endl;
}
