#include <bits/stdc++.h>
using namespace std;
namespace std {
template <class S, class T>
pair<S, T> operator+(const pair<S, T> &a, const pair<S, T> &b) {
  return make_pair<S, T>(a.first + b.first, a.second + b.second);
}
template <class S, class T>
pair<S, T> operator-(const pair<S, T> &a, const pair<S, T> &b) {
  return make_pair<S, T>(a.first - b.first, a.second - b.second);
}
template <class S, class T>
pair<S, T> &operator+=(pair<S, T> &a, const pair<S, T> &other) {
  return a = a + other;
}
template <class S, class T>
pair<S, T> &operator-=(pair<S, T> &a, const pair<S, T> &other) {
  return a = a - other;
}
template <class S, class T>
ostream &operator<<(ostream &ost, pair<S, T> p) {
  ost << "(" << p.first << ", " << p.second << ")";
  return ost;
}
template <class T>
ostream &print_iterable_container(ostream &ost, T &container) {
  for (auto &&iter = begin(container); iter != end(container); ++iter)
    ost << (iter == begin(container) ? " [ " : ", ") << (*iter);
  return ost << " ]";
}
template <class T>
ostream &operator<<(ostream &ost, vector<T> &container) {
  return print_iterable_container(ost, container);
};
template <class T>
ostream &operator<<(ostream &ost, list<T> &container) {
  return print_iterable_container(ost, container);
};
template <class T>
ostream &operator<<(ostream &ost, deque<T> &container) {
  return print_iterable_container(ost, container);
};
}  // namespace std
template <class T>
inline bool CHMAX(T &l, const T &r) {
  return l < r ? l = r, 1 : 0;
}
template <class T>
inline bool CHMIN(T &l, const T &r) {
  return l > r ? l = r, 1 : 0;
}
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using ld = long double;
template <class T>
using VV = vector<vector<T> >;
template <class T>
using maxPQ = priority_queue<T>;
template <class T>
using minPQ = priority_queue<T, vector<T>, greater<T> >;
template <class T, class U>
using uomap = unordered_map<T, U>;
template <class T>
using uoset = unordered_set<T>;
const ll INF = 1001001001;
const ll INFll = (ll)INF * INF;
const ll MOD = 1000000007;
const ll MOD_FFT = 998244353;
const ld EPS = 1e-15;
int main() {
  ios_base::sync_with_stdio(false);
  int N, D;
  cin >> N >> D;
  vi A(N);
  for (int i = 0; i < (N); i++) cin >> A[i];
  int am = distance(begin(A), min_element(begin(A), end(A)));
  ll ans = 0;
  int li = am - 1, ri = am + 1;
  int lmi = am, rmi = am;
  vi par(N, -1);
  par[am] = am;
  for (int i = 0; i < (N - 1); i++) {
    ll rcost = ri >= N ? INFll : ll(ri - rmi) * D + A[ri] + A[rmi];
    ll lcost = li < 0 ? INFll : ll(lmi - li) * D + A[li] + A[lmi];
    if (rcost < lcost) {
      ans += rcost;
      par[ri] = rmi;
      if (A[ri] - A[rmi] < ll(ri - rmi) * D) {
        int root = ri;
        for (int k = ri - 1; k > rmi; k--) {
          ll rcost = ll(rmi - k) * D + A[rmi] + A[k];
          ll lcost = ll(i - root) * D + A[k] + A[root];
          if (lcost < rcost) {
            ans -= rcost - lcost;
          }
          if (A[k] - A[root] < ll(k - root) * D) root = k;
        }
        rmi = ri;
      }
      ri++;
    } else {
      ans += lcost;
      par[li] = lmi;
      if (A[li] - A[lmi] < ll(lmi - li) * D) {
        int root = li;
        for (int k = li + 1; k < lmi; k++) {
          ll rcost = ll(k - lmi) * D + A[lmi] + A[k];
          ll lcost = ll(root - k) * D + A[k] + A[root];
          if (rcost < lcost) {
            ans -= lcost - rcost;
          }
          if (A[k] - A[root] < ll(root - k) * D) root = k;
        }
        lmi = li;
      }
      li--;
    }
  }
  cout << ans << endl;
  return 0;
}
