#include <bits/stdc++.h>

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;
struct RangeMin {
  using T = pair<long long, int>;
  T operator()(const T &a, const T &b) {
    if (a.first <= b.first) {
      return {min(a.first, b.first), a.second};
    } else {
      return {min(a.first, b.first), b.second};
    }
  }
  static constexpr T id() { return T(LINF, -1); };
};

struct RangeAdd {
  using T = long long;
  T operator()(const T &a, const T &b) { return a + b; };
  static constexpr T id() { return T(0); };
};

struct Min_Add {
  using V = RangeMin;
  using A = RangeAdd;
  V::T operator()(const V::T &a, const A::T &b, const int &h) { return {a.first + b, a.second}; };
};
template <typename M>
struct LazySegmentTree {
  using Val = typename M::V::T;
  using Del = typename M::A::T;
  typename M::V calc;
  typename M::A composite;
  M act;
  vector<Val> val;
  vector<Del> delay;

  int n, height;
  explicit LazySegmentTree(int size) : n(1), height(0) {
    while (n < size) {
      n <<= 1;
      ++height;
    }
    val = vector<Val>(n << 1, calc.id());
    delay = vector<Del>(n << 1, composite.id());
  }
  explicit LazySegmentTree(const vector<Val> &v) : n(1), height(0) {
    while (n < v.size()) {
      n <<= 1;
      ++height;
    }
    val = vector<Val>(n << 1, calc.id());
    delay = vector<Del>(n << 1, composite.id());
    copy(v.begin(), v.end(), val.begin() + n);
    for (int i = n - 1; i > 0; --i) {
      val[i] = calc(val[i * 2], val[i * 2 + 1]);
    }
  }
  void propagate(int k, int h) {
    val[k] = act(val[k], delay[k], h);
    if (h > 0) {
      delay[2 * k] = composite(delay[2 * k], delay[k]);
      delay[2 * k + 1] = composite(delay[2 * k + 1], delay[k]);
    }
    delay[k] = composite.id();
  }
  inline void update(int l, int r, Del v) { update(l, r, v, 1, 0, n, height); }
  void update(int l, int r, Del v, int k, int a, int b, int h) {
    if (l <= a && b <= r) {
      delay[k] = composite(delay[k], v);
      propagate(k, h);
      return;
    }
    propagate(k, h);
    if (b <= l || r <= a) {
      return;
    }  //
    update(l, r, v, 2 * k, a, (a + b) / 2, h - 1);
    update(l, r, v, 2 * k + 1, (a + b) / 2, b, h - 1);
    val[k] = calc(val[2 * k], val[2 * k + 1]);
  }
  inline Val query(int l, int r) { return query(l, r, 1, 0, n, height); }
  Val query(int l, int r, int k, int a, int b, int h) {
    if (b <= l || r <= a) {
      return calc.id();
    }  //
    propagate(k, h);
    if (l <= a && b <= r) {
      return val[k];
    }
    Val vall = query(l, r, 2 * k, a, (a + b) / 2, h - 1);
    Val valr = query(l, r, 2 * k + 1, (a + b) / 2, b, h - 1);
    return calc(vall, valr);
  }
};
class Solver {
 public:
  int n;
  LL d;
  vector<LL> a;
  Solver(LL n, LL d) : n(n), d(d), a(n){};

