#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
using Value = pair<long long int, int>;
const Value ini = (make_pair(1e18, 0));
struct segtree {
  int N;
  vector<Value> dat;
  segtree() {}
  segtree(int n) : dat(2 * (1 << 20)) {
    N = 1;
    while (N < n) N *= 2;
    for (int i = 0; i < 2 * N - 1; i++) {
      dat[i] = ini;
    }
  }
  Value connect(const Value& l, const Value& r) { return min(l, r); }
  void update(int k, Value a) {
    k += N - 1;
    dat[k] = a;
    while (k > 0) {
      k = (k - 1) / 2;
      const Value al(dat[k * 2 + 1]);
      const Value ar(dat[k * 2 + 2]);
      dat[k] = connect(al, ar);
    }
  }
  Value query(int a, int b) { return query(a, b, 0, 0, N); }
  Value query(int a, int b, int k, int l, int r) {
    if (r <= a or b <= l) return ini;
    if (a <= l and r <= b) return dat[k];
    const int m = (l + r) / 2;
    const Value al(query(a, b, k * 2 + 1, l, m));
    const Value ar(query(a, b, k * 2 + 2, m, r));
    return connect(al, ar);
  }
};
struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) {}
  bool unionSet(int x, int y) {
    x = root(x);
    y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }
  int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
  int size(int x) { return -data[root(x)]; }
};
int main() {
  int N;
  cin >> N;
  long long int D;
  cin >> D;
  vector<long long int> as(N);
  for (int i = 0; i < N; ++i) {
    cin >> as[i];
  }
  segtree l_seg(N);
  segtree r_seg(N);
  for (int i = 0; i < N; ++i) {
    l_seg.update(i, make_pair(i * D + as[i], i));
    r_seg.update(i, make_pair((N - 1 - i) * D + as[i], i));
  }
  vector<pair<long long int, pair<int, int>>> vs;
  for (int i = 0; i < N; ++i) {
    if (i) {
      auto lp = r_seg.query(0, i);
      long long int l_cost = as[i] + as[lp.second] + (i - lp.second) * D;
      vs.push_back(make_pair(l_cost, make_pair(lp.second, i)));
    }
    if (i != N - 1) {
      auto rp = l_seg.query(i + 1, N);
      long long int r_cost = as[i] + as[rp.second] + (rp.second - i) * D;
      vs.push_back(make_pair(r_cost, make_pair(rp.second, i)));
    }
  }
  long long int answer = 0;
  sort(vs.begin(), vs.end());
  UnionFind uf(N);
  for (auto v : vs) {
    int a = v.second.first;
    int b = v.second.second;
    if (uf.root(a) == uf.root(b)) {
    } else {
      answer += v.first;
      uf.unionSet(a, b);
    }
  }
  assert(uf.size(0) == N);
  cout << answer << endl;
  return 0;
}
