#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int n;
const int maxN = 2 * (int)1e5 + 100;
pair < ll, int > t[2][4 * maxN];
ll val[2][maxN];
void build(int v, int tl, int tr, int ind) {
    if (tl == tr) {
        t[ind][v] = make_pair(val[ind][tl], tl);
        return ;
    }
    int tm = (tl + tr) / 2;
    build(v + v, tl, tm, ind);
    build(v + v + 1, tm + 1, tr, ind);
    t[ind][v] = min(t[ind][v + v], t[ind][v + v + 1]);
}
void upd(int v, int tl, int tr, ll val, int pos, int ind) {
    if (tl == tr) {
        t[ind][v] = make_pair(val, pos);
        return ;
    }
    int tm = (tl + tr) / 2;
    if (pos <= tm) upd(v + v, tl, tm, val, pos, ind);
    else if (pos > tm) upd(v + v + 1, tm + 1, tr, val, pos, ind);
    t[ind][v] = min(t[ind][v + v], t[ind][v + v + 1]);
}
pair < ll, int > get(int v, int tl, int tr, int l, int r, int ind) {
    if (tl == l && tr == r) {
        return t[ind][v];
    }
    int tm = (tl + tr) / 2;
    if (r <= tm) return get(v + v, tl, tm, l, r, ind);
    else if (l > tm) return get(v + v + 1, tm + 1, tr, l, r, ind);
    else return min(get(v + v, tl, tm, l, tm, ind), get(v + v + 1, tm + 1, tr, tm + 1, r, ind));
}
ll D;
ll a[maxN];
ll ans = 0;
int sz[maxN];
int p[maxN];
int get(int a) {
    if (a == p[a]) return a;
    p[a] = get(p[a]);
    return p[a];
}
bool unite(int a, int b) {
    a = get(a);
    b = get(b);
    if (a == b) return false;
    if (sz[a] > sz[b]) swap(a, b);
    sz[b] += sz[a];
    p[a] = b;
    return true;
}
const ll INF = (ll)1e18;
vector < int > comps[maxN];
pair < ll, int > mi[maxN];
void solve() {
    for (int i = 1; i <= n; i++) {
        comps[i].clear();
    }
    for (int i = 1; i <= n; i++) {
        comps[get(i)].push_back(i);
    }
    for (int i = 1; i <= n; i++) {
        if (comps[i].empty()) continue;
        for (int v : comps[i]) {
            for (int j = 0; j < 2; j++) {
                upd(1, 1, n, INF, v, j);
            }
        }
        pair < ll, int > mn = make_pair(INF, -1);
        for (int v : comps[i]) {
            auto t1 = get(1, 1, n, 1, v, 0);
            auto t2 = get(1, 1, n, v, n, 1);
            mn = min(mn, {t1.first + val[1][v], t1.second});
            mn = min(mn, {t2.first + val[0][v], t2.second});
        }
        for (int v : comps[i]) {
            for (int j = 0; j < 2; j++) {
                upd(1, 1, n, val[j][v], v, j);
            }
        }
        mi[i] = mn;
    }
    for (int i = 1; i <= n; i++) {
        //cout << i << " " << mi[i].second << " " << mi[i].first << " " << val[i][0]
        if (unite(i, mi[i].second)) {
            ans += mi[i].first;
        }
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("input.txt", "r", stdin);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        p[i] = i;
        sz[i] = 1;
    }
    cin >> D;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        val[0][i] = -i * D + a[i];
        val[1][i] = i * D + a[i];
    }
    for (int i = 0; i < 2; i++) build(1, 1, n, i);
    while (true) {
        bool ok = false;
        for (int i = 1; i <= n; i++) {
            if (sz[i] == n) {
                ok = true;
                break;
            }
        }
        if (ok) break;
        solve();
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 47352