#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, int>;
using T = tuple<ll, int, int>;
const int MX = 200005;
const P INF = P(1e16, -1);
int n, c, d, sz;
bool used[MX];
ll k, ans, a2[MX], b2[MX];
priority_queue<T, vector<T>, greater<T>> qu;
struct SegTree {
  vector<P> dat;
  void ini(int n) {
    for (sz = 2; sz < n; sz *= 2)
      ;
    dat.assign(sz * 2, INF);
  }
  void set(int x, ll n) {
    dat[x += sz] = P(n, x);
    while (x /= 2) dat[x] = min(dat[x * 2], dat[x * 2 + 1]);
  }
  P query(int a, int b, int k = 1, int l = 0, int r = -1) {
    if (r == -1) r = sz;
    if (r <= a || b <= l) return INF;
    if (a <= l && r <= b) return dat[k];
    return min(query(a, b, k * 2, l, (l + r) / 2),
               query(a, b, k * 2 + 1, (l + r) / 2, r));
  }
} a, b;
T find(int t) {
  P e = b.query(0, t), f = a.query(t + 1, n);
  e.first += a2[t];
  f.first += b2[t];
  if (e.first > f.first) swap(e, f);
  return T(e.first, t, e.second);
}
int main() {
  scanf("%d%d", &n, &d);
  a.ini(n);
  b.ini(n);
  for (int i = 0; i < (n); i++) {
    scanf("%d", &c);
    a.set(i, a2[i] = c + (ll)i * d);
    b.set(i, b2[i] = c - (ll)i * d);
  }
  qu.push(find(0));
  a.set(0, 1e16);
  b.set(0, 1e16);
  used[0] = true;
  for (int i = 0; i < (n - 1); i++) {
    while (1) {
      tie(k, c, d) = qu.top();
      qu.pop();
      if (used[d])
        qu.push(find(c));
      else
        break;
    }
    ans += k;
    a.set(d, 1e16);
    b.set(d, 1e16);
    used[d] = true;
    qu.push(find(d));
    qu.push(find(c));
  }
  printf("%lld\n", ans);
}
