#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1 << 18;
int m;
long long int mx[2][2 * MAX_N], ind[2][2 * MAX_N];
const long long int INF = 1e18;
void init(int m_) {
  m = 1;
  while (m < m_) m <<= 1;
  for (int i = 1; i <= 2 * m - 1; i++)
    mx[0][i] = mx[1][i] = INF, ind[0][i] = ind[1][i] = -1;
}
void update(int k, int a, int i) {
  k += m;
  mx[i][k] = a;
  ind[i][k] = k - m;
  while (k > 1) {
    k >>= 1;
    if (mx[i][2 * k] < mx[i][2 * k + 1]) {
      ind[i][k] = ind[i][2 * k];
    } else {
      ind[i][k] = ind[i][2 * k + 1];
    }
    mx[i][k] = min(mx[i][2 * k], mx[i][2 * k + 1]);
  }
}
int query(int a, int b, int i) {
  a += m, b += m;
  long long int ans = INF;
  int ind0 = -1;
  for (; a < b; a >>= 1, b >>= 1) {
    if (b & 1) {
      b--;
      if (ans > mx[i][b]) {
        ans = mx[i][b];
        ind0 = ind[i][b];
      }
    }
    if (a & 1) {
      if (ans > mx[i][a]) {
        ans = mx[i][a];
        ind0 = ind[i][a];
      }
      a++;
    }
  }
  return ind0;
}
int par[200002];
int rk[200002];
void init1(int n) {
  for (int i = 0; i < n; i++) {
    par[i] = i;
  }
}
int find(int x) {
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}
void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) return;
  if (rk[x] < rk[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (rk[x] == rk[y]) rk[x]++;
  }
}
bool same(int x, int y) { return find(x) == find(y); }
int main() {
  int n;
  long long int d;
  cin >> n >> d;
  long long int a[200001];
  int ind0[200001];
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
    ind0[i] = i;
  }
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  if (n == 2) {
    cout << a[0] + a[1] + d << endl;
    return 0;
  }
  sort(ind0, ind0 + n, [&](int i, int j) { return a[i] < a[j]; });
  long long int ans = 0;
  init(n);
  vector<pair<long long int, pair<int, int> > > e;
  for (int i = 1; i < n; i++) {
    update(ind0[i - 1], a[ind0[i - 1]] - (long long int)ind0[i - 1] * d, 0);
    update(ind0[i - 1], a[ind0[i - 1]] + (long long int)ind0[i - 1] * d, 1);
    if (ind0[i] > 0) {
      int ind1 = query(0, ind0[i], 0);
      if (ind1 >= 0) {
        e.push_back(pair<long long int, pair<int, int> >(
            a[ind0[i]] + a[ind1] + (long long int)(ind0[i] - ind1) * d,
            pair<int, int>(ind0[i], ind1)));
      }
    }
    if (ind0[i] < n - 1) {
      int ind1 = query(ind0[i], n, 1);
      if (ind1 >= 0) {
        e.push_back(pair<long long int, pair<int, int> >(
            a[ind0[i]] + a[ind1] + (long long int)(ind1 - ind0[i]) * d,
            pair<int, int>(ind0[i], ind1)));
      }
    }
  }
  sort(e.begin(), e.end());
  init1(n);
  for (int i = 0; i < e.size(); i++) {
    int x = e[i].second.first, y = e[i].second.second;
    if (!same(x, y)) {
      unite(x, y);
      ans += e[i].first;
    }
  }
  cout << ans << endl;
  return 0;
}
