#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
long long 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); }
};
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;
  pair<long long int, int> box = {(N - 1) * K + v[0], 0};
  for (int i = 1; i < N; i++) {
    Edge add;
    add.a = i;
    add.b = box.second;
    add.cost = box.first + v[i] - K * (N - i - 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--) {
    Edge add;
    add.a = i;
    add.b = box.second;
    add.cost = box.first + v[i] - K * i;
    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) {
    if (uf.Check_Same(i.a, i.b)) continue;
    ans += i.cost;
    uf.Unite(i.a, i.b);
  }
  cout << ans << endl;
  return 0;
}
