#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e17;
struct segtree {
  int n = 1;
  vector<pair<long long, long long> > node;
  void init(int N) {
    node.clear();
    while (N > n) n *= 2;
    node.resize(n * 2, {inf, inf});
  }
  void update(int k, long long x, int a) {
    k += n - 1;
    node[k] = {x, a};
    while (k > 0) {
      k = (k - 1) / 2;
      int l = k * 2 + 1;
      int r = k * 2 + 2;
      if (node[l].first < node[r].first)
        node[k] = node[l];
      else
        node[k] = node[r];
    }
  }
  pair<long long, long long> mini(int a, int b, int k = 0, int l = 0,
                                  int r = -1) {
    if (r < 0) r = n;
    if (b <= l || r <= a) return {inf, inf};
    if (a <= l && r <= b) return node[k];
    pair<long long, long long> ln = mini(a, b, k * 2 + 1, l, (l + r) / 2);
    pair<long long, long long> rn = mini(a, b, k * 2 + 2, (l + r) / 2, r);
    if (ln.first < rn.first)
      return ln;
    else
      return rn;
  }
};
struct edge {
  long long to;
  long long cost;
  bool operator<(const edge &e1) const { return e1.cost < cost; }
};
int N;
int idx[100010];
long long D;
bool used[100010];
vector<long long> A;
vector<pair<long long, long long> > B;
vector<edge> G[100010];
long long prim() {
  priority_queue<edge> pq;
  pq.push(edge{0, 0});
  long long total = 0;
  while (!pq.empty()) {
    edge e = pq.top();
    pq.pop();
    if (!used[e.to]) {
      used[e.to] = true;
      total += e.cost;
      for (auto u : G[e.to]) {
        if (!used[u.to]) pq.push(u);
      }
    }
  }
  return total;
}
void build() {
  segtree seg;
  seg.init(N);
  for (int i = 0; i < N; i++) {
    seg.update(idx[i], A[i] + D * (N - i - 1), idx[i]);
    if (i != 0) {
      pair<long long, long long> lp = seg.mini(0, idx[i]);
      if (lp.first == inf) continue;
      lp.first -= D * (N - i - 1) - A[i];
      G[B[lp.second].second].push_back(edge{i, lp.first});
      G[i].push_back(edge{B[lp.second].second, lp.first});
    }
  }
  seg.init(N);
  for (int i = N - 1; i >= 0; i--) {
    seg.update(idx[i], A[i] + D * i, idx[i]);
    if (i != N - 1) {
      pair<long long, long long> lp = seg.mini(0, idx[i]);
      if (lp.first == inf) continue;
      lp.first -= D * i - A[i];
      G[B[lp.second].second].push_back(edge{i, lp.first});
      G[i].push_back(edge{B[lp.second].second, lp.first});
    }
  }
}
void init() {
  cin >> N >> D;
  for (int i = 0; i < N; i++) {
    pair<long long, long long> tmp;
    cin >> tmp.first;
    tmp.second = i;
    A.push_back(tmp.first);
    B.push_back(tmp);
  }
  sort(B.begin(), B.end());
  for (int i = 0; i < N; i++) {
    idx[B[i].second] = i;
  }
}
int main() {
  init();
  build();
  cout << prim() << endl;
  return 0;
}
