#include <bits/stdc++.h>
using namespace std;
__int128_t th = 1000000000000000000;
inline __int128_t encode(long long int a, long long int b) {
  __int128_t A = a, B = b;
  return th * th + A * th + B;
}
pair<long long int, long long int> decode(__int128_t a) {
  long long int B = a % th;
  a -= B;
  return make_pair((a - th * th) / th, B);
}
struct segtree {
  __int128_t M = 1, INIT;
  __int128_t INF = encode(th, th);
  vector<__int128_t> dat;
  segtree(long long int N, long long int num) {
    INIT = num;
    while (M < N) M *= 2;
    dat.resize(M * 2 - 1, encode(num, 0));
  }
  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] = encode(x, k - (M - 1));
    while (k > 0) {
      k = (k - 1) / 2;
      dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }
  __int128_t 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 INF;
    if (a <= l && r <= b) return dat[k];
    __int128_t A = query(a, b, k * 2 + 1, l, (l + r) / 2);
    __int128_t 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);
  use[0] = 1;
  long long int ans = 0;
  vector<vector<long long int>> dat =
      vector<vector<long long int>>(n + 1, vector<long long int>(2, -1));
  priority_queue<tuple<long long int, long long int>,
                 vector<tuple<long long int, long long int>>,
                 greater<tuple<long long int, long long int>>>
      q;
  set<long long int> area;
  q.push(tuple<long long int, long long int>(0, 1));
  while (!q.empty()) {
    tuple<long long int, long long int> top = q.top();
    q.pop();
    long long int dst = get<1>(top);
    if (dst < 0 || get<0>(top) >= INF || use[dst]) continue;
    use[dst] = 1;
    l.update(INF, dst);
    r.update(INF, dst);
    ans += get<0>(top);
    auto itr = area.upper_bound(dst);
    auto itl = itr;
    long long int L = 1, R = n;
    vector<int> dellist;
    while (itr != area.end() && (A[(*itr)] - A[dst]) >= D * ((*itr) - dst)) {
      dellist.push_back((*itr));
      itr++;
    }
    if (itl != area.begin()) {
      auto T = itl;
      T--;
      while (itl != area.begin() && (A[*T] - A[dst]) >= D * (dst - (*T))) {
        dellist.push_back((*T));
        itl--;
        if (itl != area.begin()) T--;
      }
    }
    if (itr != area.end()) {
      long long int id = (*itr);
      long long int x = 0, y = n;
      while (y - x > 1) {
        long long int mid = (x + y) / 2;
        long long int costA = A[dst] + D * abs(dst - mid);
        long long int costB = A[id] + D * abs(id - mid);
        if (costB < costA)
          y = mid;
        else
          x = mid;
      }
      R = y - 1;
      pair<long long int, long long int> tmp = decode(l.query(y, id));
      q.push(tuple<long long int, long long int>(A[id] + D * id + tmp.first,
                                                 tmp.second));
    }
    if (itl != area.begin()) {
      itl--;
      long long int id = (*itl);
      long long int x = 0, y = n;
      while (y - x > 1) {
        long long int mid = (x + y) / 2;
        long long int costA = A[dst] + D * abs(dst - mid);
        long long int costB = A[id] + D * abs(id - mid);
        if (costB < costA)
          x = mid;
        else
          y = mid;
      }
      L = x + 1;
      pair<long long int, long long int> tmp = decode(r.query(id, y + 1));
      q.push(tuple<long long int, long long int>(A[id] - D * id + tmp.first,
                                                 tmp.second));
    }
    if (R > L) area.insert(dst);
    for (auto d : dellist) area.erase(d);
    pair<long long int, long long int> tmp = decode(l.query(L, dst));
    q.push(tuple<long long int, long long int>(A[dst] + D * dst + tmp.first,
                                               tmp.second));
    tmp = decode(r.query(dst + 1, R + 1));
    q.push(tuple<long long int, long long int>(A[dst] - D * dst + tmp.first,
                                               tmp.second));
  }
  std::cout << ans << '\n';
  return 0;
}
