#ifdef LOCAL
    #define _GLIBCXX_DEBUG
#endif



#include <cstdio>
#include <iostream>
#include <cmath>
#include <utility>
#include <memory>
#include <memory.h>
#include <cstdlib>
#include <set>
#include <map>
#include <cassert>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <numeric>
#include <algorithm>
#include <complex>
#include <vector>
#include <random>
#include <ctime>
#include <ostream>
#include <queue>
#include <array>


using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ld = long double;
using vi = std::vector<int>;
using pii = std::pair<int, int>;
using vvi = std::vector<vi>;
using vii = std::vector<pii>;
using vll = std::vector<ll>;
using pll = std::pair<ll, ll>;

#define MAKE_FINAL_NAME_HELPER(A, B) A ## B
#define MAKE_FINAL_NAME(NAME, NUM) MAKE_FINAL_NAME_HELPER(NAME ## _, NUM)
#define ARGUMENTS_SIZE_HELPER(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, COUNT, ...) COUNT
#define ARGUMENTS_SIZE(...) ARGUMENTS_SIZE_HELPER(__VA_ARGS__, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)
#define SELECT_MACRO(NAME, ...) MAKE_FINAL_NAME(NAME, ARGUMENTS_SIZE(__VA_ARGS__))(__VA_ARGS__)

#define pb push_back
#define sz(c) int((c).size())
#define all(c) begin(c), end(c)
#define mp(x, y) make_pair(x, y)
#define fst first
#define snd second

#define ford(...) SELECT_MACRO(ford, __VA_ARGS__)
#define ford_3(i, s, n) for (int i = int(n) - 1; i >= int(s); --i)
#define ford_2(i, n) ford_3(i, 0, n)

#define forn(...) SELECT_MACRO(forn, __VA_ARGS__)
#define forn_3(i, s, n) for (int i = int(s); i < int(n); ++i)
#define forn_2(i, n) forn_3(i, 0, n)

#define y1 y1___
#define prev prev___
#define next next___
#define hash hash___
#define left left___
#define right right___
#include <chrono>

template<typename T>
int sign(const T& t) {
    return (t > 0) - (t < 0);
}

