//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>

using i8 = ::std::int_least8_t;
using i32 = ::std::int_least32_t;
using i64 = ::std::int_least64_t;
using u8 = ::std::uint_least8_t;
using u32 = ::std::uint_least32_t;
using u64 = ::std::uint_least64_t;
using isize = ::std::ptrdiff_t;
using usize = ::std::size_t;

template <class T = usize> class rep {
	const T f, l;

public:
	class itr {
		friend rep;
		T i;
		constexpr itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { ++i; }
		constexpr T operator*() const noexcept { return i; }
		constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	constexpr rep(const T first, const T last) noexcept : f(first), l(last) {}
	constexpr itr begin() const noexcept { return itr(f); }
	constexpr itr end() const noexcept { return itr(l); }
};
template <class T = usize> class revrep {
	const T f, l;

public:
	class itr {
		friend revrep;
		T i;
		constexpr itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { --i; }
		constexpr T operator*() const noexcept { return i; }
		constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	constexpr revrep(const T first, const T last) noexcept : f(first), l(last) {}
	constexpr itr begin() const noexcept { return itr(l - 1); }
	constexpr itr end() const noexcept { return itr(f - 1); }
};
template <class T> bool amax(T &a, const T &b) {
	return a <= b ? (a = b, 1) : 0;
}
template <class T> bool amin(T &a, const T &b) {
	return b <= a ? (a = b, 1) : 0;
}
template <class T> bool asmax(T &a, const T &b) {
	return b <= a ? 0 : (a = b, 1);
}
template <class T> bool asmin(T &a, const T &b) {
	return a <= b ? 0 : (a = b, 1);
}
template <class T> using vec_alias = ::std::vector<T>;
template <class T> auto md_vec(usize n, const T &value) {
	return ::std::vector<T>(n, value);
}
template <class... Args> auto md_vec(usize n, Args... args) {
	return ::std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> const T &as_const(const T &v) noexcept { return v; }
template <class T> constexpr T difference(const T &a, const T &b) {
	return a <= b ? b - a : a - b;
}

#include <cassert>
#include <cstdint>

template <::std::uint_least32_t Modulus> class modint {
	using u32 = ::std::uint_least32_t;
	using u64 = ::std::uint_least64_t;
	using i64 = ::std::int_fast64_t;
	class optimize_tag_t {};
	static constexpr optimize_tag_t optimize_tag{};

public:
	using value_type = u32;
	value_type a;

private:
	static constexpr value_type cst(i64 x) noexcept {
		x %= static_cast<i64>(Modulus);
		if (x < static_cast<i64>(0)) {
			x += static_cast<i64>(Modulus);
		}
		return static_cast<value_type>(x);
	}

	constexpr modint(optimize_tag_t, const value_type &x) noexcept : a(x) {}

public:
	constexpr modint() noexcept : a(static_cast<value_type>(0)) {}
	constexpr modint(const i64 &x) noexcept : a(cst(x)) {}
	constexpr value_type value() const noexcept { return a; }
	constexpr modint operator+(const modint &o) const noexcept {
		return modint(optimize_tag,
			a + o.a < Modulus ? a + o.a : a + o.a - Modulus);
	}
	constexpr modint operator-(const modint &o) const noexcept {
		return modint(optimize_tag, a < o.a ? a + Modulus - o.a : a - o.a);
	}
	constexpr modint operator*(const modint &o) const noexcept {
		return modint(
			optimize_tag,
			static_cast<value_type>(static_cast<u64>(a) * static_cast<u64>(o.a) %
				static_cast<u64>(Modulus)));
	}
	constexpr modint operator/(const modint &o) const {
		return modint(
			optimize_tag,
			static_cast<value_type>(static_cast<u64>(a) * static_cast<u64>((~o).a) %
				static_cast<u64>(Modulus)));
	}
	modint &operator+=(const modint &o) noexcept {
		if ((a += o.a) >= Modulus)
			a -= Modulus;
		return *this;
	}
	modint &operator-=(const modint &o) noexcept {
		if (a < o.a)
			a += Modulus;
		a -= o.a;
		return *this;
	}
	modint &operator*=(const modint &o) noexcept {
		a = static_cast<value_type>(static_cast<u64>(a) * static_cast<u64>(o.a) %
			static_cast<u64>(Modulus));
		return *this;
	}
	modint &operator/=(const modint &o) {
		a = static_cast<u64>(a) * (~o).a % Modulus;
		return *this;
	}
	constexpr modint inverse() const noexcept {
		assert(a != static_cast<value_type>(0) && "0 does not have inverse");
		return pow(static_cast<u64>(Modulus - static_cast<value_type>(2)));
	}
	constexpr modint operator~() const noexcept { return inverse(); }
	constexpr modint operator-() const noexcept {
		if (a == static_cast<value_type>(0)) {
			return modint(optimize_tag, static_cast<value_type>(0));
		}
		else {
			return modint(optimize_tag, Modulus - a);
		}
	}
	modint &operator++() noexcept {
		if (++a == Modulus) {
			a = static_cast<value_type>(0);
		}
		return *this;
	}
	modint &operator--() noexcept {
		if (a == static_cast<value_type>(0)) {
			a = Modulus;
		}
		--a;
		return *this;
	}
	constexpr bool operator==(const modint &o) const noexcept { return a == o.a; }
	constexpr bool operator!=(const modint &o) const noexcept { return a != o.a; }
	constexpr bool operator<(const modint &o) const noexcept { return a < o.a; }
	constexpr bool operator<=(const modint &o) const noexcept { return a <= o.a; }
	constexpr bool operator>(const modint &o) const noexcept { return a > o.a; }
	constexpr bool operator>=(const modint &o) const noexcept { return a >= o.a; }
	constexpr explicit operator bool() const noexcept { return a; }
	constexpr explicit operator value_type() const noexcept { return a; }
	modint pow(u64 x) const noexcept {
		u64 t = a, u = 1;
		while (x) {
			if (x & 1)
				u = u * t % Modulus;
			t = (t * t) % Modulus;
			x >>= 1;
		}
		return modint(optimize_tag, static_cast<value_type>(u));
	}
};

#include <cassert>
#include <cstddef>
#include <utility>

template <template <class> class Container> class union_find {
protected:
	class node_type;

public:
	using container_type = Container<node_type>;
	using size_type = typename container_type::size_type;

protected:
	class node_type {
	public:
		typename union_find::size_type parent, size;
	};
	container_type c;

public:
	union_find() : c() {}
	explicit union_find(const size_type size) : c(size, { 0, 1 }) {
		for (size_type i = 0; i < size; ++i)
			c[i].parent = i;
	}

	bool empty() const { return c.empty(); }
	size_type size() const { return c.size(); }

	size_type find(size_type x) {
		assert(x < size());
		while (c[x].parent != x)
			x = c[x].parent = c[c[x].parent].parent;
		return x;
	}
	bool same(const size_type x, const size_type y) {
		assert(x < size());
		assert(y < size());
		return find(x) == find(y);
	}
	size_type size(const size_type x) {
		assert(x < size());
		return c[find(x)].size;
	}

	::std::pair<size_type, size_type> unite(size_type x, size_type y) {
		assert(x < size());
		assert(y < size());
		x = find(x);
		y = find(y);
		if (x != y) {
			if (c[x].size < c[y].size)
				::std::swap(x, y);
			c[x].size += c[y].size;
			c[y].parent = x;
		}
		return { x, y };
	}
};



#include <algorithm>
#include <iostream>
#include <utility>
#include <string>
#include <array>
#include <numeric>

int main() {
	usize n;
	u64 d;
	::std::cin >> n >> d;
	::std::vector<u64> a(n);
	for (auto &e : a) {
		::std::cin >> e;
	}
	if (n == 1) {
		::std::cout << 0 << ::std::endl;
		return 0;
	}
	union_find<vec_alias> uf(n + 1);
	const auto cost = [&a, &d, &n](const usize l, const usize r)->u64 {
		if (l == n || r == n) return ::std::numeric_limits<u64>::max();
		return d*difference(l, r) + a[l] + a[r];
	};
	u64 ans = 0;
	usize cnt = 0, looper = 0;
	while(cnt!=n-1)
	{
		::std::vector<usize> near(n, n);
		::std::array<usize, 3> top = { n,n,n };
		for (const auto i : rep<>(0, n)) {
			if (!uf.same(i, top[0])) {
				near[i] = top[0];
			}
			else {
				near[i] = top[1];
			}
			top[2] = i;
			::std::sort(top.begin(), top.end(),
				[&cost, &i](usize l, usize r) {return cost(i, l) < cost(i, r);});
			if (uf.same(top[0], top[1])) {
				top[1] = top[2];
			}
		}
		top = { n,n,n };
		for (const auto i : revrep<>(0, n)) {
			if (!uf.same(i, top[0])) {
				if (cost(i, near[i]) > cost(i, top[0]))
					near[i] = top[0];
			}
			else {
				if (cost(i, near[i]) > cost(i, top[1]))
					near[i] = top[1];
			}
			top[2] = i;
			::std::sort(top.begin(), top.end(),
				[&cost, &i](usize l, usize r) {return cost(i, l) < cost(i, r);});
			if (uf.same(top[0], top[1])) {
				top[1] = top[2];
			}
		}
		::std::vector<usize> next(n);
		::std::iota(next.begin(), next.end(), 0);
		for (const auto i : rep<>(0, n)) {
			const auto r = uf.find(i);
			if (r != i) {
				next[i] = n;
				if (cost(i, near[i]) < cost(next[r], near[next[r]])) {
					next[r] = i;
				}
			}
		}
		0;
		for (const auto i : rep<>(0, n)) {
			if (next[i] != n) {
				const usize e = next[i];
				if (!uf.same(e, near[e])) {
					uf.unite(e, near[e]);
					++cnt;
					ans += cost(e, near[e]);
				}
			}
		}
		++looper;
	}
	::std::cout << ans << ::std::endl;
	return 0;
}


Measured memory_bytes: 8192