#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1;
const int BIT = 29;
const int mod = 1e9 + 7;
int seg[4 * N];
int n, d, par[N];
long long a[N];
vector<int> sz[N];
void update(int node, int start, int end, int idx){
    if(start > end || idx < start || end < idx) return;
    if(start == end){
        seg[node][0] = idx;
        seg[node][1] = idx;
        return;
    }
    int mid = (start + end) >> 1;
    update(node << 1, start, mid, idx);
    update(node << 1 | 1, mid + 1, end, idx);
    if(a[seg[node << 1][typ]][typ] <= a[seg[node << 1 | 1][typ]][typ]){
        seg[node][typ] = seg[node << 1][typ];
    }else{
        seg[node][typ] = seg[node << 1 | 1][typ];
    }
}
int query(int node, int start, int end, int l, int r, int typ){
    if(start > end || r < start || end < l) return 0;
    if(l <= start && end <= r){
        return seg[node][typ];
    }
    int mid = (start + end) >> 1;
    int q1 = query(node << 1, start, mid, l, r, typ);
    int q2 = query(node << 1 | 1, mid + 1, end, l, r, typ);
    if(a[q1][typ] <= a[q2][typ]){
        return q1;
    }else{
        return q2;
    }
}
int main(){
    set<pair<int, int> > s;
    long long ans = 0;
    scanf("%d %d", &n, &d);
    a[0][0] = a[0][1] = 1e16;
    for(int i = 1; i <= n; i++){
        int val;
        scanf("%d", &val);
        a[i][0] = val - 1LL * i * d;
        a[i][1] = val + 1LL * i * d;
    }
    for(int i = 1; i <= n; i++){
        par[i] = i;
        sz[i].push_back(i);
        update(1, 1, n, i);
        s.insert({sz[i].size(), i});
    }
    int edge = n - 1;
    while(edge--){
        int c = (s.begin()) -> second;
        for(int i : sz[c]){
            update(1, 1, n, 0);
        }
        long long mini = 2e9;
        int idx;
        s.erase(s.find({sz[c].size(), c}));
        s.erase(s.find({sz[p].size(), p}));
        for(int i : sz[c]){
            int q1 = query(1, 1, n, 1, i - 1, 0);
            int q2 = query(1, 1, n, i + 1, n, 1);
            long long res = a[i][1] + a[q1][0];
            if(res < mini){
                mini = res;
                idx = q1;
            } 
            res = a[i][0] + a[q2][1];
            if(res < mini){
                mini = res;
                idx = q2;
            } 
        }
        ans += mini;
        int p = par[idx];
        while(sz[c].size()){
            int i = sz[c].back();
            update(1, 1, n, i);
            sz[p].push_back(i);
            par[i] = p;
            sz[c].pop_back();
        }
        s.insert({sz[p].size(), p});
    }
    printf("%lld\n", ans);
    return 0;
}