#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>
#include <tuple>
#include <limits>

template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max<int>(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr r, l;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max<int>(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

template <class T>
inline T scan() {
  T res;
  std::cin >> res;
  return res;
}

class union_find {
private:
  int component;
  std::vector<int> parent;

public:
  union_find() = default;
  union_find(int size_) { init(size_); }

  void init(int size_) {
    component = size_;
    parent.assign(size_, -1);
  }

  int count_components() const { 
    return component; 
  }
  int component_size(int i) { 
    return -parent[find_parent(i)]; 
  }
  bool same_component(int i, int j) { 
    return find_parent(i) == find_parent(j); 
  }

  int find_parent(int i) {
    if (parent[i] < 0) {
      return i;
    }
    else {
      return parent[i] = find_parent(parent[i]);
    }
  }

  bool unite(int i, int j) {
    i = find_parent(i);
    j = find_parent(j);
    if (i == j) {
      return true;
    }
    if (parent[i] > parent[j]) {
      std::swap(i, j);
    }
    parent[i] += parent[j];
    parent[j] = i;
    --component;
    return true;
  }

};

template <class T>
class segment_tree {
public:
  using value_type = typename T::value_type;
  using effector_type = typename T::effector_type;
  using value_operation = typename T::value_operation;
  using merge_operation = typename T::merge_operation;

private:
  int size;
  const value_operation op1;
  const merge_operation op2;
  std::vector<value_type> node;

  void update() {
    for (int k = size - 1; k > 0; --k) {
      node[k] = op1(node[k << 1 | 0], node[k << 1 | 1]);
    }
  }

public:
  segment_tree(): op1(value_operation()), op2(merge_operation()) { }
  segment_tree(int size_, const value_type &initial_ = value_operation().identity):
    op1(value_operation()), op2(merge_operation())
  { init(size_, initial_); }
  segment_tree(const std::vector<value_type> &node_):
    op1(value_operation()), op2(merge_operation())
  { build(node_); }

  void init(int size_, const value_type &initial_ = value_operation().identity) {
    size = 1;
    while (size < size_) {
      size <<= 1;
    }
    node.assign(size << 1, initial_);
    if (initial_ != value_operation().identity) {
      update();
    }
  }
  void build(const std::vector<value_type> &node_) {
    init(node_.size());
    assign(node_.begin(), node_.end(), 0);
  }

  void modify(int i, const effector_type &x) {
    i += size;
    node[i] = op2(node[i], x);
    while (i > 1) {
      i >>= 1;
      node[i] = op1(node[i << 1 | 0], node[i << 1 | 1]);
    }
  }
  template <class U>
  void modify(U begin, U end, int i) {
    i += size;
    while (begin != end) {
      node[i] = op2(node[i], *begin);
      ++i;
      ++begin;
    }
    update();
  }

  void assign(int i, const value_type &x) {
    i += size;
    node[i] = x;
    while (i > 1) {
      i >>= 1;
      node[i] = op1(node[i << 1 | 0], node[i << 1 | 1]);
    } 
  }
  template <class U>
  void assign(U begin, U end, int i) {
    i += size;
    while (begin != end) {
      node[i] = *begin;
      ++i;
      ++begin;
    }
    update();
  }

  value_type operator [] (int i) const { 
    return node[i + size];
  }
  value_type fold(int l, int r) const {
    l += size;
    r += size;
    value_type resl = op1.identity;
    value_type resr = op1.identity;
    while (l < r) {
      if (l & 1) {
        resl = op1(resl, node[l++]);
      }
      if (r & 1) {
        resr = op1(node[--r], resr);
      }
      l >>= 1;
      r >>= 1;
    }
    return op1(resl, resr);
  }

};

struct range_min_single_assign {
  using value_type = std::pair<long long, int>;
  using effector_type = std::pair<long long, int>;
  struct value_operation {
    value_type identity = std::make_pair(std::numeric_limits<long long>::max(), std::numeric_limits<int>::max());
    value_type operator () (const value_type &x, const value_type &y) const {
      return x < y ? x : y;
    }
  };
  struct merge_operation {
    value_type operator () (const value_type &x, const effector_type &y) const {
      return y;
    }
  };
};

int main() {
  const int N = scan<int>();
  const long long D = scan<long long>();
  std::vector<std::pair<int, int>> scale(N);
  for (const int i: range(0, N)) {
    std::cin >> scale[i].first;
    scale[i].second = i;
  }
  std::sort(scale.begin(), scale.end());
  std::vector<std::tuple<long long, int, int>> candidate;
  segment_tree<range_min_single_assign> left(N), right(N);
  for (const auto p: scale) {
    auto l = left.fold(0, p.second);
    if (l.second != std::numeric_limits<int>::max()) {
      candidate.emplace_back(l.first - D * (N - p.second - 1) + p.first, p.second, l.second);
    }
    auto r = right.fold(p.second + 1, N);
    if (r.second != std::numeric_limits<int>::max()) {
      candidate.emplace_back(r.first - D * p.second + p.first, p.second, r.second);
    }
    left.modify(p.second, std::make_pair(D * (N - p.second - 1) + p.first, p.second));
    right.modify(p.second, std::make_pair(D * p.second + p.first, p.second));
  }
  std::sort(candidate.begin(), candidate.end());
  union_find dsu(N);
  long long answer = 0;
  for (const auto tp: candidate) {
    long long cost;
    int u, v;
    std::tie(cost, u, v) = tp;
    if (!dsu.same_component(u, v)) {
      answer += cost;
      dsu.unite(u, v);
    }
  }
  std::cout << answer << '\n';
  return 0;
}


Measured memory_bytes: 28524