#include <bits/stdc++.h>
using namespace std;
template <typename T>
T id(T b) {
  return b;
};
template <class It>
bool all(It f, It l) {
  return std::all_of(f, l, id<bool>);
}
template <class It>
bool any(It f, It l) {
  return std::any_of(f, l, id<bool>);
}
struct union_find {
  vector<int> parent, rank, cnt;
  int n;
  union_find(int n) : n(n) {
    parent = vector<int>(n);
    rank = vector<int>(n, 0);
    cnt = vector<int>(n, 1);
    for (int i = 0; i < n; i++) parent[i] = i;
  }
  int find(int a) {
    if (parent[a] == a) return a;
    return parent[a] = find(parent[a]);
  }
  void unite(int a, int b) {
    a = find(a);
    b = find(b);
    if (a == b) return;
    if (rank[a] < rank[b]) {
      parent[a] = b;
      cnt[b] += cnt[a];
    } else {
      parent[b] = a;
      cnt[a] = cnt[b];
      if (rank[a] == rank[b]) rank[a]++;
    }
  }
  int count(int a) { return cnt[find(a)]; }
  bool same(int a, int b) { return find(a) == find(b); }
};
const int MAX_N = 200000;
int n;
int64_t d, a[MAX_N];
int main() {
  cin >> n >> d;
  for (int i = 0; i < n; i++) cin >> a[i];
  int64_t m = a[0] - d;
  int idx = 0;
  vector<tuple<int64_t, int, int> > es;
  for (int i = 1; i < n; i++) {
    es.push_back(make_tuple(a[i] + (i + 1) * d + m, idx, i));
    int64_t v = a[i] - (i + 1) * d;
    if (m > v) {
      m = v;
      idx = i;
    }
  }
  m = a[n - 1] + n * d, idx = n - 1;
  for (int i = n - 2; i >= 0; i--) {
    es.push_back(make_tuple(a[i] - (i + 1) * d + m, idx, i));
    int64_t v = a[i] + (i + 1) * d;
    if (m > v) {
      m = v;
      idx = i;
    }
  }
  sort(es.begin(), es.end());
  union_find uf(n);
  int64_t res = 0;
  for (auto e : es) {
    int64_t cost;
    int u, v;
    tie(cost, u, v) = e;
    if (uf.same(u, v)) continue;
    res += cost;
    uf.unite(u, v);
    if (uf.count(0) == n) break;
  }
  cout << res << endl;
  return 0;
}
