#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

const ll INF = 1ll << 60;

template <class I>
class SegmentTree {
 public:
  using Op = function<I(const I&, const I&)>;

 private:
  int n;
  vector<I> dat;
  Op op;
  I e;

 public:
  SegmentTree(int n_, const Op& op, const I& e)
      : op(op), e(e) {
    n = 1;
    while (n < n_) n *= 2;
    dat.resize(2 * n - 1, e);
  }
  SegmentTree(const vector<I>& init, const Op& op, const I& e)
      : SegmentTree(init.size(), op, e) {
    for (int i = 0; i < init.size(); i++) {
      dat[i + n - 1] = init[i];
    }
    for (int i = n - 2; i >= 0; i--) {
      dat[i] = op(dat[i * 2 + 1], dat[i * 2 + 2]);
    }
  }
  const I& operator[](int k) const {
    return dat[k + n - 1];
  }
  void update(int k, const I& a) {
    k += n - 1;
    dat[k] = a;
    while (k > 0) {
      k = (k - 1) / 2;
      dat[k] = op(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }
  // [a, b)
  I query(int a, int b) const {
    a += n - 1;
    b += n - 1;
    I vl = e;
    I vr = e;
    while (a < b) {
      if ((a & 1) == 0) vl = op(vl, dat[a]);
      if ((b & 1) == 0) vr = op(dat[b - 1], vr);
      a = a / 2;
      b = (b - 1) / 2;
    }
    return op(vl, vr);
  }
  // query(0, i) >= x となる最小のi
  int kth(const I& x) const {
    int k = 0;
    I v = e;
    while (k < n - 1) {
      I t = op(v, dat[k * 2 + 1]);
      if (x <= t) {
        k = k * 2 + 1;
      } else {
        v = t;
        k = k * 2 + 2;
      }
    }
    return k - (n - 1) + 1;
  }
};

struct Edge {
  int x, y;
  ll w;

  bool operator<(const Edge& rhs) const {
    if (w != rhs.w) return w < rhs.w;
    if (x != rhs.x) return x < rhs.x;
    return y < rhs.y;
  }
};

struct UnionFind {
  vector<int> parent;  // parent[root] is the negative of the size.
  UnionFind(int n)
      : parent(n, -1){};
  bool unite(int u, int v) {
    u = root(u);
    v = root(v);
    if (u == v) return false;
    if (parent[u] > parent[v]) swap(u, v);
    parent[u] += parent[v];
    parent[v] = u;
    return true;
  }
  bool find(int u, int v) {
    return root(u) == root(v);
  }
  int root(int u) {
    return parent[u] < 0 ? u : parent[u] = root(parent[u]);
  }
  int size(int u) {
    return -parent[root(u)];
  }
};

ll minimumSpanningTree(int N, vector<Edge> edges) {
  sort(edges.begin(), edges.end());
  UnionFind uf(N);
  ll res = 0;
  for (Edge& e : edges) {
    if (uf.unite(e.x, e.y)) {
      res += e.w;
    }
  }
  return res;
}

using P = pair<ll, int>;

int main() {
  int N;
  ll D;
  while (cin >> N >> D) {
    vector<ll> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    map<ll, int> num;
    {
      for (ll x : A) num[x] = 0;
      int id = 0;
      for (auto& e : num) e.snd = id++;
    }
    vector<Edge> edges;
    auto op = [&](const P& a, const P& b) {
      return min(a, b);
    };
    SegmentTree<P> segL(N, op, P(INF, -1));
    for (int i = 0; i < N; i++) {
      int x = num[A[i]];
      auto p = segL.query(0, x + 1);
      if (p.snd >= 0) {
        edges.push_back(Edge{i, p.snd, p.fst + i * D + A[i]});
      }
      segL.update(x, P(-i * D + A[i], i));
    }
    SegmentTree<P> segR(N, op, P(INF, -1));
    for (int i = N - 1; i >= 0; i--) {
      int x = num[A[i]];
      auto p = segR.query(0, x + 1);
      if (p.snd >= 0) {
        edges.push_back(Edge{i, p.snd, p.fst - i * D + A[i]});
      }
      segR.update(x, P(i * D + A[i], i));
    }
    ll res = minimumSpanningTree(N, edges);
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 45804