#include <bits/stdc++.h>
using namespace std;
class segtree {
 public:
  static const int N = 1 << 19;
  pair<long long, int> dp[1 << 20];
  segtree() {
    for (int i = N - 1; i < N * 2; i++) {
      dp[i] = pair<long long, int>((1LL << 50), i - (N - 1));
    }
    for (int i = N - 2; i >= 0; i--) {
      dp[i] = min(dp[i * 2 + 1], dp[i * 2 + 2]);
    }
  }
  void update(int k, int v) {
    k += N - 1;
    dp[k].first = v;
    while (k > 0) {
      k = (k - 1) / 2;
      dp[k] = min(dp[k * 2 + 1], dp[k * 2 + 2]);
    }
  }
  pair<long long, int> query(int a, int b, int k = 0, int l = 0, int r = N) {
    if (b <= l || r <= a) return pair<long long, int>((1LL << 50), -1);
    if (a <= l && r <= b) return dp[k];
    int mid = (l + r) / 2;
    pair<long long, int> vl = query(a, b, k * 2 + 1, l, mid);
    pair<long long, int> vr = query(a, b, k * 2 + 2, mid, r);
    return min(vl, vr);
  }
};
segtree seg, seg2;
int n;
long long d;
long long a[200005];
long long ans = 0;
void solve(int l, int r, long long lc, long long rc) {
  if (l >= r) return;
  pair<long long, int> p1 = seg.query(l, r);
  pair<long long, int> p2 = seg2.query(l, r);
  p1.first -= d * (l - 1);
  p2.first -= d * (n - r - 1);
  if (l == 0) p1.first = (1LL << 50);
  if (r == n) p2.first = (1LL << 50);
  p1.first += lc;
  p2.first += rc;
  if (p1.first < p2.first) {
    ans += p1.first;
    solve(l, p1.second, lc,
          min(a[p1.second], (long long)rc + d * ((long long)r - p1.second)));
    solve(
        p1.second + 1, r,
        min(a[p1.second], (long long)lc + d * ((long long)p1.second + 1LL - l)),
        rc);
  } else {
    ans += p2.first;
    solve(l, p2.second, lc,
          min(a[p2.second], (long long)rc + d * ((long long)r - p2.second)));
    solve(
        p2.second + 1, r,
        min(a[p2.second], (long long)lc + d * ((long long)p2.second + 1LL - l)),
        rc);
  }
}
int main(void) {
  scanf("%d%lld", &n, &d);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }
  if (n == 1) {
    printf("0\n");
    return 0;
  }
  for (int i = 0; i < n; i++) {
    seg.update(i, a[i] + (long long)d * i);
    seg2.update(i, a[i] + (long long)d * (n - i - 1));
  }
  int best = 0;
  for (int i = 0; i < n - 1; i++) {
    if (a[i] + a[i + 1] < a[best] + a[best + 1]) {
      best = i;
    }
  }
  ans += a[best] + a[best + 1] + d;
  solve(0, best, (1LL << 50), min(a[best], a[best + 1] + d));
  solve(best + 2, n, min(a[best + 1], a[best] + d), (1LL << 50));
  printf("%lld\n", ans);
  return 0;
}
