#include <bits/stdc++.h>
using namespace std;
long long int n;
long long int d;
vector<long long int> v;
int lef[200002];
int rig[200002];
long long int eval(int a, int b) {
  if (a == -1 || b == -1) return LLONG_MAX;
  return abs(a - b) * d + v[a] + v[b];
}
long long int calc(int star) {
  long long int ans = 0;
  int nex1 = star;
  int nex2 = star;
  for (int i = 0; i < n; i++) {
    if (star == i) {
      if (i == n - 1) break;
      if (lef[n - 1] <= i) {
        ans += eval(i, n - 1);
        star = n - 1;
        nex1 = i;
        nex2 = n - 1;
      } else {
        auto cost = eval(i, rig[i]);
        ans += cost;
        nex1 = i;
        nex2 = rig[i];
        star = nex2;
        continue;
      }
    } else {
      ans += min(eval(i, nex1), eval(i, nex2));
    }
  }
  return ans;
}
int main() {
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    v.push_back(a);
  }
  for (int i = 0; i < n; i++) {
    lef[i] = rig[i] = -1;
  }
  pair<long long int, int> p = make_pair(LLONG_MAX / 2LL, -1);
  for (int i = 0; i < n; i++) {
    p.first += d;
    lef[i] = p.second;
    pair<long long int, int> z = make_pair(v[i], i);
    p = min(p, z);
  }
  p = make_pair(LLONG_MAX / 2LL, -1);
  for (int i = n - 1; i >= 0; i--) {
    p.first += d;
    rig[i] = p.second;
    pair<long long int, int> z = make_pair(v[i], i);
    p = min(p, z);
  }
  auto ans = calc(0);
  printf("%lld\n", ans);
  return 0;
}
