#include <bits/stdc++.h>
int main(void) {
  long long int n, d;
  static long long int a[200010];
  static long long int localmin[200010];
  static long long int road[200010][2];
  int i, j, k, l;
  int flag = 0;
  long long int ans = 0;
  int count = 0;
  long long int temp, temp1, temp2;
  int max, min;
  int len;
  int sum = 0;
  scanf("%lld %lld", &n, &d);
  for (i = (0); i < (n); i++) {
    scanf("%lld", &a[i]);
  }
  for (i = (0); i < (n); i++) {
    localmin[i] = -1;
  }
  temp = 0;
  for (i = (1); i < (n); i++) {
    if (a[temp] >= d * (i - temp) + a[i]) {
      temp = i;
    } else if (a[temp] + d * (i - temp) > a[i]) {
      localmin[count] = temp;
      count++;
      temp = i;
    }
  }
  localmin[count] = temp;
  count++;
  temp = 0;
  for (i = 0; i < count - 1; i++) {
    road[i][0] = localmin[i];
    road[i][1] = localmin[i + 1];
  }
  temp = count - 1;
  temp1 = -1;
  temp2 = localmin[0];
  count = 1;
  for (i = 0; i < n; i++) {
    if (temp1 == -1) {
      if (i < temp2) {
        road[temp][0] = i;
        road[temp][1] = temp2;
        temp++;
      } else if (i == temp2) {
        temp1 = temp2;
        temp2 = localmin[1];
      }
    } else if (temp2 != -1) {
      if (i < temp2) {
        if (a[temp1] + (i - temp1) * d < a[temp2] + (temp2 - i) * d) {
          road[temp][0] = temp1;
          road[temp][1] = i;
          temp++;
        } else {
          road[temp][0] = i;
          road[temp][1] = temp2;
          temp++;
        }
      } else if (i == temp2) {
        temp1 = temp2;
        temp2 = localmin[count + 1];
        count++;
      }
    } else {
      road[temp][0] = temp1;
      road[temp][1] = i;
      temp++;
    }
  }
  for (i = (0); i < (temp); i++) {
    ans = ans + a[road[i][0]] + a[road[i][1]] + (road[i][1] - road[i][0]) * d;
  }
  printf("%lld", ans);
  return 0;
}
