#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define STRINGIFY(n) #n
#define TOSTRING(n) STRINGIFY(n)
#define PREFIX "#" TOSTRING(__LINE__) "| "
#define debug(x) \
{ \
  std::cout << PREFIX << #x << " = " << x << std::endl; \
}

std::ostream& output_indent(std::ostream& os, int ind) {
  for(int i = 0; i < ind; i++) os << " ";
  return os;
}

template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p);
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v);

template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p) {
  return (os << "(" << p.first << ", " << p.second << ")");
}
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
  os << "[";
  for(int i = 0;i < v.size();i++) os << v[i] << ", ";
  return (os << "]");
}

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain { Cond cond; chain(Cond cond) : cond(cond) {} template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }


#include <vector>
#include <tuple>

struct union_find {
  std::vector<int> par;
  union_find(int N): par(N, -1) {}
  int root(int x) {
    return par[x] < 0 ? x : par[x] = root(par[x]);
  }
  std::tuple<int, int> unite(int x, int y) {
    x = root(x);
    y = root(y);
    if(x == y) return { -1, -1 };
    if(par[x] > par[y]) std::swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return { x, y };
  }
  int size(int x) {
    return -par[root(x)];
  }
};

int main() {
  i64 N, D;
  cin >> N >> D;
  vector<i64> A(N);
  rep(i,0,N) {
    cin >> A[i];
  }

  union_find uf(N);
  i64 ans = 0;
  while(uf.size(0) < N) {
    vector<i64> belong(N);
    vector<i64> par(N);
    i64 cnt = 0;
    rep(i,0,N) {
      if(uf.root(i) == i) {
        belong[i] = cnt;
        par[cnt++] = i;
      }
    }
    rep(i,0,N) {
      belong[i] = belong[uf.root(i)];
    }

    vector<pair<i64, i64>> edge(cnt, { i64(1e18), -1 });
    auto func = [](vector<pair<i64, i64>>& min2, pair<i64, i64> p) {
      rep(i,0,2) {
        if(min2[i].second == p.second) {
          min2[i] = std::min(min2[i], p);
          return;
        }
      }
      rep(i,0,2) {
        if(p < min2[i]) std::swap(min2[i], p);
      }
    };
    auto choise = [](const vector<pair<i64, i64>>& min2, i64 v) {
      rep(i,0,2) {
        if(min2[i].second == v) return min2[1 - i];
      }
      return std::min(min2[0], min2[1]);
    };
    {
      vector<pair<i64, i64>> min2(2, { i64(1e18), -1 });
      rep(i,0,N) {
        auto e = choise(min2, belong[i]);
        e.first += i * D + A[i];
        edge[belong[i]] = std::min(edge[belong[i]], e);
        func(min2, { -i * D + A[i], belong[i] });
      }
    }
    {
      vector<pair<i64, i64>> min2(2, { i64(1e18), -1 });
      for(i64 i = N; i --> 0;) {
        auto e = choise(min2, belong[i]);
        e.first += -i * D + A[i];
        edge[belong[i]] = std::min(edge[belong[i]], e);
        func(min2, { i * D + A[i], belong[i] });
      }
    }

    rep(i,0,cnt) {
      i64 a = par[i];
      i64 b = par[edge[i].second];
      i64 cost = edge[i].first;
      if(uf.root(a) != uf.root(b)) {
        uf.unite(a, b);
        ans += cost;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 11984