#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
ostream& operator<<(ostream& s, const pair<T1, T2>& p) {
  return s << "(" << p.first << ", " << p.second << ")";
}
template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  for (int i = 0; i < v.size(); ++i) {
    s << v[i] << (i == v.size() - 1 ? "" : "\t");
  }
  return s;
}
template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T> >& vv) {
  for (int i = 0; i < vv.size(); ++i) {
    s << vv[i] << endl;
  }
  return s;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& s, const map<T1, T2>& m) {
  for (auto it = m.begin(); it != m.end(); ++it) {
    s << (it == m.begin() ? "{\t" : "") << (*it).first << " : " << (*it).second
      << "\t";
  }
  return s << "}";
}
int main() {
  ios_base::sync_with_stdio(false);
  int N, D;
  cin >> N >> D;
  int a;
  vector<vector<int> > A(N, vector<int>(3));
  for (int(i) = (0); (i) < (N); ++(i)) {
    cin >> a;
    A[i] = {a, i, -1};
  }
  sort(A.begin(), A.end());
  long long int ans = 0;
  for (int(i) = (0); (i) < (N); ++(i)) {
    int cur = A[i][0];
    int cur_pos = A[i][1];
    long long int cost = 1e18;
    for (int(j) = (0); (j) < (N); ++(j)) {
      if (i == j) continue;
      long long int ncost =
          (long long int)(abs(cur_pos - A[j][1]) * D + cur + A[j][0]);
      if (ncost <= cost) {
        cost = ncost;
        A[i][2] = j;
      }
    }
    if (A[A[i][2]][2] == i) continue;
    ans += cost;
  }
  cout << (ans) << endl;
  return 0;
}
