#include <bits/stdc++.h>
using namespace std;
int N;
signed long long D;
signed long long A[202020];
pair<int, int> P[202020];
template <class V, int NV>
class SegTree_Pair {
 public:
  vector<pair<V, int>> val;
  static V const def = 1LL << 60;
  pair<V, int> comp(pair<V, int> l, pair<V, int> r) { return min(l, r); }
  SegTree_Pair() {
    val.resize(NV * 2);
    int i;
    for (i = 0; i < (NV); i++) val[i + NV] = make_pair(def, i);
    for (i = NV - 1; i >= 1; i--) val[i] = comp(val[2 * i], val[2 * i + 1]);
  };
  pair<V, int> getval(int x, int y, int l = 0, int r = NV, int k = 1) {
    if (r <= x || y <= l) return make_pair(def, NV);
    if (x <= l && r <= y) return val[k];
    return comp(getval(x, y, l, (l + r) / 2, k * 2),
                getval(x, y, (l + r) / 2, r, k * 2 + 1));
  }
  void update(int entry, V v) {
    entry += NV;
    val[entry] = make_pair(v, entry - NV);
    while (entry > 1)
      entry >>= 1, val[entry] = comp(val[entry * 2], val[entry * 2 + 1]);
  }
};
SegTree_Pair<signed long long, 1 << 22> LT, RT;
signed long long mi[202020];
int id[202020];
template <int um>
class UF {
 public:
  vector<int> par, rank, cnt;
  UF() {
    par = rank = vector<int>(um, 0);
    cnt = vector<int>(um, 1);
    for (int i = 0; i < um; i++) par[i] = i;
  }
  void reinit() {
    int i;
    for (i = 0; i < (um); i++) rank[i] = 0, cnt[i] = 1, par[i] = i;
  }
  int operator[](int x) {
    return (par[x] == x) ? (x) : (par[x] = operator[](par[x]));
  }
  int count(int x) { return cnt[operator[](x)]; }
  int operator()(int x, int y) {
    if ((x = operator[](x)) == (y = operator[](y))) return x;
    cnt[y] = cnt[x] = cnt[x] + cnt[y];
    if (rank[x] > rank[y]) return par[x] = y;
    rank[x] += rank[x] == rank[y];
    return par[y] = x;
  }
};
UF<500000> uf;
set<pair<int, int>> S;
void update(int cur) {
  S.erase({mi[cur], cur});
  auto L = LT.getval(0, cur);
  auto R = RT.getval(cur + 1, N);
  L.first -= (N - 1 - cur) * D;
  R.first -= cur * D;
  L.first += A[cur];
  R.first += A[cur];
  if (L.first > R.first) swap(L, R);
  mi[cur] = L.first;
  id[cur] = L.second;
  S.insert({mi[cur], cur});
}
void solve() {
  int i, j, k, l, r, x, y;
  string s;
  cin >> N >> D;
  for (i = 0; i < (N); i++) {
    cin >> A[i];
    mi[i] = 1LL << 60;
    if (i == 0) {
      LT.update(0, 1LL << 60);
      RT.update(0, 1LL << 60);
    } else {
      LT.update(i, A[i] + (N - 1 - i) * D);
      RT.update(i, A[i] + i * D);
    }
  }
  signed long long ret = 0;
  update(0);
  S.insert({mi[0], 0});
  while (uf.count(0) < N) {
    signed long long v = S.begin()->first;
    int cur = S.begin()->second;
    S.erase(S.begin());
    if (uf[cur] == uf[id[cur]]) {
      update(cur);
      continue;
    }
    ret += mi[cur];
    LT.update(id[cur], 1LL << 60);
    RT.update(id[cur], 1LL << 60);
    uf(cur, id[cur]);
    update(id[cur]);
    update(cur);
  }
  cout << ret << endl;
}
int main(int argc, char** argv) {
  string s;
  int i;
  if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);
  for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s += '\n';
  for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);
  cout.tie(0);
  solve();
  return 0;
}
