#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cassert>
#include<ctime>
using namespace std;

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 1000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define P_TYPE int
typedef pair<P_TYPE, P_TYPE> P;
typedef pair<P, P_TYPE> PI;
typedef pair<P_TYPE, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

#define N 200006
#define N0 262145

int n;
ll a[N];
ll d;

struct Val {
  ll value; int i;

  Val() : value(INFLL), i(-1) {}
  Val(ll value, int i) : value(value), i(i) {}

};

bool operator<(const Val &a, const Val &b) {
  return a.value < b.value;
}

class SegmentTree {
  Val inf = Val();
  Val *ldata;
  Val *rdata;
  int *p, *q;
  int n0;

  void __update(Val *data, int k, ll x) {
    Val v = Val(x, k);
    k += n0-1;
    data[k] = v;
    while(k) {
      k = (k - 1) >> 1;
      data[k] = min(data[2*k+1], data[2*k+2]);
    }
  }

public:
  SegmentTree(int n) {
    n0 = 1;
    while(n0 < n) n0 <<= 1;
    ldata = new Val[2*n0];
    rdata = new Val[2*n0];


    p = new int[n0+1];
    q = new int[n0+1];
    int z;
    rep(x, n0+1) {
      int y = n0 + x;
      z = (y / (y & -y)) >> 1;
      p[x] = z ? 2*z-1 : 0;
      z = (y / (y & -y));
      q[n0-x] = z-1;
    }
  }

  void lupdate(int k, ll x) {
    __update(ldata, k, x);
  }

  void rupdate(int k, ll x) {
    __update(rdata, k, x);
  }

  Val lquery(int r) {
    Val v = inf;
    while(r) {
      v = min(v, ldata[p[r]]);
      r -= r & -r;
    }
    return v;
  }

  Val rquery(int l) {
    Val v = inf;
    int r = n0 - l;
    while(r) {
      v = min(v, rdata[q[r]]);
      r -= r & -r;
    }
    return v;
  }
};

int parent[N];
int root(int x) {
  if(x == parent[x]) {
    return x;
  }
  return parent[x] = root(parent[x]);
}

bool unite(int x, int y) {
  int px = root(x), py = root(y);
  if(px == py) return false;

  if(px < py) {
    parent[py] = px;
  } else {
    parent[px] = py;
  }
  return true;
};

int ids[N];
bool cmp(int i, int j) {
  return a[i] < a[j];
}

using Edge = pair<ll, P>;
vector<Edge> es;

int main() {
  scanf("%d %lld", &n, &d);
  rep(i, n) scanf("%lld", a+i), ids[i] = i;

  sort(ids, ids+n, cmp);

  SegmentTree st(n);
  rep(i, n) {
    int j = ids[i];

    Val p = st.lquery(j);
    if(p.i != -1) {
      ll c = p.value - d*(n-1-j);
      es.push_back(Edge(c + a[j], P(p.i, j)));
    }
    Val q = st.rquery(j+1);
    if(q.i != -1) {
      ll c = q.value - d*j;
      es.push_back(Edge(c + a[j], P(j, q.i)));
    }
    st.lupdate(j, d*(n-1-j) + a[j]);
    st.rupdate(j, d*j + a[j]);
  }

  rep(i, n) parent[i] = i;

  sort(ALL(es));
  ll ans = 0;
  repe(&e, es) {
    ll c = e.first; int i = e.second.first, j = e.second.second;
    if(unite(i, j)) {
      ans += c;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 31212