#include <bits/stdc++.h>
using namespace std;
struct LazySegmentTree {
 private:
  int n;
  vector<pair<long long, int>> node;
  vector<long long> di;
  vector<long long> lazy;

 public:
  LazySegmentTree(vector<long long> v, vector<long long> w) {
    int sz = (int)v.size();
    n = 1;
    while (n < sz) n *= 2;
    di = w;
    node.resize(2 * n - 1, {10000000000000000, 0});
    lazy.resize(2 * n - 1, 10000000000000000);
    for (int i = 0; i < sz; i++) node[i + n - 1] = {v[i], i};
    for (int i = n - 2; i >= 0; i--) {
      if (node[i * 2 + 1].first + di[node[i * 2 + 1].second] <
          node[i * 2 + 2].first + di[node[i * 2 + 2].second])
        node[i] = node[i * 2 + 1];
      else
        node[i] = node[i * 2 + 2];
    }
  }
  void eval(int k, int l, int r) {
    if (lazy[k] != 10000000000000000) {
      node[k].first =
          ((node[k].first) < (lazy[k]) ? (node[k].first) : (lazy[k]));
      if (r - l > 1) {
        lazy[2 * k + 1] =
            ((lazy[2 * k + 1]) < (lazy[k]) ? (lazy[2 * k + 1]) : (lazy[k]));
        lazy[2 * k + 2] =
            ((lazy[2 * k + 2]) < (lazy[k]) ? (lazy[2 * k + 2]) : (lazy[k]));
      }
      lazy[k] = 10000000000000000;
    }
  }
  void add(int a, int b, long long x, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    eval(k, l, r);
    if (b <= l || r <= a) return;
    if (a <= l && r <= b) {
      lazy[k] = ((lazy[k]) < (x) ? (lazy[k]) : (x));
      eval(k, l, r);
    } else {
      add(a, b, x, 2 * k + 1, l, (l + r) / 2);
      add(a, b, x, 2 * k + 2, (l + r) / 2, r);
      if (node[k * 2 + 1].first + di[node[k * 2 + 1].second] <
          node[k * 2 + 2].first + di[node[k * 2 + 2].second])
        node[k] = node[k * 2 + 1];
      else
        node[k] = node[k * 2 + 2];
    }
  }
  void use(int k) {
    di[k] = 10000000000000000;
    k += n - 1;
    do {
      k /= 2;
      if (node[k * 2 + 1].first + di[node[k * 2 + 1].second] <
          node[k * 2 + 2].first + di[node[k * 2 + 2].second])
        node[k] = node[k * 2 + 1];
      else
        node[k] = node[k * 2 + 2];
    } while (k > 0);
  }
  pair<long long, int> getmin(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) {
      pair<long long, int> ret = getmin(a, b, k, l, n);
      return {ret.first + di[ret.second], ret.second};
    }
    if (b <= l || r <= a) return {10000000000000000, 0};
    eval(k, l, r);
    if (a <= l && r <= b) return node[k];
    pair<long long, int> vl = getmin(a, b, 2 * k + 1, l, (l + r) / 2);
    pair<long long, int> vr = getmin(a, b, 2 * k + 2, (l + r) / 2, r);
    if (vl.first + di[vl.second] < vr.first + di[vr.second]) {
      return vl;
    } else {
      return vr;
    }
  }
  void disp() {
    for (int i = 0; i < 2 * n - 1; i++) {
      cout << node[i].first << " ";
    }
    cout << endl;
    for (int i = 0; i < 2 * n - 1; i++) {
      cout << node[i].second << " ";
    }
    cout << endl;
    for (int i = 0; i < di.size(); i++) {
      cout << di[i] << " ";
    }
    cout << endl;
  }
};
int main() {
  int n;
  long long d;
  cin >> n >> d;
  vector<long long> a(n), b(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<long long> v(n, 0);
  v[0] = 10000000000000000;
  for (int i = 1; i < n; i++) {
    v[i] = d * i + a[i];
  }
  for (int i = 0; i < n; i++) {
    b[i] = a[0];
  }
  LazySegmentTree r(b, v);
  for (int i = 1; i < n; i++) {
    v[i] = d * (n - i - 1) + a[i];
  }
  for (int i = 0; i < n; i++) {
    b[i] = 10000000000000000;
  }
  LazySegmentTree l(b, v);
  long long ans = 0;
  pair<long long, int> next, vl, vr;
  for (int i = 0; i < n - 1; i++) {
    vl = l.getmin(0, n);
    vr = r.getmin(0, n);
    next = ((vl) < (vr) ? (vl) : (vr));
    ans += next.first;
    l.add(0, next.second, a[next.second] - d * (n - next.second - 1));
    r.add(next.second, n, a[next.second] - d * next.second);
    l.use(next.second);
    r.use(next.second);
  }
  cout << ans << endl;
  return 0;
}
