#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;
int n, d;
vector<int> as0;
vector<pair<int, int>> as;
struct UnionFind {
  int n, cnt;
  vi par, rank, sz;
  UnionFind(int n) : n(n), cnt(n), par(n), rank(n), sz(n, 1) {
    iota(par.begin(), par.end(), 0);
  }
  int find(int x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return sz[find(x)]; }
  void unite(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) {
      par[x] = y;
      sz[y] += sz[x];
    } else {
      par[y] = x;
      sz[x] += sz[y];
      if (rank[x] == rank[y]) {
        rank[x]++;
      }
    }
    cnt--;
  }
};
void solve1() {
  vector<tuple<i64, int, int>> es;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      i64 c = 1ll * d * abs(as[i].second - as[j].second) + as[i].first +
              as[j].first;
      es.emplace_back(c, as[i].second, as[j].second);
    }
  }
  sort(es.begin(), es.end());
  UnionFind uf(n);
  i64 cost = 0;
  for (int i = 0;; i++) {
    if (!uf.same(get<1>(es[i]), get<2>(es[i]))) {
      uf.unite(get<1>(es[i]), get<2>(es[i]));
      cost += get<0>(es[i]);
    }
    if (uf.cnt == 1) break;
  }
  cout << cost << endl;
}
auto start = chrono::system_clock::now();
const int NAX = 31;
void solve2() {
  vector<tuple<i64, int, int>> es;
  for (int k = 1; k < NAX; k++) {
    for (int i = 0; i < n - k + 1; i++) {
      i64 c = 1ll * k * d + as0[i] + as0[i + k];
      es.emplace_back(c, i, i + k);
    }
  }
  for (int s = 1; s < NAX; s++) {
    for (int i = 0; i < n; i++) {
      int j = s - i;
      if (j <= i) break;
      i64 c = 1ll * d * abs(i - j) + as0[i] + as0[j];
      es.emplace_back(c, i, j);
    }
  }
  sort(es.begin(), es.end());
  UnionFind uf(n);
  i64 cost = 0;
  for (int i = 0;; i++) {
    if (!uf.same(get<1>(es[i]), get<2>(es[i]))) {
      uf.unite(get<1>(es[i]), get<2>(es[i]));
      cost += get<0>(es[i]);
    }
    if (uf.cnt == 1) break;
  }
  cout << cost << endl;
}
int main() {
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    as0.push_back(a);
    as.emplace_back(a, i);
  }
  sort(as.begin(), as.end());
  if (n <= 1e4) {
    solve1();
  } else {
    solve2();
  }
}
