#include <bits/stdc++.h>
using namespace std;
struct segtree {
  long long int M = 1, INF = 1000000000000000000, INIT;
  vector<vector<long long int>> dat;
  segtree(long long int N, long long int num) {
    INIT = num;
    while (M < N) M *= 2;
    dat.resize(M * 2 - 1, vector<long long int>{num, -1});
  }
  void update(long long int x, long long int k, long long int l = 0,
              long long int r = -1) {
    if (r == -1) r = M;
    k += M - 1;
    dat[k] = vector<long long int>{x, k - (M - 1)};
    while (k > 0) {
      k = (k - 1) / 2;
      dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }
  vector<long long int> query(long long int a, long long int b = -1,
                              long long int k = 0, long long int l = 0,
                              long long int r = -1) {
    if (r == -1) r = M;
    if (b == -1) b = M;
    if (r <= a || b <= l) return vector<long long int>{INIT, -INIT};
    if (a <= l && r <= b) return dat[k];
    vector<long long int> A = query(a, b, k * 2 + 1, l, (l + r) / 2);
    vector<long long int> B = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return min(A, B);
  }
};
long long int INF = 1000000000000000000;
segtree l(200001, INF), r(200001, INF);
int main(int argc, char const *argv[]) {
  long long int n, D;
  scanf("%lld %lld", &n, &D);
  vector<long long int> A(n + 1, 0);
  for (int i = 1; i <= n; i++) scanf("%lld", &A[i]);
  for (long long int i = 1; i <= n; i++) {
    l.update(A[i] - D * i, i);
    r.update(A[i] + D * i, i);
  }
  if (n == 1) {
    std::cout << 0 << '\n';
    return 0;
  }
  vector<bool> use(n + 1, 0);
  long long int ans = 0;
  priority_queue<
      tuple<long long int, long long int, long long int, long long int>,
      vector<tuple<long long int, long long int, long long int, long long int>>,
      greater<
          tuple<long long int, long long int, long long int, long long int>>>
      q;
  q.push(tuple<long long int, long long int, long long int, long long int>(
      0, -1, 1, 0));
  while (!q.empty()) {
    tuple<long long int, long long int, long long int, long long int> top =
        q.top();
    q.pop();
    long long int src = get<1>(top);
    long long int dst = get<2>(top);
    if (dst < 0) continue;
    if (use[dst]) {
      if (get<3>(top) == 1) {
        vector<long long int> x = r.query(src + 1, n + 1);
        q.push(
            tuple<long long int, long long int, long long int, long long int>(
                A[src] - D * src + x[0], src, x[1], 1));
      } else {
        vector<long long int> x = l.query(0, src);
        q.push(
            tuple<long long int, long long int, long long int, long long int>(
                A[src] + D * src + x[0], src, x[1], 0));
      }
      continue;
    }
    ans += get<0>(top);
    use[dst] = 1;
    r.update(INF, dst);
    l.update(INF, dst);
    if (src != -1) {
      if (get<3>(top) == 1) {
        vector<long long int> x = r.query(src + 1, n + 1);
        q.push(
            tuple<long long int, long long int, long long int, long long int>(
                A[src] - D * src + x[0], src, x[1], 1));
      } else {
        vector<long long int> x = l.query(0, src);
        q.push(
            tuple<long long int, long long int, long long int, long long int>(
                A[src] + D * src + x[0], src, x[1], 0));
      }
    }
    vector<long long int> L = l.query(0, dst);
    vector<long long int> R = r.query(dst + 1, n + 1);
    q.push(tuple<long long int, long long int, long long int, long long int>(
        A[dst] - D * dst + R[0], dst, R[1], 1));
    q.push(tuple<long long int, long long int, long long int, long long int>(
        A[dst] + D * dst + L[0], dst, L[1], 0));
    if (dst == 12) std::cout << L[0] << " " << L[1] << '\n';
  }
  std::cout << ans << '\n';
  return 0;
}
