#include <bits/stdc++.h>
const long long INF = 1791791791791791791;
using namespace std;
class segment_tree {
  int n;
  vector<long long> tval;
  vector<int> tid;
  vector<long long> mod;
  void push(int v) {
    mod[2 * v + 1] += mod[v];
    mod[2 * v + 2] += mod[v];
    tval[v] += mod[v];
    mod[v] = 0;
  }
  void build(int v, int L, int R) {
    tval[v] = INF;
    mod[v] = 0;
    tid[v] = L;
    if (L < R - 1) {
      build(2 * v + 1, L, (L + R) / 2);
      build(2 * v + 2, (L + R) / 2, R);
    }
  }
  pair<int, long long> get_min(int v, int L, int R, int l, int r) {
    if (R <= l || r <= L) {
      return make_pair(n, INF);
    } else if (l <= L && R <= r) {
      return make_pair(tid[v], tval[v] + mod[v]);
    } else {
      push(v);
      auto p1 = get_min(2 * v + 1, L, (L + R) / 2, l, r);
      auto p2 = get_min(2 * v + 2, (L + R) / 2, R, l, r);
      if (p1.second < p2.second)
        return p1;
      else
        return p2;
    }
  }
  void update(int v) {
    if (tval[2 * v + 1] + mod[2 * v + 1] < tval[2 * v + 2] + mod[2 * v + 2]) {
      tid[v] = tid[2 * v + 1];
      tval[v] = tval[2 * v + 1] + mod[2 * v + 1];
    } else {
      tid[v] = tid[2 * v + 2];
      tval[v] = tval[2 * v + 2] + mod[2 * v + 2];
    }
  }
  void update(int v, int L, int R, int i, long long x) {
    if (i < L || R <= i)
      return;
    else if (L == R - 1) {
      tid[v] = i;
      tval[v] = x;
      mod[v] = 0;
    } else {
      push(v);
      update(2 * v + 1, L, (L + R) / 2, i, x);
      update(2 * v + 2, (L + R) / 2, R, i, x);
      update(v);
    }
  }
  void add(int v, int L, int R, int l, int r, long long x) {
    if (R <= l || r <= L)
      return;
    else if (l <= L && R <= r)
      mod[v] += x;
    else {
      push(v);
      add(2 * v + 1, L, (L + R) / 2, l, r, x);
      add(2 * v + 2, (L + R) / 2, R, l, r, x);
      update(v);
    }
  }

 public:
  segment_tree(int _n) : n(_n) {
    tval.resize(4 * n);
    tid.resize(4 * n);
    mod.resize(4 * n);
    build(0, 0, n);
  }
  pair<int, long long> get_min(int l, int r) { return get_min(0, 0, n, l, r); }
  void set(int i, long long x) { update(0, 0, n, i, x); }
  void add(int l, int r, long long x) { return add(0, 0, n, l, r, x); }
};
struct min_holder {
  int n;
  long long d;
  vector<long long> a;
  segment_tree st;
  segment_tree stvals;
  set<int> prefmins;
  min_holder(long long _d, vector<long long> _a)
      : n(_a.size()), d(_d), a(_a), st(n), stvals(n) {
    prefmins.insert(0);
    prefmins.insert(n);
    for (int i = 0; i < (int)(n); i++) {
      stvals.set(i, INF + a[i] + d * i);
    }
  }
  void add_to_set(int i) {
    stvals.set(i, 2 * INF);
    auto prevmin = st.get_min(0, i);
    long long val = a[i] - d * i;
    st.set(i, val);
    if (prevmin.second > val) {
      int j = i;
      long long prev_val = prevmin.second;
      while (true) {
        auto it = prefmins.upper_bound(i);
        stvals.add(j, *it, val - prev_val);
        if (*it == n || a[*it] - d * (*it) < val) {
          break;
        } else {
          prev_val = a[*it] - d * (*it);
          j = *it;
          prefmins.erase(it);
        }
      }
      prefmins.insert(i);
    }
  }
  pair<int, int> get_min_edge() {
    int j = stvals.get_min(0, n).first;
    int i = st.get_min(0, j).first;
    return make_pair(i, j);
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  long long d;
  cin >> n >> d;
  vector<long long> a(n);
  for (int i = 0; i < (int)(n); i++) {
    cin >> a[i];
  }
  vector<long long> ra = a;
  reverse(ra.begin(), ra.end());
  min_holder frw(d, a);
  min_holder bckw(d, ra);
  frw.add_to_set(0);
  bckw.add_to_set(n - 1);
  vector<bool> took(n, false);
  took[0] = true;
  long long ans = 0;
  for (int i = 0; i < n - 1; i++) {
    auto p1 = frw.get_min_edge();
    auto p2 = bckw.get_min_edge();
    p2.first = n - 1 - p2.first;
    p2.second = n - 1 - p2.second;
    long long p1cost =
        (p1.first == n || !took[p1.first]
             ? INF
             : a[p1.first] + a[p1.second] + d * abs(p1.second - p1.first));
    long long p2cost =
        (p2.first == -1 || !took[p2.first]
             ? INF
             : a[p2.first] + a[p2.second] + d * abs(p2.second - p2.first));
    int to_a;
    if (p1cost < p2cost) {
      to_a = p1.second;
      ans += p1cost;
    } else {
      to_a = p2.second;
      ans += p2cost;
    }
    took[to_a] = true;
    frw.add_to_set(to_a);
    bckw.add_to_set(n - 1 - to_a);
  }
  cout << ans << endl;
  return 0;
}
