#include <bits/stdc++.h>
using namespace std;
const long MOD = 1e9 + 7;
const long LINF = 1e13;
const long LLINF = 1e18;
const long ALPHABET = 26;
template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}
using Table = vector<pair<int, int>>;
int main() {
  long n, d;
  cin >> n >> d;
  vector<long> a(n);
  vector<pair<long, long>> id_a(n);
  vector<bool> remind_node(n, true);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    id_a[i] = make_pair(i, a[i]);
  }
  int64_t ans = 0;
  sort(id_a.begin(), id_a.end(), [](pair<long, long>& l, pair<long, long>& r) {
    return l.second < r.second;
  });
  long mincostnode_id = id_a[0].first;
  long mincostnode_cost = id_a[0].second;
  remind_node[mincostnode_id] = false;
  long secondnode_id = 0;
  int64_t mincost2 = LLINF;
  for (int i = 0; i < n; i++) {
    if (remind_node[i] == false) continue;
    if (mincost2 > abs(mincostnode_id - i) * d + mincostnode_cost + a[i]) {
      secondnode_id = i;
      mincost2 = abs(mincostnode_id - i) * d + mincostnode_cost + a[i];
    }
  }
  vector<long> net;
  net.push_back(mincostnode_id);
  net.push_back(secondnode_id);
  ans += abs(mincostnode_id - secondnode_id) * d + a[secondnode_id] +
         a[mincostnode_id];
  vector<tuple<int64_t, int64_t, int64_t>> remind_node_list;
  for (int i = 0; i < n; i++) {
    if (i == mincostnode_id || i == secondnode_id) continue;
    long minNodeid = 0;
    int64_t cost = LLINF;
    for (auto v : net) {
      if (cost > abs(i - v) * d + a[v] + a[i]) {
        cost = abs(i - v) * d + a[v] + a[i];
        minNodeid = v;
      }
    }
    remind_node_list.push_back(make_tuple(i, minNodeid, cost));
  }
  int64_t mincost = LLINF;
  long min_node_id = 0;
  long min_node_id_to = 0;
  for (auto v : remind_node_list) {
    cerr << get<0>(v) << " : " << get<1>(v) << " : " << get<2>(v) << endl;
    if (mincost > get<2>(v)) {
      mincost = get<2>(v);
      min_node_id = get<0>(v);
      min_node_id_to = get<1>(v);
    }
  }
  while (remind_node_list.size() > 0) {
    cerr << min_node_id << endl;
    ans += abs(min_node_id - min_node_id_to) * d + a[min_node_id_to] +
           a[min_node_id];
    net.push_back(min_node_id);
    mincost = LLINF;
    long next_min_node_id = 0;
    long next_min_node_id_to = 0;
    for (int i = 0; i < remind_node_list.size(); i++) {
      long nodeid = get<0>(remind_node_list[i]);
      if (nodeid == min_node_id) continue;
      int64_t value =
          abs(min_node_id - nodeid) * d + a[nodeid] + a[min_node_id];
      if (get<2>(remind_node_list[i]) > value) {
        remind_node_list[i] = make_tuple(nodeid, min_node_id, value);
      }
    }
    for (auto itr = remind_node_list.begin(); itr != remind_node_list.end();
         itr++) {
      if (get<0>((*itr)) == min_node_id) {
        remind_node_list.erase(itr);
        break;
      }
    }
    for (auto v : remind_node_list) {
      long id = get<0>(v);
      long id_to = get<1>(v);
      int64_t cost_ = get<2>(v);
      if (mincost > cost_) {
        mincost = cost_;
        next_min_node_id = id;
        next_min_node_id_to = id_to;
      }
    }
    min_node_id = next_min_node_id;
    min_node_id_to = next_min_node_id_to;
  }
  cout << ans << endl;
}
