#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll linf = 1e18;
const double eps = 1e-12, pi = acos(-1);
template <typename Head>
void out(Head h) {
  cout << h << endl;
}
template <typename Head, typename... Tail>
void out(Head h, Tail... t) {
  cout << h << " ";
  out(t...);
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
  for (auto&& x : v) is >> x;
  return is;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  for (ll i = (0), __last_i = (v.size()); i < __last_i; i++) {
    if (i) os << " ";
    os << v[i];
  }
  return os;
}
ostream& operator<<(ostream& os, const vector<string>& v) {
  for (ll i = (0), __last_i = (v.size()); i < __last_i; i++) {
    if (i) os << endl;
    os << v[i];
  }
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
  for (ll i = (0), __last_i = (v.size()); i < __last_i; i++) {
    if (i) os << endl;
    os << v[i];
  }
  return os;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
struct yes_no : std::numpunct<char> {
  string_type do_truename() const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};
void solve();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  locale loc(locale(), new yes_no);
  cout.imbue(loc);
  cout << fixed << setprecision(10) << boolalpha;
  solve();
}
class UnionFind {
  vector<ll> par, h, sz;

 public:
  UnionFind(ll size) : par(size, 0), h(size, 0), sz(size, 1) {
    for (ll i = (0), __last_i = (size); i < __last_i; i++) par[i] = i;
  }
  void unite(ll u, ll v) {
    u = root(u), v = root(v);
    if (u == v) return;
    if (h[u] < h[v]) {
      par[u] = v;
      sz[v] += sz[u];
    } else {
      par[v] = u;
      sz[u] += sz[v];
    }
    if (h[u] == h[v]) ++h[u];
  }
  ll size(ll v) { return sz[root(v)]; }
  bool isUnited(ll u, ll v) { return root(u) == root(v); }
  ll root(ll v) {
    if (par[v] == v) return v;
    return par[v] = root(par[v]);
  }
};
struct Edge {
  ll a, b, c;
};
bool operator<(const Edge& e1, const Edge& e2) { return e1.c < e2.c; }
void solve() {
  ll n, D;
  cin >> n >> D;
  vector<ll> a(n);
  cin >> a;
  vector<P> c1(n), c2(n);
  for (ll i = (0), __last_i = (n); i < __last_i; i++) {
    c1[i] = P(-i * D + a[i], i);
    c2[i] = P(i * D + a[i], i);
  }
  vector<P> L(n + 1, P(linf, 0)), R(n + 1, P(linf, 0));
  for (ll i = (0), __last_i = (n); i < __last_i; i++)
    L[i + 1] = (L[i] < c1[i] ? L[i] : c1[i]);
  for (ll i = (n)-1, __last_i = (0); i >= __last_i; i--)
    R[i] = (R[i + 1] < c2[i] ? R[i + 1] : c2[i]);
  vector<Edge> edges;
  for (ll i = (0), __last_i = (n); i < __last_i; i++) {
    {
      P p = L[i];
      ll cost = p.first;
      ll to = p.second;
      cost += i * D + a[i];
      edges.push_back({i, to, cost});
    }
    {
      P p = R[i + 1];
      ll cost = p.first;
      ll to = p.second;
      cost += -i * D + a[i];
      edges.push_back({i, to, cost});
    }
  }
  sort(begin(edges), end(edges));
  UnionFind uf(n);
  ll ans = 0;
  for (auto&& e : edges) {
    if (uf.isUnited(e.a, e.b)) continue;
    uf.unite(e.a, e.b);
    ans += e.c;
  }
  cout << ans << endl;
}
