#include <bits/stdc++.h>

// pbds
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
// gp_hash_table<int, int> table;

using namespace std;

#define vec vector
#define ALL(x) begin(x), end(x)

typedef unsigned long long ull;
typedef unsigned int ui;
typedef long long ll;
typedef long double ld;
typedef pair< int, int > pii;
typedef pair< long long, long long > pll;

const int inf = 1000 * 1000 * 1000;
const ll inf64 = 1e18;

const int N = 2e5 + 5;

int n, d;
int a[N];
int p[N];

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

void merge(int x, int y) {
    p[find(x)] = find(y);
}

int main() {

#ifdef debug
    freopen("input.txt", "r", stdin);
#endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

//#define TEST

#ifndef TEST
    cin >> n >> d;
#else
    mt19937 rnd(time(NULL));
//    n = rnd() % 10000 + 1;
    n = 1e5;
    d = rnd() % 100 + 1;
#endif

    for(int i = 1;i <= n;i++) {
#ifndef TEST
        cin >> a[i];
#else
        a[i] = rnd() % 100 + 1;
#endif
        p[i] = i;
    }

    vector< pair< ll, pii > > ed;
    set< pair< ll, int > > top;

    top.clear();
    for(int i = 1;i <= n;i++) {
        int ptr = 0;
        for(auto it = top.begin();it != top.end() && ptr < 20;it++, ptr++) {
            int j = it->second;
            ed.push_back({1ll * abs(i - j) * d + a[i] + a[j], {i, j}});
        }
        top.insert({-1ll * i * d + a[i], i});
    }

    top.clear();
    for(int j = -1, i = n;i >= 1;i--) {
        int ptr = 0;
        for(auto it = top.begin();it != top.end() && ptr < 20;it++, ptr++) {
            int j = it->second;
            ed.push_back({1ll * abs(i - j) * d + a[i] + a[j], {i, j}});
        }
        top.insert({1ll * i * d + a[i], i});
    }

    sort(ed.begin(), ed.end());

    ll res = 0;
    int cc = n;

    for(pair< ll, pii > e : ed) {
        int u, v;
        tie(u, v) = e.second;
        if(find(u) != find(v)) {
            res += e.first;
            merge(u, v);
            cc--;
        }
    }

#ifdef TEST
    cout << "cc = " << cc << "\n";
#endif

    cout << res << "\n";

    return 0;
}