template<typename T, typename U>
bool remax(T& a, U b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<typename T, typename U>
bool remin(T& a, U b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<typename T>
T gcd(T a, T b) {
    a = std::abs(a);
    b = std::abs(b);
    while (b) {
        a %= b;
        std::swap(a, b);
    }
    return a;
}

template<typename T>
T lcm(T a, T b) {
    a = std::abs(a);
    b = std::abs(b);
    return a / gcd(a, b) * b;
}

double get_time() {
    return static_cast<double>(clock()) / CLOCKS_PER_SEC;
}

long long current_nanoseconds() {
    return std::chrono::steady_clock::now().time_since_epoch().count();
}

#ifdef LOCAL
long long default_seed = 1;
#else
long long default_seed = current_nanoseconds();
#endif

uint32_t mrand_32t() {
    static std::mt19937 rng(default_seed);
    return rng();
}

uint64_t mrand_64t() {
    static std::mt19937_64 rng(default_seed);
    return rng();
}

template<typename T>
void make_unique(std::vector<T>& v) {
    std::sort(std::begin(v), std::end(v));
    v.erase(std::unique(std::begin(v), std::end(v)), std::end(v));
}

#include <sstream>

namespace std {

template<typename A, typename B>
string to_string(const pair <A, B>& p) {
    string str;
    str += "(";
    str += to_string(p.first);
    str += ", ";
    str += to_string(p.second);
    str += ")";
    return str;
}

string to_string(bool value) {
    return value ? "true" : "false";
}

template<typename T>
string to_string(const vector <T>& vec) {
    string str = "{ ";
    bool first = true;
    for (const auto& it : vec) {
        if (!first) {
            str += ", ";
        }
        str += to_string(it);
        first = false;
    }
    str += " }";
    return str;
}

template<typename T>
string to_string(const set <T>& s) {
    string str = "{ ";
    bool first = true;
    for (const auto& it : s) {
        if (!first) {
            str += ", ";
        }
        str += to_string(it);
        first = false;
    }
    str += " }";
    return str;
}


template<typename K, typename V>
string to_string(const map <K, V>& m) {
    string str = "{ ";
    bool first = true;
    for (const auto& it : m) {
        if (!first) {
            str += ", ";
        }
        first = false;
        str += to_string(it.first);
        str += " -> ";
        str += to_string(it.second);
    }
    str += " }";
    return str;
}

string to_string(const string& s) {
    return "\"" + s + "\"";
}

string to_string(const char* s) {
    return to_string(string(s));
}

string to_string(char ch) {
    return "\'" + string(1, ch) + "\'";
}

template<size_t N>
string to_string(const bitset<N>& b) {
    string res(N, '0');
    for (size_t i = 0; i < N; ++i) {
        res[i] = '0' + b[i];
    }
    return res;
}

template <typename T>
string to_string(const T& t) {
    std::stringstream ss;
    ss << t;
    return ss.str();
}

}

void debug_out() {
    std::cerr << std::endl;
}

template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    std::cerr << " " << std::to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
    #define debug(...) std::cerr << "[" << #__VA_ARGS__ <<  "]:", debug_out(__VA_ARGS__);
#else
    #define eprintf(...)
    #define cerr if (false) cerr
    #define debug(...)
#endif


class DSU {
public:
    explicit DSU(int n = 0) : par(n, -1) {}

    int get(int x) {
        return par[x] < 0 ? x : par[x] = get(par[x]);
    }

    bool unite(int x, int y) {
        x = get(x);
        y = get(y);
        if (x == y) {
            return false;
        }
        if (-par[x] < -par[y]) {
            std::swap(x, y);
        }
        par[x] += par[y];
        par[y] = x;
        return true;
    }

private:
    std::vector<int> par;
};

using namespace std;

/* *************************** TEMPLATE CODE ENDS HERE ******************************** */



int n;
int d;
vi a;

bool read() {
    if (!(cin >> n)) {
        return 0;
    }
    cin >> d;
    a.resize(n);
    forn(i, n) {
        cin >> a[i];
    }
    return 1;
}

const ll INF = 1e18;

//struct segm_tree {
//    vector<pair<ll, int>> t;
//    int sz;
//
//    segm_tree(int n = 0) {
//        sz = 1;
//        while (sz < n) {
//            sz *= 2;
//        }
//        t.assign(sz * 2, mp(INF, -1));
//        forn(i, n) {
//            t[sz + i] = mp(INF, i);
//        }
//        ford(v, 1, sz) {
//            upd(v);
//        }
//    }
//
//    void upd(int v) {
//        t[v] = min(t[v * 2], t[v * 2 + 1]);
//    }
//
//    pair<ll, int> get_min(int l, int r) {
//        l += sz;
//        r += sz;
//        pair<ll, int> res(INF, -1);
//        while (l <= r) {
//            remin(res, t[l]);
//            remin(res, t[r]);
//            l = (l + 1) >> 1;
//            r = (r - 1) >> 1;
//        }
//        return res;
//    }
//
//    void upd(int pos, ll val) {
//        int v = sz + pos;
//        t[v] = mp(val, pos);
//        v >>= 1;
//        while (v > 0) {
//            upd(v);
//            v >>= 1;
//        }
//    }
//};

void solve() {
    ll ans = 0;
    DSU dsu(n);
    while (1) {
        vi comp(n);
        bool all_same = 1;
        forn(i, n) {
            comp[i] = dsu.get(i);
            if (comp[i] != comp[0]) {
                all_same = 0;
            }
        }
        if (all_same) {
            break;
        }

        vector<pair<ll, int>> min_to(n, mp(INF, -1));

        // j < i
        {
            pair<ll, int> mn1(INF, -1);
            pair<ll, int> mn2(INF, -1);
            forn(i, n) {
                for (const auto& mn : {mn1, mn2}) {
                    if (mn.snd != -1 && mn.snd != comp[i]) {
                        ll cost = mn.fst + i * 1ll * d + a[i];
                        remin(min_to[i], mp(cost, mn.snd));
                    }
                }

                const pair<ll, int> cur(-i * 1ll * d + a[i], comp[i]);
                if (cur.snd == mn1.snd) {
                    remin(mn1, cur);
                } else if (cur.snd == mn2.snd) {
                    if (cur < mn1) {
                        mn2 = mn1;
                        mn1 = cur;
                    } else if (cur < mn2) {
                        mn2 = cur;
                    }
                } else if (cur < mn1) {
                    mn2 = mn1;
                    mn1 = cur;
                } else if (cur < mn2) {
                    mn2 = cur;
                }
            }
        }

        // i < j
        {
            pair<ll, int> mn1(INF, -1);
            pair<ll, int> mn2(INF, -1);
            ford(i, n) {
                for (const auto& mn : {mn1, mn2}) {
                    if (mn.snd != -1 && mn.snd != comp[i]) {
                        ll cost = mn.fst - i * 1ll * d + a[i];
                        remin(min_to[i], mp(cost, mn.snd));
                    }
                }

                const pair<ll, int> cur(i * 1ll * d + a[i], comp[i]);
                if (cur.snd == mn1.snd) {
                    remin(mn1, cur);
                } else if (cur.snd == mn2.snd) {
                    if (cur < mn1) {
                        mn2 = mn1;
                        mn1 = cur;
                    } else if (cur < mn2) {
                        mn2 = cur;
                    }
                } else if (cur < mn1) {
                    mn2 = mn1;
                    mn1 = cur;
                } else if (cur < mn2) {
                    mn2 = cur;
                }
            }
        }

        vector<pair<ll, int>> min_to_comp(n, mp(INF, -1));
        forn(i, n) {
            assert(min_to[i].fst < INF);
            remin(min_to_comp[comp[i]], min_to[i]);
        }

        forn(c, n) {
            if (min_to_comp[c].fst < INF) {
                int i = c;
                int j = min_to_comp[c].snd;
                if (dsu.unite(i, j)) {
                    ans += min_to_comp[c].fst;
                }
            }
        }
    }

    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout.tie(nullptr);
    cout.precision(12);
    cout << fixed;

#ifdef LOCAL
    #define FILE_NAME "a"
    assert(freopen(FILE_NAME ".in", "r", stdin));
//    freopen(FILE_NAME ".out", "w", stdout);
#endif

    while (read()) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 8980