#include <bits/stdc++.h>
using namespace std;
struct Edge {
  long long cost;
  int from, to;
  Edge(long long cost, int from, int to) : cost(cost), from(from), to(to) {}
};
bool operator<(const Edge& a, const Edge& b) {
  return a.cost != b.cost   ? a.cost < b.cost
         : a.from != b.from ? a.from < b.from
                            : a.to < b.to;
}
void solve(vector<Edge>& E, vector<long long> A, long long D, int t) {
  long long N = A.size();
  for (int i = 0; i < N; ++i) A[i] += i * D;
  vector<long long> M(N);
  M[N - 1] = N - 1;
  for (int i = N - 2; i >= 0; --i) {
    if (A[i] < A[M[i + 1]])
      M[i] = i;
    else
      M[i] = M[i + 1];
  }
  for (int i = 0; i < N - 1; ++i) {
    if (t)
      E.emplace_back(A[i] + A[M[i + 1]] - 2 * i * D, N - 1 - i,
                     N - 1 - M[i + 1]);
    else
      E.emplace_back(A[i] + A[M[i + 1]] - 2 * i * D, i, M[i + 1]);
  }
}
struct UnionFind {
  vector<int> data;
  UnionFind(int n) : data(n, -1) {}
  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    if (data[y] < data[x]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return x != y;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int find(int x) {
    if (data[x] < 0) return x;
    return data[x] = find(data[x]);
  }
};
int main() {
  long long N, D;
  cin >> N >> D;
  vector<long long> A(N), M(N);
  for (int i = 0; i < N; ++i) cin >> A[i];
  vector<Edge> E;
  solve(E, A, D, 0);
  reverse(A.begin(), A.end());
  solve(E, A, D, 1);
  sort(E.begin(), E.end());
  UnionFind uf(N);
  long long ans = 0;
  for (auto e : E) {
    long long cost = e.cost;
    int from = e.from, to = e.to;
    cerr << cost << " " << from << " " << to << endl;
    if (uf.same(from, to)) continue;
    uf.unite(from, to);
    ans += cost;
  }
  cout << ans << endl;
}
