#ifndef call_from_test
#include<bits/stdc++.h>
using namespace std;
#endif
//BEGIN CUT HERE
template<typename T>
struct VoronoiMST{
  int n;
  using E = pair<int, T>;
  using P = pair<T, int>;
  vector<vector<E> > G;
  VoronoiMST(vector<T> &x){
    n=x.size();
    G.assign(n<<1,vector<E>());
    for(int i=0;i<n;i++) G[i].emplace_back(n+i,x[i]);
  }
  void add_edge(int u,int v,T c){
    G[u+n].emplace_back(v+n,c);
    G[v+n].emplace_back(u+n,c);
  }
  vector<vector<E> > build(){
    priority_queue<P, vector<P>, greater<P> > pq;
    const T INF = numeric_limits<T>::max();
    vector<T> dist(n<<1,INF);
    vector<int> from(n<<1,-1);
    for(int i=0;i<n;i++){
      dist[i]=0;from[i]=i;
      pq.emplace(dist[i],i);
    }
    while(!pq.empty()){
      T d;
      int v;
      tie(d,v)=pq.top();pq.pop();
      if(dist[v]<d) continue;
      for(E e:G[v]){
        int u=e.first;
        T c=e.second;
        if(dist[u]<=dist[v]+c) continue;
        dist[u]=dist[v]+c;
        from[u]=from[v];
        pq.emplace(dist[u],u);
      }
    }
    vector<vector<E> > H(n);
    for(int v=0;v<(n<<1);v++){
      for(E e:G[v]){
        int u=e.first;
        T c=e.second;
        if(from[v]==from[u]) continue;
        int x=from[v],y=from[u];
        T z=dist[v]+dist[u]+c;
        H[x].emplace_back(y,z);
        H[y].emplace_back(x,z);
      }
    }
    return H;
  }
};
//END CUT HERE
#ifndef call_from_test

#define call_from_test
#ifndef call_from_test
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
#endif
//BEGIN CUT HERE
struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;
//END CUT HERE
#ifndef call_from_test
signed main(){
  return 0;
}
#endif

#ifndef call_from_test
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
#endif
//BEGIN CUT HERE
template<typename T>
struct Kruskal{

  struct edge{
    int from,to;
    T cost;
    int used;
    edge(int from,int to,T cost):
      from(from),to(to),cost(cost),used(0){}
    bool operator<(const edge& e) const{
      return cost<e.cost;
    }
  };

  int n;
  vector<int> r,p;
  vector<edge> es;

  Kruskal(){}
  Kruskal(int n):n(n),r(n,1),p(n){
    iota(p.begin(),p.end(),0);
  }

  int find(int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }

  bool same(int x,int y){
    return find(x)==find(y);
  }

  void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }

  void add_edge(int u,int v,T c){
    es.emplace_back(u,v,c);
  }

  T build(){
    sort(es.begin(),es.end());
    T res=0;
    for(auto &e:es){
      if(!same(e.from,e.to)){
        res+=e.cost;
        unite(e.from,e.to);
        e.used=1;
      }
    }
    return res;
  }
};
//END CUT HERE
#ifndef call_from_test
int main(){
  return 0;
}
#endif

#undef call_from_test

//INSERT ABOVE HERE
signed CF17FINAL_J(){
  using ll = long long;
  int n;
  cin>>n;
  vector<ll> x(n);
  for(int i=0;i<n;i++) cin>>x[i];
  VoronoiMST<ll> vo(x);
  for(int i=1;i<n;i++){
    int a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    vo.add_edge(a,b,c);
  }
  auto G=vo.build();
  Kruskal<ll> ks(n);
  for(int v=0;v<n;v++){
    for(auto e:G[v]){
      int u=e.first;
      ll c=e.second;
      if(v<u) ks.add_edge(v,u,c);
    }
  }
  cout<<ks.build()<<endl;
  return 0;
}
/*
  verified on 2019/01/16
  https://atcoder.jp/contests/cf17-final/tasks/cf17_final_j
*/

