#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream &operator<<(ostream &os, vector<T> v) {
  for (long long i = (0); i < ((long long)(v).size()); i++)
    os << (i ? " " : "") << v[i];
  return os;
}
const bool debug = 0;
const long long INF = 1e18;
struct edge {
  long long i, j, v;
};
bool operator<(edge a, edge b) { return a.v > b.v; }
struct iv {
  long long i, v;
};
struct segtree {
  const iv DEF = {-1, INF};
  iv f(iv a, iv b) {
    if (a.v <= b.v)
      return a;
    else
      return b;
  }
  long long n = 1;
  vector<iv> t;
  void calc(long long i) { t[i] = f(t[2 * i], t[2 * i + 1]); }
  segtree(vector<iv> a) {
    while (n < (long long)(a).size()) n *= 2;
    t = vector<iv>(2 * n, DEF);
    copy(a.begin(), a.end(), &t[n]);
    for (long long i = n; i-- > 1;) calc(i);
  }
  void modify(long long i, iv val) {
    for (t[i += n] = val; i /= 2;) calc(i);
  }
  iv query(long long l, long long r) {
    iv accL = DEF, accR = DEF;
    for (l += n, r += n; l < r; l /= 2, r /= 2) {
      if (l & 1) accL = f(accL, t[l++]);
      if (r & 1) accR = f(t[--r], accR);
    }
    return f(accL, accR);
  }
};
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, d;
  cin >> n >> d;
  vector<long long> a(n);
  vector<bool> has(n, true);
  vector<iv> aPlus(n), aMinus(n);
  for (long long i = (0); i < (n); i++) {
    cin >> a[i];
    aPlus[i] = {i, a[i] + i * d};
    aMinus[i] = {i, a[i] - i * d};
  }
  segtree sPlus(aPlus), sMinus(aMinus);
  priority_queue<edge> pq;
  auto rem = [&](long long i) {
    sPlus.modify(i, {i, INF});
    sMinus.modify(i, {i, INF});
    has[i] = false;
  };
  auto up = [&](long long i) {
    {
      if (debug) cout << "update " << i << endl;
    }
    iv left = sMinus.query(0, i), right = sPlus.query(i + 1, n);
    left.v += a[i] + i * d;
    right.v += a[i] - i * d;
    {
      if (debug) cout << "new cand " << min(left.v, right.v) << endl;
    }
    if (left.v < min(right.v, INF / 2)) {
      pq.push({i, left.i, left.v});
    } else if (right.v < INF / 2) {
      pq.push({i, right.i, right.v});
    }
  };
  rem(0);
  up(0);
  long long numEdges = 0, totalCost = 0;
  while (numEdges < n - 1) {
    edge e = pq.top();
    pq.pop();
    {
      if (debug) cout << "edge " << e.i << " " << e.j << " " << e.v << endl;
    }
    assert(!has[e.i]);
    if (has[e.j]) {
      {
        if (debug) cout << "OK!" << endl;
      }
      totalCost += e.v;
      rem(e.j);
      up(e.j);
      numEdges++;
    }
    up(e.i);
    {
      if (debug) cout << "" << endl;
    }
  }
  cout << totalCost << "\n";
}
