#include <cstdio>
#include <cstdlib>
#include <vector>
#include <functional>
#include <algorithm>

using namespace std;

template <class T>
class segment_tree {
    public:
    segment_tree(int n, function<T(const T&, const T&)> func, const T& init = T());
    ~segment_tree();
    void add(int x, const T& value);
    void update(int x, const T& value);
    T get(int x, int y) const; // [x, y)
    
    private:
    int size;
    function<T(const T&, const T&)> func;
    T init;
    T* data;
};

template <class T> segment_tree<T>::segment_tree(int n, function<T(const T&, const T&)> func, const T& init) : size(1 << (32 - __builtin_clz(n - 1))), func(func), init(init) {
    data = (T *)malloc(sizeof(T) * size * 2);
    for (int i = 0; i < size * 2; i++) data[i] = init;
}

template <class T> segment_tree<T>::~segment_tree() {
    free(data);
}

template <class T> void segment_tree<T>::add(int x, const T& value) {
    update(x, data[x + size] + value);
}

template <class T> void segment_tree<T>::update(int x, const T& value) {
    data[x += size] = value;
    while (x >>= 1) data[x] = func(data[x * 2], data[x * 2 + 1]);
}

template <class T> T segment_tree<T>::get(int x, int y) const {
    T vl = init, vr = init;
    for (x += size, y += size; x < y; x >>= 1, y >>= 1) {
        if (x & 1) vl = func(vl, data[x++]);
        if (y & 1) vr = func(data[--y], vr);
    }
    return func(vl, vr);
}

int a[200000];
int par[200000];

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

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    
    if (x == y) return;
    
    par[x] = y;
}

int main() {
    int n, d, i, j, k;
    long long ans = 0;
    pair <long long, int> inf = make_pair(1e18, 1e9);
    
    scanf("%d %d", &n, &d);
    
    for (i = 0; i < n; i++) scanf("%d", &a[i]);
    
    for (i = 0; i < n; i++) par[i] = i;
    
    while (1) {
        vector <pair<int, int>> v;
        vector <pair<long long, pair<int, int>>> w;
        
        for (i = 0; i < n; i++) v.push_back(make_pair(find(i), i));
        sort(v.begin(), v.end());
        
        if (v[0].first == v.back().first) break;
        
        segment_tree <pair <long long, int>> s1(n, [](const pair <long long, int> &p1, const pair <long long, int> &p2) {return min(p1, p2);}, inf);
        segment_tree <pair <long long, int>> s2(n, [](const pair <long long, int> &p1, const pair <long long, int> &p2) {return min(p1, p2);}, inf);
        
        for (i = 0; i < n; i++) {
            s1.update(i, make_pair(a[i] - (long long)i * d, i));
            s2.update(i, make_pair(a[i] + (long long)i * d, i));
        }
        
        for (i = 0; i < n; ) {
            int x = -1;
            long long y = 1e18;
            
            for (j = i; j < n; j++) {
                long long z;
                pair <long long, int> p;
                
                if (v[i].first != v[j].first) break;
                
                p = s1.get(0, v[j].second);
                z = p.first + a[v[j].second] + (long long)v[j].second * d;
                if (z < y) {
                    x = p.second;
                    y = z;
                }
                
                s1.update(v[j].second, inf);
            }
            
            for (k = j - 1; k >= i; k--) {
                long long z;
                pair <long long, int> p;
                
                p = s2.get(v[k].second + 1, n);
                z = p.first + a[v[k].second] - (long long)v[k].second * d;
                if (z < y) {
                    x = p.second;
                    y = z;
                }
                
                s2.update(v[k].second, inf);
            }
            
            w.push_back(make_pair(y, make_pair(x, v[i].second)));
            
            for (; i < j; i++) {
                s1.update(v[i].second, make_pair(a[v[i].second] - (long long)v[i].second * d, v[i].second));
                s2.update(v[i].second, make_pair(a[v[i].second] + (long long)v[i].second * d, v[i].second));
            }
        }
        
        for (i = 0; i < w.size(); i++) {
            int x = w[i].second.first;
            int y = w[i].second.second;
            long long z = w[i].first;
            
            if (find(x) != find(y)) {
                ans += z;
                unite(x, y);
            }
        }
    }
    
    printf("%lld\n", ans);
    
    return 0;
}


Measured memory_bytes: 25968