#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define REP rep
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
const ll MOD=1e9+7;

#define rall(X) (X).rbegin(),(X).rend()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}

const LL INF = 1LL << 61;

int N;
int size;
LL D;
LL A[214514];
pll seg1[1 << 23];
pll seg2[1 << 23];

template<class M>
struct MonoidSegTree {
  int n;
  int size;
  vector<M> seg;

  MonoidSegTree(const vector<M> A) {
    n = A.size();

    size = 1;
    while (size < n) size *= 2;
    
    seg.resize(size);
    seg.insert(seg.end(), A.begin(), A.end());
    seg.resize(size*2);
    rrep(i, size) seg[i] = seg[i*2] * seg[i*2+1];
  }

  void Update(int k, const M v) {
    k += size;
    seg[k] = v;
    while (k > 1) {
      k /= 2;
      seg[k] = seg[k*2] * seg[k*2+1];
    }
  }

  M Get(int l, int r) {
    M retl = M(); // the identity element
    M retr = M();

    l += size;
    r += size;
    for (; l < r; l>>=1, r>>=1) {
      if (r & 1) retr = seg[--r] * retr;
      if (l & 1) retl = retl * seg[l++];
    }
    return retl * retr;
  }

  M At(int k) {
    return seg[k+size];
  }
};

struct Monoid {
  pll p;
  Monoid() {
    p = pll(INF, INF);
  }
  Monoid(const Monoid &m) : p(m.p) {}
  Monoid(pll q) : p(q) {}
  Monoid operator*(Monoid m) {
    return min(p, m.p);
  }
};

using Seg = MonoidSegTree<Monoid>;

vector<int> belong;
vector<vector<int>> grps;

signed main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);

  cin >> N >> D;
  size = 1;
  while (size < N) size <<= 1;

  belong.resize(N);
  grps.resize(N);
  vector<Monoid> v1, v2;
  rep(i, N) {
    cin >> A[i];
    v1.eb(pll(A[i]+i*D, i));
    v2.eb(pll(A[i]+(N-i)*D, i));
    grps[i].resize(1, i);
    belong[i] = i;
  }

  Seg seg1(v1);
  Seg seg2(v2);

  LL ans = 0;
  using Edge = pair<LL, pii>;
  vector<Edge> mines;
  vector<pll> restore1, restore2;
  rep(_, 18) {
    mines.clear();
    for (auto &grp : grps) {
      restore1.clear();
      restore2.clear();
      for (int v : grp) {
        restore1.eb(seg1.seg[size+v].p);
        seg1.Update(v, pll(INF, INF));
        restore2.eb(seg2.seg[size+v].p);
        seg2.Update(v, pll(INF, INF));
      }

      Edge mine(INF, pii(-1, -1));
      for (int v : grp) {
        pll p = seg1.Get(v+1, N).p;
      //cout << p.X << ", " << p.Y << endl;
        if (p.X != INF) {
          MN(mine, Edge(A[v]+A[p.Y]+abs(v-p.Y)*D, pii(v, p.Y)));
        }

        pll q = seg2.Get(0, v).p;
        //cout << q.X << ", " << q.Y << endl;
        if (q.X != INF) {
          MN(mine, Edge(A[v]+A[q.Y]+abs(v-q.Y)*D, pii(v, q.Y)));
        }
      }

      for (auto &p : restore1) {
        seg1.Update(p.Y, p);
      }

      for (auto &p : restore2) {
        seg2.Update(p.Y, p);
      }

      mines.eb(mine);
    }

    bool all = false;
    for (auto &e : mines) {
      LL c = e.X;
      int u, v;
      tie(u, v) = e.Y;
      if (belong[u] == belong[v]) continue;

      ans += c;
      u = belong[u];
      v = belong[v];
      if (grps[u].size() > grps[v].size()) swap(u, v);
      //grps[v].reserve(grps[v].size()+grps[u].size());
      for (int w : grps[u]) {
        belong[w] = v;
        grps[v].eb(w);
      }
      grps[u].clear();
      if (grps[v].size() == N) all = true;
    }

    if (all) break;
  }
  cout << ans << "\n";
}


Measured memory_bytes: 55332