#include <bits/stdc++.h>
using namespace std;
template <class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& p) {
  return o << "(" << p.first << "," << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& vc) {
  o << "{";
  for (const T& v : vc) o << v << ",";
  o << "}";
  return o;
}
using ll = long long;
template <class T>
using V = vector<T>;
template <class T>
using VV = vector<vector<T>>;
int N;
ll D;
ll A[200010];
using P = pair<int, int>;
using PP = pair<ll, P>;
struct UnionFind {
  vector<int> par;
  UnionFind(int N) {
    par.assign(N, 0);
    for (int i = 0; i < (int)(N); i++) par[i] = i;
  }
  int find(int x) {
    if (par[x] == x) return x;
    return par[x] = find(par[x]);
  }
  bool same(int x, int y) { return find(x) == find(y); }
  void unite(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return;
    par[y] = x;
  }
};
int main() {
  cin >> N >> D;
  for (int i = 0; i < (int)(N); i++) cin >> A[i];
  ll inf = 1e17;
  ll best = inf;
  int agi = -1;
  V<PP> es;
  for (int j = 1; j <= (int)(N - 1); j++) {
    ll cost = A[j - 1] - (j - 1) * D;
    if (cost < best) {
      best = cost;
      agi = j - 1;
    }
    es.push_back(PP(A[j] + j * D + best, P(agi, j)));
  }
  best = inf;
  int agj = -1;
  for (int i = N - 2; i >= 0; i--) {
    ll cost = (i + 1) * D + A[i + 1];
    if (cost < best) {
      best = cost;
      agj = i + 1;
    }
    es.push_back(PP(best + A[i] - i * D, P(i, agj)));
  }
  sort(es.begin(), es.end());
  UnionFind UF(N);
  ll ans = 0;
  for (PP e : es) {
    ll c = e.first;
    int x = e.second.first, y = e.second.second;
    if (!UF.same(x, y)) {
      UF.unite(x, y);
      ans += c;
    }
  }
  cout << ans << endl;
}
