#include <bits/stdc++.h>
using namespace std;
struct SimpleSegTree {
  int segn2;
  pair<long long, int> initVal;
  vector<pair<long long, int> > data;
  function<pair<long long, int>(pair<long long, int>, pair<long long, int>)>
      merge;
  SimpleSegTree(
      int n, pair<long long, int> initVal,
      function<pair<long long, int>(pair<long long, int>, pair<long long, int>)>
          merge)
      : initVal(initVal), merge(merge) {
    for (segn2 = 1; segn2 < n; segn2 *= 2)
      ;
    data.assign(segn2 * 2, initVal);
  }
  SimpleSegTree(int n)
      : SimpleSegTree(n, {2000000000000000000LL, -1},
                      [](pair<long long, int> a, pair<long long, int> b) {
                        return min(a, b);
                      }) {}
  SimpleSegTree(int n, pair<long long, int> initVal)
      : SimpleSegTree(n, initVal,
                      [](pair<long long, int> a, pair<long long, int> b) {
                        return min(a, b);
                      }) {}
  pair<long long, int> query(int a, int b, int l = 0, int r = -1, int k = 0) {
    if (r == -1) r = segn2;
    if (a <= l && r <= b) return data[k];
    if (r <= a || b <= l) return initVal;
    return merge(query(a, b, l, (l + r) / 2, k * 2 + 1),
                 query(a, b, (l + r) / 2, r, k * 2 + 2));
  }
  void set(int k, pair<long long, int> x) {
    k += segn2 - 1;
    data[k] = x;
    while (k > 0) {
      k = (k - 1) / 2;
      data[k] = merge(data[k * 2 + 1], data[k * 2 + 2]);
    }
  }
};
int main() {
  long long n, d, a[200010];
  scanf("%lld%lld\n", &n, &d);
  SimpleSegTree segL(n), segR(n);
  for (int i = 0; i < n; i++) {
    scanf("%lld", a + i);
    segL.set(i, {-i * d + a[i], i});
    segR.set(i, {i * d + a[i], i});
  }
  long long ans = 0;
  int m = 0;
  bool visited[200010] = {};
  priority_queue<pair<long long, pair<int, int> > > pq;
  auto next = [&](int pos) {
    auto x = segL.query(0, pos);
    auto y = segR.query(pos + 1, n);
    if (x.first == 2000000000000000000LL && y.first == 2000000000000000000LL)
      return make_pair(2000000000000000000LL, -1);
    x.first += pos * d + a[pos];
    y.first += -pos * d + a[pos];
    if (x.first < y.first)
      return x;
    else
      return y;
  };
  pq.push({0, {0, -1}});
  while (pq.size() && m < n) {
    auto p = pq.top();
    pq.pop();
    long long cost = -p.first;
    int now = p.second.first;
    int prev = p.second.second;
    if (visited[now]) {
      if (prev != -1) {
        auto res = next(prev);
        if (res.first != 2000000000000000000LL)
          pq.push({-res.first, {res.second, prev}});
      }
      continue;
    }
    visited[now] = true;
    m++;
    segL.set(now, {2000000000000000000LL, now});
    segR.set(now, {2000000000000000000LL, now});
    if (prev != -1) {
      auto res = next(prev);
      if (res.first != 2000000000000000000LL)
        pq.push({-res.first, {res.second, prev}});
    }
    ans += cost;
    auto res = next(now);
    if (res.first != 2000000000000000000LL)
      pq.push({-res.first, {res.second, now}});
  }
  cout << ans << endl;
  return 0;
}
