#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
char string_in_buffer[(int)260];
void fast_scan(int &first) { scanf("%d", &first); }
void fast_scan(long long &first) { scanf("%lld", &first); }
void fast_scan(unsigned long long &first) { scanf("%llu", &first); }
void fast_scan(double &first) { scanf("%lf", &first); }
void fast_scan(long double &first) { scanf("%Lf", &first); }
void fast_scan(char &first) {
  scanf("%c", &first);
  if (first == '\n') {
    fast_scan(first);
  }
}
void fast_scan(string &first) {
  scanf("%s", string_in_buffer);
  first = string(string_in_buffer);
}
template <class TFirst, class TSecond>
void fast_scan(pair<TFirst, TSecond> &p) {
  fast_scan(p.first);
  fast_scan(p.second);
}
template <class T>
void fast_scan(vector<T> &v) {
  for (auto &first : v) fast_scan(first);
}
void fast_print(const int &first) { printf("%d", first); }
void fast_print(const unsigned int &first) { printf("%u", first); }
void fast_print(const long long &first) { printf("%lld", first); }
void fast_print(const unsigned long long &first) { printf("%llu", first); }
void fast_print(const double &first) { printf("%.15lf", first); }
void fast_print(const long double &first) { printf("%.15Lf", first); }
void fast_print(const char &first) { printf("%c", first); };
void fast_print(const string &first) { printf("%s", first.c_str()); }
void fast_print(const char v[]) { fast_print((string)v); }
template <class TFirst, class TSecond>
void fast_print(const pair<TFirst, TSecond> &p) {
  fast_print(p.first);
  fast_print(' ');
  fast_print(p.second);
}
template <class T>
void fast_print(const vector<T> &v) {
  if (v.empty()) return;
  fast_print(v[0]);
  for (int i = 1; i < v.size(); i++) {
    fast_print(' ');
    fast_print(v[i]);
  }
}
template <class T>
void fast_print(const vector<vector<T>> &v) {
  if (v.empty()) return;
  fast_print(v[0]);
  for (int i = 1; i < v.size(); i++) {
    fast_print('\n');
    fast_print(v[i]);
  }
}
template <class T>
void fast_print(const T &v) {
  for (const auto &first : v) {
    fast_print(first);
    fast_print(' ');
  }
}
using namespace std;
namespace smart_io {
string print_start = "";
string sep = " ";
bool first_print = false;
void precall_print() {
  fast_print(print_start);
  print_start = "\n";
  first_print = true;
}
void _print(deque<string>) {}
template <class T, class... Args>
void _print(deque<string> names, T elem, Args... args) {
  if (!first_print) {
    fast_print("\n");
  } else {
    first_print = false;
  }
  fast_print(names.front());
  fast_print(" = ");
  fast_print(elem);
  names.pop_front();
  _print(names, args...);
}
}  // namespace smart_io
template <class T>
ostream &operator,(ostream &os, const T &object) {
  if (!smart_io::first_print) {
    fast_print(smart_io::sep);
  } else {
    smart_io::first_print = false;
  }
  fast_print(object);
  return os;
}
template <class T>
istream &operator,(istream &is, T &object) {
  fast_scan(object);
  return is;
}
namespace escape__from__random__aetuhoetnuhshe {
using namespace std::chrono;
mt19937 rng(duration_cast<milliseconds>(system_clock::now().time_since_epoch())
                .count());
uniform_real_distribution<> prob_dist(0.0, 1.0);
};  // namespace escape__from__random__aetuhoetnuhshe
namespace typedefs {}
namespace numbers_operation {
template <class T>
T floor_mod(T a, T b) {
  if (a >= 0 && b >= 0) return a % b;
  if (a <= 0 && b <= 0) return a % b;
  return abs(b) - (abs(a) % abs(b));
}
}  // namespace numbers_operation
using namespace numbers_operation;
using namespace typedefs;
using namespace escape__from__random__aetuhoetnuhshe;
template <class Value, class Mod, class Magic, class ApplyMod, class MergeMods>
struct TreeSegment {
  struct Node {
    bool have_mod = false;
    int l = -1, r = -1;
    Value value;
    Mod mod;
  };
  Magic magic;
  ApplyMod apply_mod;
  MergeMods merge_mods;
  vector<Node> S;
  int n;
  bool __intersects(const int &tl, const int &tr, const int &ql,
                    const int &qr) {
    return !(tr <= ql || qr <= tl);
  }
  int __create_node() {
    S.push_back(Node());
    return ((int)S.size()) - 1;
  }
  Value __get_value(const int &i, const int &tl, const int &tr) {
    if (!S[i].have_mod) return S[i].value;
    return apply_mod(S[i].value, S[i].mod, tl, tr);
  }
  void __recalc_value(const int &i, const int &tl, const int &tr) {
    if (tl + 1 != tr) {
      int mid = (tl + tr) / 2;
      S[i].value =
          magic(__get_value(S[i].l, tl, mid), __get_value(S[i].r, mid, tr));
    }
  }
  void __add_mod(const int &i, const int &tl, const int &tr, const Mod &sub) {
    if (S[i].have_mod) {
      S[i].mod = merge_mods(S[i].mod, sub, tl, tr);
    } else {
      S[i].mod = sub;
      S[i].have_mod = true;
    }
  }
  void __push(const int &i, const int &tl, const int &tr) {
    if (S[i].have_mod) {
      S[i].value = apply_mod(S[i].value, S[i].mod, tl, tr);
      if (tl + 1 != tr) {
        int mid = (tl + tr) / 2;
        __add_mod(S[i].l, tl, mid, S[i].mod);
        __add_mod(S[i].r, mid, tr, S[i].mod);
      }
      S[i].have_mod = false;
    }
  }
  int init(const int &tl, const int &tr, const vector<Value> &src) {
    int i = __create_node();
    if (tl + 1 == tr) {
      S[i].value = src[tl];
    } else {
      int mid = (tl + tr) / 2;
      int __a = init(tl, mid, src);
      int __b = init(mid, tr, src);
      S[i].l = __a;
      S[i].r = __b;
      __recalc_value(i, tl, tr);
    }
    return i;
  }
  Value __query(const int &i, const int &tl, const int &tr, const int &ql,
                const int &qr) {
    __push(i, tl, tr);
    if (ql <= tl && tr <= qr) {
      return S[i].value;
    } else {
      int mid = (tl + tr) / 2;
      if (__intersects(tl, mid, ql, qr) && __intersects(mid, tr, ql, qr)) {
        return magic(__query(S[i].l, tl, mid, ql, qr),
                     __query(S[i].r, mid, tr, ql, qr));
      } else if (__intersects(tl, mid, ql, qr)) {
        return __query(S[i].l, tl, mid, ql, qr);
      } else {
        return __query(S[i].r, mid, tr, ql, qr);
      }
    }
  }
  void __change(const int &i, const int &tl, const int &tr, const int &j,
                const Value &_new) {
    __push(i, tl, tr);
    if (tl + 1 == tr) {
      S[i].value = _new;
    } else {
      int m = (tl + tr) / 2;
      if (j < m) {
        __change(S[i].l, tl, m, j, _new);
      } else {
        __change(S[i].r, m, tr, j, _new);
      }
      __recalc_value(i, tl, tr);
    }
  }
  void __update(const int &i, const int &tl, const int &tr, const int &ql,
                const int &qr, const Mod &mod) {
    __push(i, tl, tr);
    if (ql <= tl && tr <= qr) {
      __add_mod(i, tl, tr, mod);
    } else {
      int mid = (tl + tr) / 2;
      if (__intersects(tl, mid, ql, qr)) {
        __update(S[i].l, tl, mid, ql, qr, mod);
      }
      if (__intersects(mid, tr, ql, qr)) {
        __update(S[i].r, mid, tr, ql, qr, mod);
      }
      __recalc_value(i, tl, tr);
    }
  }
  template <class Check>
  pair<int, Value> __find_right(const int &i, const int &tl, const int &tr,
                                const int &L, const Check &checker,
                                const Value &pref) {
    __push(i, tl, tr);
    if (tr <= L) return make_pair(-1, pref);
    if (tl + 1 == tr) {
      Value _this = magic(pref, __get_value(i, tl, tr));
      if (checker(_this)) {
        return make_pair(tl, _this);
      } else {
        return make_pair(-1, _this);
      }
    } else {
      int mid = (tl + tr) / 2;
      if (L <= tl) {
        Value _left = magic(pref, __get_value(S[i].l, tl, mid));
        if (checker(_left)) {
          return __find_right(S[i].l, tl, mid, L, checker, pref);
        } else {
          return __find_right(S[i].r, mid, tr, L, checker, _left);
        }
      } else {
        auto t = __find_right(S[i].l, tl, mid, L, checker, pref);
        if (t.first != -1) return t;
        return __find_right(S[i].r, mid, tr, L, checker, t.second);
      }
    }
  }
  template <class Check>
  pair<int, Value> __find_left(const int &i, const int &tl, const int &tr,
                               const int &R, const Check &checker,
                               const Value &pref) {
    __push(i, tl, tr);
    if (R < tl) return make_pair(-1, pref);
    if (tl + 1 == tr) {
      Value _this = magic(pref, __get_value(i, tl, tr));
      if (checker(_this)) {
        return make_pair(tl, _this);
      } else {
        return make_pair(-1, _this);
      }
    } else {
      int mid = (tl + tr) / 2;
      if (tr <= R + 1) {
        Value _right = magic(pref, __get_value(S[i].r, mid, tr));
        if (checker(_right)) {
          return __find_left(S[i].r, mid, tr, R, checker, pref);
        } else {
          return __find_left(S[i].l, tl, mid, R, checker, _right);
        }
      } else {
        auto t = __find_left(S[i].r, mid, tr, R, checker, pref);
        if (t.first != -1) return t;
        return __find_left(S[i].l, tl, mid, R, checker, t.second);
      }
    }
  }
  void init(const vector<Value> &src) {
    n = ((int)src.size());
    init(0, ((int)src.size()), src);
  }
  TreeSegment(const int &n, const Value &def, Magic _magic, ApplyMod _apply_mod,
              MergeMods _merge_mods, Mod)
      : magic(_magic), apply_mod(_apply_mod), merge_mods(_merge_mods) {
    init(vector<Value>(n, def));
  }
  TreeSegment(const vector<Value> &def, Magic _magic, ApplyMod _apply_mod,
              MergeMods _merge_mods, Mod)
      : magic(_magic), apply_mod(_apply_mod), merge_mods(_merge_mods) {
    init(def);
  }
  Value query(const int &ql, const int &qr) {
    if (ql >= qr) return make_pair((long long)1e18, -1);
    return __query(0, 0, n, ql, qr);
  }
  void change(const int &i, const Value &value) {
    assert(0 <= i && i < n);
    __change(0, 0, n, i, value);
  }
  void update(const int &ql, const int &qr, const Mod &mod) {
    __update(0, 0, n, ql, qr, mod);
  }
  template <class Check>
  int find_right(const int &L, const Check &checker, const Value &start) {
    if (checker(start)) return L - 1;
    int rez = __find_right(0, 0, n, L, checker, start).first;
    return (rez == -1) ? n : rez;
  }
  template <class Check>
  int find_left(const int &R, const Check &checker, const Value &start) {
    if (checker(start)) return R + 1;
    int rez = __find_left(0, 0, n, R, checker, start).first;
    return (rez == -1) ? -1 : rez;
  }
};
int n;
long long D;
vector<int> a;
struct SUS {
  vector<vector<int>> comps;
  vector<int> up;
  int get_root(int v) {
    if (up[v] == v) return v;
    return up[v] = get_root(up[v]);
  }
  SUS(int n) {
    up.resize(n);
    comps.resize(n);
    for (int i = 0; i < (n); i++) {
      up[i] = i;
      comps[i].push_back(i);
    }
  }
  void merge(int a, int b) {
    a = get_root(a);
    b = get_root(b);
    if (a == b) return;
    if (((int)comps[a].size()) > ((int)comps[b].size())) swap(a, b);
    for (int first : comps[a]) {
      comps[b].push_back(first);
    }
    comps[a].clear();
    comps[a].shrink_to_fit();
    up[a] = b;
  }
  bool one_comp(int a, int b) { return get_root(a) == get_root(b); }
};
signed main(signed argc, char *argv[]) {
  cin, n, D;
  a.resize(n);
  cin, a;
  SUS sus(n);
  long long result = 0;
  auto __min = [](pair<long long, int> a, pair<long long, int> b) {
    return min(a, b);
  };
  auto __apply_mod = [](pair<long long, int> value, bool, int, int) {
    return value;
  };
  auto __merge_mods = [](bool, bool, int, int) { return true; };
  TreeSegment<pair<long long, int>, bool, decltype(__min),
              decltype(__apply_mod), decltype(__merge_mods)>
      POS(n, make_pair((long long)1e18, -1), __min, __apply_mod, __merge_mods,
          true);
  TreeSegment<pair<long long, int>, bool, decltype(__min),
              decltype(__apply_mod), decltype(__merge_mods)>
      NEG(n, make_pair((long long)1e18, -1), __min, __apply_mod, __merge_mods,
          true);
  vector<pair<long long, int>> edges(n);
  for (int i = 0; i < n; i++) {
    POS.change(i, make_pair(D * (i + 1) + a[i], i));
    NEG.change(i, make_pair(-D * (i + 1) + a[i], i));
  }
  while (true) {
    int noempty = 0;
    for (int i = 0; i < (n); i++) {
      if (!sus.comps[i].empty()) {
        noempty++;
      }
    }
    if (noempty == 1) break;
    for (int i = 0; i < n; i++) {
      if (sus.comps[i].empty()) continue;
      edges[i] = make_pair((long long)1e18, -1);
      for (int j : sus.comps[i]) {
        POS.change(j, make_pair((long long)1e18, -1));
        NEG.change(j, make_pair((long long)1e18, -1));
      }
      for (int j : sus.comps[i]) {
        auto c = NEG.query(0, j);
        auto d = POS.query(j + 1, n);
        c.first += a[j] + (j + 1) * D;
        d.first += a[j] - (j + 1) * D;
        edges[i] = min(edges[i], min(c, d));
      }
      for (int j : sus.comps[i]) {
        POS.change(j, make_pair(D * (j + 1) + a[j], j));
        NEG.change(j, make_pair(-D * (j + 1) + a[j], j));
      }
    }
    for (int i = 0; i < n; i++) {
      if (edges[i].second == -1) continue;
      int a = i;
      int b = edges[i].second;
      if (sus.one_comp(a, b)) continue;
      sus.merge(a, b);
      result += edges[i].first;
    }
  }
  smart_io::precall_print();
  cout, result;
}
