#include <bits/stdc++.h>
using namespace std;
template <class T>
struct UF {
  vector<T> par, sz;
  UF(T n) {
    par.resize(n);
    sz.resize(n);
    for (int i = 0; i < n; ++i) {
      par[i] = i;
      sz[i] = 1;
    }
  }
  T find(T x) {
    if (par[x] == x) return x;
    return par[x] = find(par[x]);
  }
  bool unit(T x, T y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    if (sz[x] > sz[y]) {
      par[y] = x;
      sz[x] += sz[y];
    } else {
      par[x] = y;
      sz[y] += sz[x];
    }
    return true;
  }
  bool same(T x, T y) { return find(x) == find(y); }
};
struct edge {
  long long dm, cd, ct;
  edge(long long a, long long b, long long c) {
    dm = a;
    cd = b;
    ct = c;
  }
  bool operator<(const edge& right) const { return ct < right.ct; }
};
long long kk(vector<edge>& edges, long long n) {
  sort(edges.begin(), edges.end());
  long long cnt = 0, ans = 0;
  UF<long long> uf(n);
  for (auto it = edges.begin(); cnt < n - 1; it++) {
    edge e = *it;
    if (uf.same(e.dm, e.cd)) continue;
    uf.unit(e.dm, e.cd);
    ans += e.ct;
    cnt++;
  }
  return ans;
}
class EConnectingCities {
 public:
  void solve(istream& in, ostream& out) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    using P = pair<long long, int>;
    int n, d;
    in >> n >> d;
    vector<int> a(n);
    for (auto& i : a) in >> i;
    priority_queue<P, vector<P>, greater<P>> pq;
    vector<edge> es;
    for (int i = 0; i < (n); ++i) {
      while (!pq.empty()) {
        int j = pq.top().second;
        if (a[j] > a[i])
          pq.pop();
        else {
          es.emplace_back(j, i, (long long)a[i] + a[j] + d * (i - j));
          break;
        }
      }
      pq.emplace(a[i] - d * i, i);
    }
    while (!pq.empty()) pq.pop();
    for (int i = (n)-1; i >= 0; --i) {
      while (!pq.empty()) {
        int j = pq.top().second;
        if (a[j] > a[i])
          pq.pop();
        else {
          es.emplace_back(j, i, (long long)a[i] + a[j] + d * (j - i));
          break;
        }
      }
      pq.emplace(a[i] + d * i, i);
    }
    out << kk(es, n) << endl;
  }
};
int main() {
  EConnectingCities solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}
