#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
inline bool chmax(A &a, B b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename A, typename B>
inline bool chmin(A &a, B b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll << 30;
constexpr ll longINF = 1ll << 60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
struct UnionFind {
  vector<int> par, rank;
  UnionFind(int n) {
    par.resize(n);
    rank.resize(n);
    for (int i = (0); i < (n); ++i) {
      par[i] = i;
      rank[i] = 0;
    }
  }
  int operator[](int x) { return find(x); }
  int find(int x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) swap(x, y);
    par[y] = x;
    if (rank[x] == rank[y]) rank[x]++;
  }
  bool same(int x, int y) { return find(x) == find(y); }
};
using pll = pair<ll, ll>;
using ll3 = tuple<ll, ll, ll>;
ll N, D;
vector<pii> solve(UnionFind &uf, vector<ll> &A) {
  set<pll> ss;
  for (int i = (0); i < (N); ++i) ss.insert(pll(i * D + A[i], i));
  auto bit = ss.begin();
  int bitc = 0;
  vector<pair<set<pll>::iterator, int> > v(N, make_pair(bit, 0));
  vector<pii> pairv;
  for (int i = (0); i < (N); ++i) {
    while (bit != ss.end() && bit->second <= i) ++bit, ++bitc;
    auto it = v[uf[i]].first;
    int itc = v[uf[i]].second;
    if (it == ss.end()) continue;
    if (itc < bitc) it = bit;
    while (it != ss.end() && (uf[it->second] == uf[i] || it->second <= i))
      ++it, ++itc;
    v[uf[i]] = make_pair(it, itc);
    if (it == ss.end()) continue;
    pairv.emplace_back(i, it->second);
  }
  return pairv;
}
int main() {
  cin >> N >> D;
  vector<ll> A(N), RA;
  for (int i = (0); i < (N); ++i) scanf("%lld", &A[i]);
  RA = A;
  reverse(begin(RA), end(RA));
  UnionFind uf(N);
  ll ans = 0;
  int cnt = 0;
  while (true) {
    vector<pii> pairv[2]{solve(uf, A), solve(uf, RA)};
    for (pii &cur : pairv[1]) {
      cur.first = N - cur.first - 1;
      cur.second = N - cur.second - 1;
    }
    vector<ll3> v;
    for (int i = (0); i < (2); ++i)
      for (pii &cur : pairv[i])
        v.emplace_back(
            abs(cur.first - cur.second) * D + A[cur.first] + A[cur.second],
            cur.first, cur.second);
    sort(begin(v), end(v));
    for (ll3 &cur : v) {
      ll cost, x, y;
      tie(cost, x, y) = cur;
      if (uf[x] == uf[y]) puts("K");
    }
    bool loop = false;
    for (ll3 &cur : v) {
      ll cost, x, y;
      tie(cost, x, y) = cur;
      if (uf[x] == uf[y]) continue;
      uf.unite(x, y);
      loop = true;
      cnt++;
      ans += cost;
    }
    if (!loop) break;
  }
  assert(cnt == N - 1);
  cout << ans << endl;
  return 0;
}
