#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;

template<class T> inline T sqr(T x) {return x*x;}

LL f(VI &a, VP &b, int &i, LL &sum, LL &d, LL &n) {
    LL ksum = sum;
    LL tmp = 0;
    REP(j,0,i) {
        int pos = b[j].second;
        LL v = b[j].first;
        if (pos == 0 || pos == n - 1) continue;
        ksum -= 2 * v;
        LL mincost = 1LL << 60;
        int index = -1;
        REP(k,0,n) {
            bool bo = false;
            REP(l,0,i) {
                if (b[l].second == k) bo = true;
            }
            if (bo) continue;
            if (k == pos) continue;
            // if (abs(pos - k) <= 1) continue;
            LL cost = d * (abs(pos - k)) + a[k] + a[pos];
            if (cost < mincost) {
                mincost = cost;
                index = k;
            }
        }
        //cerr << i << " " << pos << " " << index << endl;
        ksum += mincost;
        tmp += mincost;
    }
    return ksum;
} 

void solve() {
    LL n,d;
    cin >> n >> d;
    VI a(n);
    VP b(n);
    REP(i,0,n) {
        cin >> a[i];
        b[i] = MP(a[i], i);
    }
    if (n == 1) {
        cout << 0 << endl;
        return;
    } else if (n == 2) {
        cout << d + a[0] + a[1] << endl;
        return;
    }
    sort(all(b));
    reverse(all(b));
    LL asum = 0;
    REP(i,0,n) asum += a[i];
    //LL diff = b[0][0] + b[1][0] - a[0] - a[n-1];
    LL sum = asum * 2 - a[0] - a[n-1] + (n - 1) * d;
    int L = 0,  R = n - 2;
    int cnt = 0;
    while (cnt++ < 15 && R - L > 1) {
        int m1 = (R-L)/3 + L, m2 = (R-L)*2/3 + L;
        //dump(L);
        //dump(R);
        //dump(m1);
        //dump(m2);
        //LL lv = f(a,b,L,sum,d,n);
        LL m1v = f(a,b,m1,sum,d,n);
        LL m2v = f(a,b,m2,sum,d,n);
        //dump(m1v);
        //dump(m2v);
        //LL Rv = f(a,b,R,sum,d,n);
        if (m1v > m2v) L = m1;
        else R = m2;
    }
    //dump(L);
    //dump(R);
    LL ans = f(a,b,L,sum,d,n);
    REP(i,L+1-5,R+1+5) {
        if (i < 0 || i >= n - 1) continue;
        ans = min(ans, f(a,b,i,sum,d,n));
        //dump(f(a,b,i,sum,d,n));
    }
    cout << ans << endl;
}

int main() {
    solve();
    
    return 0;
}