signed KEYENCE2019_E(){
  using ll = long long;

  int n,d;
  cin>>n>>d;
  vector<ll> a(n);
  for(int i=0;i<n;i++) cin>>a[i];
  VoronoiMST<ll> vo(a);
  for(int i=1;i<n;i++){
    vo.add_edge(i-1,i,d);
  }
  auto G=vo.build();
  Kruskal<ll> ks(n);
  for(int v=0;v<n;v++){
    for(auto e:G[v]){
      int u=e.first;
      ll c=e.second;
      if(v<u) ks.add_edge(v,u,c);
    }
  }
  cout<<ks.build()<<endl;
  return 0;
}
/*
  verified on 2019/01/16
  https://atcoder.jp/contests/keyence2019/tasks/keyence2019_e
*/

signed main(){
  //CF17FINAL_J();
  KEYENCE2019_E();
  return 0;
}
#endif

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using P = pair<ll, int>;
using E = pair<ll, pair<int, int> >;

const ll INF = 1LL << 60;

template <typename T>
struct SegmentTree {
    int n;
    vector<T> data;
    T INITIAL_VALUE;

    //使うときは、この2つを適宜変更する
    static T merge(T x, T y);
    void updateNode(int k, T x);

    SegmentTree(int size, T initial_value) {
        n = 1;
        INITIAL_VALUE = initial_value;
        while (n < size) n *= 2;
        data.resize(2 * n - 1, INITIAL_VALUE);
    }

    T getLeaf(int k) {
        return data[k + n - 1];
    }

    void update(int k, T x) {
        k += n - 1; //葉の節点
        updateNode(k, x);
        while (k > 0) {
            k = (k - 1) / 2;
            data[k] = merge(data[k * 2 + 1], data[k * 2 + 2]);
        }
    }

    //区間[a, b)に対するクエリに答える
    //k:節点番号, [l, r):節点に対応する区間
    T query(int a, int b) {
        T vl = INITIAL_VALUE, vr = INITIAL_VALUE;
        for (int l = a + n, r = b + n; l != r; l >>= 1, r >>= 1) {
            if (l & 1) vl = merge(vl, data[l++ - 1]);
            if (r & 1) vr = merge(vr, data[--r - 1]);
        }
        return merge(vl, vr);
    }
};

//使うときは以下2つを変更
template <typename T>
T SegmentTree<T>::merge(T x, T y) {
    return min(x, y);
}

template <typename T>
void SegmentTree<T>::updateNode(int k, T x) {
    data[k] = x;
}

int n;
ll D;
ll a[200005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> D;
    vector< vector<int> > vs(n);
    vector<int> root(n), idxs(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        vs[i].push_back(i);
        root[i] = i;
        idxs[i] = i;
    }
    
    SegmentTree<P> st1(n, P(INF, -1)), st2(n, P(INF, -1));
    for (int i = 0; i < n; i++) {
        st1.update(i, P(a[i] - D * i, i));
        st2.update(i, P(a[i] + D * i, i));
    }

    int max_size = 1;
    ll ans = 0;

    while (max_size < n) {
        vector< E > es;
        for (int i : idxs) {
            if (vs[i].empty()) continue;
            for (int j : vs[i]) {
                st1.update(j, P(INF, -1));
                st2.update(j, P(INF, -1));
            }

            P p(INF, -1);
            for (int j : vs[i]) {
                P q1 = st1.query(0, j);
                q1.first += a[j] + D * j;
                P q2 = st2.query(j + 1, n);
                q2.first += a[j] - D * j;
                P p2 = min(q1, q2);
                if (p > p2) p = p2;
            }

            for (int j : vs[i]) {
                st1.update(j, P(a[j] - D * j, j));
                st2.update(j, P(a[j] + D * j, j));
            }

            if (p.second == -1) continue;
            es.emplace_back(p.first, make_pair(i, p.second));
        }

        for (E& e : es) {
            int ri = root[e.second.first];
            int r = root[e.second.second];
            if (ri == r) continue;

            ans += e.first;
            if (vs[ri].size() >= vs[r].size()) {
                for (int j : vs[r]) {
                    vs[ri].push_back(j);
                    root[j] = ri;
                }
                vs[r].clear();
                max_size = max(max_size, (int)vs[ri].size());
            } else {
                for (int j : vs[ri]) {
                    vs[r].push_back(j);
                    root[j] = r;
                }
                vs[ri].clear();
                max_size = max(max_size, (int)vs[r].size());
            }
        }
    }
    cout << ans << endl;
    return 0;
}