  void solve() {
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    if (n == 1) {
      cout << 0 << endl;
      return;
    }
    if (n == 2) {
      cout << a[0] + a[1] + d << endl;
      return;
    }
    vector<pair<LL, int>> R(n), L(n);
    R[0] = {LINF, 0};
    L[0] = {a[0] + a[1] + d, 0};
    R[1] = {LINF, 1};
    L[1] = {LINF, 1};
    for (int i = 2; i < n; ++i) {
      R[i] = {d * (LL)(i - 1) + a[1] + a[i], i};
      L[i] = {LINF, i};
    }

    LazySegmentTree<Min_Add> segr(R), segl(L);
    LL ans = 0;
    int rb = 1, lb = 1;
    set<LL> sr, sl;
    sr.insert(1);
    sl.insert(1);

    for (int loop = 0; loop < n - 1; ++loop) {
      auto tmpR = segr.query(0, n);
      auto tmpL = segl.query(0, n);
      int pos;
      if (tmpR.first <= tmpL.first) {
        ans += tmpR.first;
        pos = tmpR.second;
      } else {
        ans += tmpL.first;
        pos = tmpL.second;
      }
      DBG(tmpR, tmpL, pos)

      //update segr
      for (int i = pos; i < rb; ++i) {
        segr.update(i, i + 1, d * (LL)(i - pos) + a[pos] + a[i] - segr.query(i, i + 1).first);
      }
      bool fr = false;
      if (pos < rb) {
        rb = pos;
        sr.insert(pos);
        fr = true;
      } else {
        auto pp = *(prev(sr.lower_bound(pos)));
        LL diff = -(a[pp] - d * pp) + (a[pos] - d * pos);
        if (diff < 0) {
          segr.update(pos, *sr.lower_bound(pos), diff);
          sr.insert(pos);
          fr = true;
        }
      }
      while (fr) {
        auto it = sr.upper_bound(pos);
        if (it == sr.end()) break;
        auto it2 = next(it);
        int it3 = n;
        if (it2 != sr.end()) it3 = *it2;
        LL diff = -(a[*it] - d * *it) + (a[pos] - d * pos);
        if (diff < 0) {
          segr.update(*it, it3, diff);
          sr.erase(it);
        } else {
          break;
        }
      }

      // update segl
      for (int i = lb + 1; i <= pos; ++i) {
        segl.update(i, i + 1, d * (LL)(pos - i) + a[pos] + a[i] - segl.query(i, i + 1).first);
      }
      bool fl = false;
      if (pos > lb) {
        lb = pos;
        sl.insert(pos);
        fl = true;
      } else {
        auto pp = *(sl.lower_bound(pos));
        LL diff = -(a[pp] + d * pp) + (a[pos] + d * pos);
        if (diff < 0) {
          if (sl.lower_bound(pos) == sl.begin()) {
            segl.update(0, pos, diff);
          } else {
            segl.update(*prev(sl.lower_bound(pos)) + 1, pos, diff);
          }
          sl.insert(pos);
          fl = true;
        }
      }
      while (fl) {
        if (sl.lower_bound(pos) == sl.begin()) break;
        auto it = prev(sl.lower_bound(pos));
        if (it == sl.begin()) {
          LL diff = -(a[*it] + d * *it) + (a[pos] + d * pos);
          if (diff < 0) {
            segl.update(0, *it + 1, diff);
            sl.erase(it);
          } else {
            break;
          }
        } else {
          auto it2 = prev(it);
          LL diff = -(a[*it] + d * *it) + (a[pos] + d * pos);
          if (diff < 0) {
            segl.update(*it2 + 1, *it + 1, diff);
            sl.erase(it);
          } else {
            break;
          }
        }
      }

      //remove
      segr.update(pos, pos + 1, LINF - segr.query(pos, pos + 1).first);
      segl.update(pos, pos + 1, LINF - segl.query(pos, pos + 1).first);

      /*else {
      ans += tmpL.first;
      //remove
      segr.update(tmpL.second, tmpL.second + 1, LINF - segr.query(tmpL.second, tmpL.second + 1).first);
      segl.update(tmpL.second, tmpL.second + 1, LINF - segl.query(tmpL.second, tmpL.second + 1).first);

      //update segr

      // update segl
      if (tmpR.second > rb) {
        lb = tmpR.second;
      }
    }*/
    }
    cout << ans << endl;
  }
};  // namespace Problem

}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0, d;
  std::cin >> n >> d;

  Problem::Solver sol(n, d);
  sol.solve();
  return 0;
}
