#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& a) {
  return os << "(" << a.first << "," << a.second << ")";
}
template <class T>
void pv(T a, T b) {
  for (T i = a; i != b; ++i) cout << (*i) << " ";
  cout << endl;
}
template <class T>
void chmin(T& a, const T& b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T& a, const T& b) {
  if (a < b) a = b;
}
const int MAX_N = 212345;
struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) {}
  bool link(int x, int y) {
    x = root(x);
    y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }
  int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
  int size(int x) { return -data[root(x)]; }
  bool same(int x, int y) { return root(x) == root(y); }
};
int nextInt() {
  int x;
  scanf("%d", &x);
  return x;
}
long long A[MAX_N];
struct Edge {
  int a;
  int b;
  long long w;
  bool operator<(const Edge& o) const { return w < o.w; }
};
int main2() {
  int N = nextInt();
  long long D = nextInt();
  for (int i = 0, _n = (int)(N); i < _n; ++i) A[i] = nextInt();
  vector<Edge> es;
  {
    int j = -1;
    for (int i = 1; i < N; i++) {
      if (A[i - 1] < A[i]) {
        if (j == -1) {
          j = i - 1;
        } else {
          long long w0 = A[j] + abs(i - j) * D;
          long long w1 = A[i - 1] + abs(i - 1 - i) * D;
          if (w0 > w1) {
            j = i - 1;
          }
        }
      }
      if (j != -1) es.push_back((Edge){i, j, abs(i - j) * D + A[i] + A[j]});
    }
  }
  {
    int j = -1;
    for (int i = N - 2; i >= 0; i--) {
      if (A[i] > A[i + 1]) {
        if (j == -1) {
          j = i + 1;
        } else {
          long long w0 = A[j] + abs(i - j) * D;
          long long w1 = A[i + 1] + abs(i + 1 - i) * D;
          if (w0 >= w1) {
            j = i + 1;
          }
        }
      }
      if (j != -1) es.push_back((Edge){i, j, abs(i - j) * D + A[i] + A[j]});
    }
  }
  sort((es).begin(), (es).end());
  long long ans = 0;
  UnionFind uf(N);
  for (Edge e : es) {
    if (uf.link(e.a, e.b)) {
      ans += e.w;
    }
  }
  cout << ans << endl;
  return 0;
}
int main() {
  for (; !cin.eof(); cin >> ws) main2();
  return 0;
}
