#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
#define FI(i,a,b) for(int i=(a);i<=(b);++i)
#define FD(i,b,a) for(int i=(b);i>=(a);--i)
#define DEBUG(x) cerr << #x << ": " << (x) << endl;
constexpr int inv(LL x, int m) { return x > m ? inv(x % m, m) : x > 1 ? inv(m % x, m) * (m - m / x) % m : x; }
constexpr int mpow(LL a, LL k, int m) { int r(1); for (a %= m; k; k >>= 1, a = a * a % m) if (k & 1)r = r * a % m; return r; }

struct DSU {
    vector<int> F;
    DSU(int n): F(n, -1) {}
    int root(int x) { return F[x] < 0 ? x : F[x] = root(F[x]); }
    int size(int x) { return -F[root(x)]; }
    bool same(int x, int y) { return root(x) == root(y); }
    bool unite(int x, int y) {
        x = root(x), y = root(y);
        if (x != y) { if (F[y] < F[x]) swap(x, y); F[x] += F[y], F[y] = x; }
        return x != y;
    }
};

const int N = 2e5 + 5;
LL n, d, A[N];
const LL INF = 1LL << 60;
DSU uf(N);
using PLI = pair<LL, int>;
vector<tuple<LL, int, int>> E;

int main() {
    cin >> n >> d;
    FI(i, 1, n) scanf("%lld", &A[i]);
    set<PLI> L, R;
    FI(i, 1, n) R.emplace(i * d + A[i], i);
    FI(i, 1, n) {
        R.erase(PLI{i * d + A[i], i});
        if (!R.empty()) {
            E.emplace_back(R.begin()->first - i * d + A[i], i, R.begin()->second);
        }
        if (!L.empty()) {
            E.emplace_back(L.begin()->first - (n + 1 - i) * d + A[i], i, L.begin()->second);
        }
        L.emplace((n + 1 - i)*d + A[i], i);
    }
    sort(E.begin(), E.end());
    LL ans = 0;
    for (auto tup : E) {
        LL len;
        int i, j;
        tie(len, i, j) = tup;
        if (!uf.same(i, j)) ans += len, uf.unite(i, j);
    }
    cout << ans << endl;
}
