#include <bits/stdc++.h>
using namespace std;
long long inf = 1e16;
long long Nmax = 2 * 100000 + 3;
vector<long long> par(Nmax), ranki(Nmax, 0);
struct edge {
  long long from;
  long long to;
  long long cost;
  bool operator<(const edge& rhs) const { return cost > rhs.cost; }
};
void init() {
  for (long long i = 0; i < Nmax; i++) {
    par.at(i) = i;
  }
}
long long find(long long x) {
  if (par.at(x) == x) {
    return x;
  } else {
    par.at(x) = find(par.at(x));
    return par.at(x);
  }
}
void unite(long long x, long long y) {
  long long px, py;
  px = find(x);
  py = find(y);
  if (px == py) {
    return;
  }
  if (ranki.at(px) < ranki.at(py)) {
    par.at(px) = py;
  } else {
    par.at(py) = px;
    if (ranki.at(px) == ranki.at(py)) {
      ranki.at(px) += 1;
    }
  }
}
bool connect(long long x, long long y) { return find(x) == find(y); }
vector<long long> lbit(Nmax + 1, 1e16);
long long search(long long i) {
  long long s = 1e16;
  while (i > 0) {
    s = min(s, lbit.at(i));
    i -= i & -i;
  }
  return s;
}
void add(long long i, long long x) {
  while (i <= Nmax) {
    lbit.at(i) = min(x, lbit.at(i));
    i += i & -i;
  }
}
int main() {
  init();
  long long N, D;
  cin >> N >> D;
  vector<long long> A(N);
  for (long long i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  vector<edge> table;
  map<long long, long long> dl;
  for (long long i = 0; i < N; i++) {
    add(i + 1, A.at(i) + (N - 1 - i) * D);
    dl[A.at(i) + (N - 1 - i) * D] = i;
    if (i > 0) {
      long long s;
      s = dl[search(i)];
      table.push_back({i, s, A.at(i) + A.at(s) + D * (abs(i - s))});
    }
  }
  for (long long i = 0; i < Nmax + 1; i++) {
    lbit.at(i) = inf;
  }
  map<long long, long long> dr;
  for (long long i = N - 1; i > -1; i--) {
    add(N - i, A.at(i) + i * D);
    dr[A.at(i) + i * D] = i;
    if (i < N - 1) {
      long long s;
      s = dr[search(N - 1 - i)];
      table.push_back({i, s, A.at(i) + A.at(s) + D * (abs(i - s))});
    }
  }
  sort(table.begin(), table.end());
  reverse(table.begin(), table.end());
  long long k = table.size();
  long long ans = 0;
  for (long long i = 0; i < k; i++) {
    long long x = table.at(i).from;
    long long y = table.at(i).to;
    long long co = table.at(i).cost;
    if (!(connect(x, y))) {
      ans += co;
      unite(x, y);
    }
  }
  cout << (ans) << endl;
  ;
}
