#include <bits/stdc++.h>
using namespace std;
inline int rei() {
  int x;
  cin >> x;
  return x;
}
inline long long rel() {
  long long x;
  cin >> x;
  return x;
}
inline string res() {
  string x;
  cin >> x;
  return x;
}
class Monoid {
 public:
  using t1 = tuple<long long, long long, int>;
  using t2 = long long;
  static t1 id1() {
    return make_tuple(10000000000000000, 10000000000000000, -1);
  }
  static t2 id2() { return 10000000000000000; }
  static t1 op1(const t1& l, const t1& r) {
    if (get<0>(l) + get<1>(l) < get<0>(r) + get<1>(r)) {
      return l;
    } else {
      return r;
    }
  }
  static t1 op2(const t1& l, const t2& r) {
    return make_tuple(get<0>(l), min(get<1>(l), r), get<2>(l));
  }
  static t2 op3(const t2& l, const t2& r) { return min(r, l); }
};
template <typename M>
class LazySegmentTree {
  using T1 = typename M::t1;
  using T2 = typename M::t2;

 private:
  const int h, n;
  vector<T1> data;
  vector<T2> lazy;

 private:
  int ceillog2(int n) {
    int res = 1;
    int c = 0;
    while (res < n) {
      res <<= 1;
      c++;
    }
    return c;
  }
  void push(int node) {
    if (lazy[node] == M::id2()) return;
    if (node < n) {
      lazy[node * 2] = M::op3(lazy[node * 2], lazy[node]);
      lazy[node * 2 + 1] = M::op3(lazy[node * 2 + 1], lazy[node]);
    }
    data[node] = M::op2(data[node], lazy[node]);
    lazy[node] = M::id2();
  }
  void update(int node) {
    data[node] = M::op1(M::op2(data[node * 2], lazy[node * 2]),
                        M::op2(data[node * 2 + 1], lazy[node * 2 + 1]));
  }

 public:
  LazySegmentTree(int n_)
      : h(ceillog2(n_)),
        n(1 << h),
        data(n * 2, M::id1()),
        lazy(n * 2, M::id2()) {}
  LazySegmentTree(int n_, T1 v1)
      : h(ceillog2(n_)), n(1 << h), data(n * 2, v1), lazy(n * 2, M::id2()) {}
  LazySegmentTree(const vector<T1>& data_)
      : h(ceillog2(data_.size())),
        n(1 << h),
        data(n * 2, M::id1()),
        lazy(n * 2, M::id2()) {
    init(data_);
  }
  void init() {
    for (int i = n - 1; i >= 1; i--)
      data[i] = M::op1(data[i * 2], data[i * 2 + 1]);
  }
  void init(const vector<T1>& data_) {
    for (int i = 0; i < (int)data_.size(); i++) data[i + n] = data_[i];
    init();
  }
  void update(int l, int r, T2 val) {
    l += n, r += n;
    for (int i = h; i > 0; i--) push(l >> i), push(r >> i);
    int tl = l, tr = r;
    r++;
    while (l < r) {
      if (l & 1) lazy[l] = M::op3(lazy[l], val), l++;
      if (r & 1) r--, lazy[r] = M::op3(lazy[r], val);
      l >>= 1;
      r >>= 1;
    }
    while (tl >>= 1, tr >>= 1, tl) {
      update(tl);
      update(tr);
    }
  }
  void update(int p, T1 val) {
    p += n;
    for (int i = h; i > 0; i--) push(p >> i);
    data[p] = val;
    lazy[p] = M::id2();
    while (p >>= 1, p) {
      update(p);
    }
  }
  T1 find(int l, int r) {
    l += n, r += n;
    for (int i = h; i > 0; i--) push(l >> i), push(r >> i);
    r++;
    T1 res1 = M::id1(), res2 = M::id1();
    while (l < r) {
      if (l & 1) res1 = M::op1(res1, M::op2(data[l], lazy[l])), l++;
      if (r & 1) r--, res2 = M::op1(M::op2(data[r], lazy[r]), res2);
      l >>= 1;
      r >>= 1;
    }
    return M::op1(res1, res2);
  }
};
long long A[200000];
void Calc() {
  int N = rei();
  long long D = rel();
  vector<tuple<long long, long long, int>> V1(N);
  vector<tuple<long long, long long, int>> V2(N);
  for (int i = 0; i < N; i++) {
    A[i] = rel();
    V1[i] = make_tuple(A[i] + D * i, 10000000000000000, i);
    V2[i] = make_tuple(A[i] - D * i, 10000000000000000, i);
  }
  LazySegmentTree<Monoid> Seg1(V1);
  LazySegmentTree<Monoid> Seg2(V2);
  Seg1.update(1, N - 1, A[0]);
  Seg1.update(0, Monoid::id1());
  Seg2.update(0, Monoid::id1());
  long long ans = 0;
  for (int i = 1; i < N; i++) {
    tuple<long long, long long, int> m =
        Monoid::op1(Seg1.find(0, N - 1), Seg2.find(0, N - 1));
    ans += get<0>(m) + get<1>(m);
    int p = get<2>(m);
    if (p != N - 1) {
      Seg1.update(p, N - 1, A[p] - D * p);
    }
    if (p != 0) {
      Seg2.update(0, p, A[p] + D * p);
    }
    Seg1.update(p, Monoid::id1());
    Seg2.update(p, Monoid::id1());
  }
  cout << ans << endl;
}
int main(int argc, char** argv) {
  ios::sync_with_stdio(false), cin.tie(0);
  cout.tie(0);
  Calc();
  return 0;
}
