#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R;

class UnionFind {
	vector<int>parent;
	vector<int>rank;
public:
	UnionFind(int num) {
		num++;
		parent.resize(num);
		rank.resize(num);
		for (int i = 0; i < num; i++) {
			parent[i] = i;
			rank[i] = 0;
		}
	}
	int Find(int node) {
		if (parent[node] == node)return node;
		else return parent[node] = Find(parent[node]);
	}
	void Unite(int u, int v) {
		u = Find(u);
		v = Find(v);
		if (u == v)return;
		if (rank[u] < rank[v])parent[u] = v;
		else {
			parent[v] = u;
			if (rank[u] == rank[v])rank[u]++;
		}
	}
	bool Check_Same(int u, int v) {
		return Find(u) == Find(v);
	}
};

class Segment_Tree {
	vector<long long int>v;
	vector<int>l;
	vector<int>r;
	int num;
	long long int ret;
	bool is_min;
	long long int Update(int place) {
		if (place >= v.size() / 2) {
			return v[place];
		}
		if (is_min) {
			v[place] = min(Update(place * 2), Update(place * 2 + 1));
			return v[place];
		}
		v[place] = max(Update(place * 2), Update(place * 2 + 1));
		return v[place];
	}
	void RMQ(int a, int b, int place) {
		if (l[place] >= a && r[place] <= b) {
			if (is_min)ret = min(ret, v[place]);
			else ret = max(ret, v[place]);
			return;
		}
		if (l[place]>b || r[place]<a) return;
		RMQ(a, b, place * 2);
		RMQ(a, b, place * 2 + 1);
		return;
	}
public:
	void Left(int place) {
		if (place >= v.size() / 2) {
			l[place] = place - v.size() / 2;
			return;
		}
		Left(place * 2);
		Left(place * 2 + 1);
		l[place] = l[place * 2];
		return;
	}
	void Right(int place) {
		if (place >= v.size() / 2) {
			r[place] = place - v.size() / 2;
			return;
		}
		Right(place * 2);
		Right(place * 2 + 1);
		r[place] = r[place * 2 + 1];
		return;
	}
	Segment_Tree(int n, bool min) {
		n++;
		num = 1;
		while (num < n * 2) {
			num *= 2;
		}
		l.resize(num);
		r.resize(num);
		is_min = min;
		if (min) {
			v.resize(num, MOD*MOD);
		}
		else v.resize(num, -MOD * MOD);
		Left(1);
		Right(1);
	}
	void Insert(int place, long long int num, bool update) {
		place += v.size() / 2;
		v[place] = num;
		if (!update)return;
		place /= 2;
		while (place) {
			if (is_min)v[place] = min(v[place * 2], v[place * 2 + 1]);
			else v[place] = max(v[place * 2], v[place * 2 + 1]);
			place /= 2;
		}
	}
	void TopDown() {
		Update(1);
	}
	long long int RMQ(int a, int b) {
		if (is_min)ret = LLONG_MAX;
		else ret = LLONG_MIN;
		RMQ(a, b, 1);
		return ret;
	}
};

struct Edge {
	int a, b;
	long long int cost;
	bool operator<(const Edge&e)const {
		return cost < e.cost;
	}
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> N >> K;
	vector<long long int>v(N);
	for (auto &i : v)cin >> i;
	vector<Edge>edge;
	Segment_Tree lsg(N, true);
	Segment_Tree rsg(N, true);
	for (int i = 0; i < N; i++) {
		lsg.Insert(i, v[i] + i*K, false);
	}
	lsg.TopDown();
	for (int i = 0; i < N; i++) {
		rsg.Insert(i, v[i] + i * K, false);
	}
	rsg.TopDown();
	pair<long long int, int>box = { (N - 1)*K + v[0],0 };
	map<long long int, vector<int>>lm;
	for (int i = N - 1; i > 0; i--) {
		lm[lsg.RMQ(i, i)].push_back(i);
	}
	map<long long int, vector<int>>rm;
	for (int i = 0; i < N - 1; i++) {
		rm[rsg.RMQ(i, i)].push_back(i);
	}
	for (int i = 1; i < N; i++) {
		lm[lsg.RMQ(i, i)].pop_back();
		Edge add;
		add.a = i;
		add.b = box.second;
		add.cost = box.first + v[i] - K * (N - i - 1);
		//cerr << add.a << " " << add.b << endl;
		edge.emplace_back(add);
		long long int cost = lsg.RMQ(i + 1, N - 1);
		if (cost == LLONG_MAX)continue;
		int index = lm[cost].back();
		add.a = index;
		add.cost = box.first + v[index] - K * (N - index - 1);
		edge.emplace_back(add);
		if (box.first >= v[i] + (N - 1 - i)*K) {
			box = { v[i] + (N - 1 - i)*K,i };
		}
	}
	box = { v.back() + (N - 1)*K,N - 1 };
	for (int i = N - 2; i >= 0; i--) {
		rm[rsg.RMQ(i, i)].pop_back();
		Edge add;
		add.a = i;
		add.b = box.second;
		add.cost = box.first + v[i] - K * i;
		//cerr << add.a << " " << add.b << endl;
		edge.emplace_back(add);
		long long int cost = rsg.RMQ(0, i - 1);
		if (cost == LLONG_MAX)continue;
		int index = rm[cost].back();
		add.a = index;
		add.cost = box.first + v[index] - K * index;
		edge.emplace_back(add);
		if (box.first >= v[i] + K * i) {
			box = { v[i] + K * i,i };
		}
	}
	sort(edge.begin(), edge.end());
	UnionFind uf(N);
	long long int ans = 0;
	for (auto i : edge) {
		//cerr << i.a << " " << i.b << " " << i.cost << endl;
		if (uf.Check_Same(i.a, i.b))continue;
		cerr << i.a << " " << i.b << endl;
		ans += i.cost;
		uf.Unite(i.a, i.b);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 80364