#include <bits/stdc++.h>
using namespace std;

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

class union_find {
private:
    vector<int> parent, rank, gs;
    int size;

public:
    int count_group;
    union_find() = default;
    union_find(int n) { init(n); }

    void init(int n) {
        size = n;
        count_group = n;
        parent.resize(size);
        rank.assign(size, 0);
        gs.assign(size, 1);
        for (int i = 0; i < size; ++i) parent[i] = i;
    }

    int find(int x) {
        if (parent[x] == x)
            return x;
        else
            return parent[x] = find(parent[x]);
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (rank[x] < rank[y]) {
            parent[x] = y;
            gs[y] += gs[x];
        } else {
            parent[y] = x;
            gs[x] += gs[y];
            if (rank[x] == rank[y]) ++rank[x];
        }
        --count_group;
    }

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

    int group_size(int x) {
        return gs[find(x)];
    };
};

void solve(){
    i64 N,D;
    cin >> N >> D;

    vector<i64> A(N);
    set<pair<i64,i64>> ai;
    rep(i,0,N){
        cin >> A[i];
    }

    using pii=pair<i64,i64>;
    vector<vector<pii>> graph(N+N);
    rep(i,0,N){
        graph[i].emplace_back(make_pair(i+N,A[i]));
        graph[i+N].emplace_back(make_pair(i,A[i]));
        if(i>0) graph[i+N].emplace_back(make_pair(i+N-1,D));
        if(i+1<N) graph[i+N].emplace_back(make_pair(i+N+1,D));
    }

    using tup=tuple<i64,i64,i64>;
    priority_queue<tup,vector<tup>,greater<tup>> que;
    vector<i64> from(N+N,-1),dist(N+N,inf64);
    vector<tup> es;

    rep(i,0,N){
        que.push(make_tuple(0,i,i));
        dist[i]=0;
    }

    while(!que.empty()){
        auto t=que.top();
        que.pop();

        i64 d,u,f;
        tie(d,u,f)=t;

        if(from[u]!=-1) continue;
        from[u]=f;
        dist[u]=d;

        for(auto e:graph[u]){
            i64 v,c;
            tie(v,c)=e;
            if(from[v]!=-1){
                if(from[u]!=from[v]) es.emplace_back(make_tuple(dist[u]+dist[v]+c,from[u],from[v]));
            }else{
                if(dist[v]<=dist[u]+c) continue;
                dist[v]=dist[u]+c;
                que.push(make_tuple(dist[v],v,f));
            }
        }
    }

    sort(begin(es),end(es));

    union_find uf(N);
    i64 ans=0;
    for(auto e:es){
        i64 d,u,v;
        tie(d,u,v)=e;
        if(uf.is_same_group(u,v)) continue;
        uf.unite(u,v);
        ans+=d;
    }

    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 55276