#include <bits/stdc++.h>
using namespace std;
template <class T>
T inf() {
  return numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity()
                                         : (numeric_limits<T>::max() / 2);
}
struct S {
  long long val;
  int i;
  S(long long val, int i) : val(val), i(i) {}
};
struct T {
  long long val;
  int s, t;
  T() {}
  T(long long val, int s, int t) : val(val), s(s), t(t) {}
  bool operator<(const T &t) const { return val > t.val; }
};
S append(const S &l, const S &r) {
  if (l.val <= r.val) {
    return l;
  } else {
    return r;
  }
}
template <typename T>
struct SegmentTree {
  int n;
  vector<T> a;
  T unit;
  function<T(T, T)> append;
  SegmentTree() = default;
  SegmentTree(int a_n, T a_unit, function<T(T, T)> a_append)
      : unit(a_unit), append(a_append) {
    n = pow(2, ceil(log2(a_n)));
    a.resize(2 * n - 1, a_unit);
  }
  void point_update(int i, T z) {
    a[i + n - 1] = z;
    for (i = (i + n) / 2; i > 0; i /= 2) {
      a[i - 1] = append(a[2 * i - 1], a[2 * i]);
    }
  }
  T range_concat(int l, int r) { return range_concat(0, 0, n, l, r); }
  T range_concat(int i, int il, int ir, int l, int r) {
    if (l <= il and ir <= r) {
      return a[i];
    } else if (ir <= l or r <= il) {
      return unit;
    } else {
      return append(range_concat(2 * i + 1, il, (il + ir) / 2, l, r),
                    range_concat(2 * i + 2, (il + ir) / 2, ir, l, r));
    }
  }
  void build(int i, int il, int ir, const vector<T> &v) {
    if (ir - il == 1) {
      if (il < n)
        a[i] = v[il];
      else
        a[i] = unit;
    } else {
      int im = (il + ir) / 2;
      build(v, i * 2 + 1, il, im);
      build(v, i * 2 + 2, im, ir);
      a[i] = append(a[i * 2 + 1], a[i * 2 + 2]);
    }
  }
  void build(const vector<T> &v) { build(0, 0, n, v); }
  void write() {
    for (int i = 0; i < n; i++) {
      T t = range_concat(i, i + 1);
      if (t.val == inf<long long>())
        cerr << "*"
             << " ";
      else
        cerr << t.val << " ";
    }
    cerr << endl;
  }
};
long long N;
long long D;
vector<long long> A;
const S Inf = S(inf<long long>(), -1);
void solve() {
  vector<bool> selected(N, false);
  priority_queue<T> q;
  SegmentTree<S> left((int)N, Inf, append), right((int)N, Inf, append);
  for (int i = 0; i < N; i++) {
    left.point_update(i, S(A[i] - i * D, i));
    right.point_update(i, S(A[i] + i * D, i));
  }
  auto update_weight_queue = [&](int i) {
    auto sl = left.range_concat(0, i);
    long long lv =
        (sl.val < inf<long long>()) ? sl.val + A[i] + i * D : inf<long long>();
    auto sr = right.range_concat(i + 1, N);
    long long rv =
        (sr.val < inf<long long>()) ? sr.val + A[i] - i * D : inf<long long>();
    if (lv < rv) {
      q.push(T(lv, i, sl.i));
    } else {
      if (rv < inf<long long>()) q.push(T(rv, i, sr.i));
    }
  };
  long long ans = 0;
  q.push(T(0, -1, 0));
  for (; !q.empty();) {
    auto qt = q.top();
    int s = qt.s, t = qt.t;
    q.pop();
    if (selected[t]) {
      if (s >= 0) update_weight_queue(s);
      continue;
    }
    long long val = qt.val;
    selected[t] = true;
    ans += val;
    left.point_update(t, S(inf<long long>(), t));
    right.point_update(t, S(inf<long long>(), t));
    update_weight_queue(t);
    if (s >= 0) update_weight_queue(s);
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N;
  cin >> D;
  A.assign(N, long long());
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  solve();
  return 0;
}
