#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

//インデックスは正の数のみ
__int128_t th=1000000000000000000;
inline __int128_t encode(ll a, ll b){
  __int128_t A = a, B = b;
  return th*th+A*th+B;
}
pair<ll, ll> decode(__int128_t a){
  ll B = a%th;
  a -= B;
  return make_pair((a-th*th)/th, B);
}

struct segtree{
  __int128_t M=1, INIT;
  __int128_t INF = encode(th, th);
  vector<__int128_t> dat;
  segtree(ll N, ll num){
    INIT = num;
    while(M<N) M*=2;
    dat.resize(M*2-1, encode(num, 0));
  }
  void update(ll x, ll k, ll l=0, ll r=-1){
    if(r==-1) r = M;
    k+=M-1;
    dat[k] = encode(x, k-(M-1));
    while(k>0) {
      k = (k-1)/2;
      dat[k] = min(dat[k*2+1], dat[k*2+2]);
    }
  }
  __int128_t query(ll a, ll b=-1, ll k=0, ll l=0, ll r=-1){
    if(r==-1) r = M;
    if(b==-1) b = M;
    if(r<=a || b<=l) return INF;
    if(a<=l && r<=b) return dat[k];
    __int128_t A = query(a, b, k*2+1, l, (l+r)/2);
    __int128_t B = query(a, b, k*2+2, (l+r)/2, r);
    return min(A, B);
  }
};

ll INF = 1000000000000000000;
segtree l(200001, INF), r(200001, INF);

typedef tuple<ll, ll, ll> p;//cost src dst
struct UF{
  std::vector<int> par, dep, sz;
  UF(int n){
    par.resize(n+1), dep.resize(n+1), sz.resize(n+1);
    init(n);
  }
  void init(int nu) {
    for(int iu=0;iu<=nu;iu++){
      par[iu] = iu;
      dep[iu] = 0;
      sz[iu] = 1;
    }
  }
  int find(int xu){
    if(par[xu] == xu) return xu;
    return par[xu] = find(par[xu]);
  }
  void unite(int xu, int yu){
    xu=find(xu);
    yu=find(yu);
    if(xu == yu) return;
    if(dep[xu] < dep[yu]){
      sz[yu] += sz[xu];
      par[xu] = yu;
    }else{
      par[yu] = xu;
      sz[xu] += sz[yu];
      if(dep[xu] == dep[yu]) dep[xu]++;
    }
  }
  bool same(int xu, int yu){ return find(xu) == find(yu);}
  int get_size(int x){return sz[find(x)];}
};
int main(int argc, char const *argv[]) {
  ll n, D;scanf("%lld %lld", &n, &D);
  vector<ll> A(n+1, 0);
  for(int i=1;i<=n;i++) scanf("%lld",&A[i]);
  if(n==1){
    std::cout << 0 << '\n';
    return 0;
  }
  ll ans = 0;
  vvl dat = VV(n, 2, -1, ll);
  for(int i=0;i<n;i++) dat[i] = vll{A[i+1], i+1};
  sort(all(dat));

  vector<p> edges;

  for(ll i=0;i<n;i++){
    ll idx = dat[i][1];
    pair<ll, ll> L = decode(l.query(1, idx));
    pair<ll, ll> R = decode(r.query(idx+1, n+1));
    if(L.first<INF) edges.push_back(p(A[idx]+D*idx+L.first, idx, L.second));
    if(R.first<INF) edges.push_back(p(A[idx]-D*idx+R.first, idx, R.second));
    l.update(A[idx]-D*idx, idx);
    r.update(A[idx]+D*idx, idx);
  }
  sort(all(edges));
  UF uf(n+1);
  for(auto e:edges){
    ll cost = get<0>(e);
    ll src = get<1>(e);
    ll dst = get<2>(e);
    //std::cout << src << " " << dst << " " << cost << '\n';
    if(!uf.same(src, dst)){
      ans += cost;
      uf.unite(src, dst);
    }
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 43628