#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef unsigned int uint;
typedef long double ld;
//#define ll __int128
#define int ll
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<pii> vpi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;

#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define mp(a,b) make_pair(a,b)
#define modsum(a, b) ((a) + (b) >= M ? (a) + (b) - M : (a) + (b))
#define modsubtract(a, b) ((a) - (b) < 0 ? (a) - (b) + M : (a) - (b))
#define modmultiply(a, b) (((a) * (b)) % M)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define cint const int &
#define SZ(a) ((int)(a.size()))
#define watch(x) cout << (#x) << " = " << x << endl;

const double PI = atan2(1, 0) * 2;

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";


template<class T>
ostream & operator << (ostream &out, vector<T> &a) {
    out << "{";
    for (auto x : a) out << x << " ";
    return out << "}";
}

void smain();

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);


#ifdef ART_HOME
    freopen("input.txt", "r", stdin);
    clock_t start = clock();
#endif
    cout << setprecision(12) << fixed;
    smain();
#ifdef ART_HOME
    cout << "\n\n\n";
    cout << "TOTAL EXECUTION TIME: " << float(clock() - start) / CLOCKS_PER_SEC << endl;
#endif
}


struct edge
{
    int from, to, price;
    edge(int from = 0, int to = 0, int price = 0): from(from), to(to), price(price){};
};


vi val;
vector<edge> edges;

int n, d;


void construct(int l, int r)
{
//    for (int i = 0; i < n; ++i)
//        for (int j = i + 1; j < n; ++j)
//            edges.push_back(edge(i, j, val[i] + val[j] + (j - i) * d));
//
//    return;

    if (l == r)
        return;

    int m = (l + r) >> 1;

    construct(l, m);
    construct(m + 1, r);

    int i0 = l, j0 = r;
    for (int i = l; i <= m; ++i)
        if (val[i] - d * i < val[i0] - d * i0)
            i0 = i;


    for (int i = m + 1; i <= r; ++i)
    {
        if (val[i] + d * i < val[j0] + d * j0)
            j0 = i;
    }

    for (int i = l; i <= r; ++i)
    {
        if (i <= m)
        {
            edges.push_back(edge(i, j0, val[i] + val[j0] + d * (j0 - i)));
        } else
        {
            edges.push_back(edge(i0, i, val[i0] + val[i] + d * (i - i0)));
        }
    }
}


const int N = 2e5 + 100;
int par[N];


bool comp(edge a, edge b)
{
    return a.price < b.price;
}


int get_par(int v)
{
    if (par[v] == v)
        return v;

    return par[v] = get_par(par[v]);
}


int get_ans()
{
    stable_sort(ALL(edges), comp);
    int ans = 0;

    for (int i = 0; i < N; ++i)
        par[i] = i;

    int cnt = 0;
    for (auto p : edges) {

        if (get_par(p.to) != get_par(p.from))
        {
            cnt++;
            ans += p.price;
            par[par[p.to]] = par[p.from];
        }
    }

//    cout << cnt << endl;
    return ans;
}


void smain() {
    cin >> n >> d;
    val.resize(n);

    for (int i = 0; i < n; ++i)
        cin >> val[i];

    construct(0, n - 1);
    cout << get_ans();
}

Measured memory_bytes: 169564