#include <bits/stdc++.h>
using namespace std;
const long long inf = 2e18;
struct segtree {
  pair<long long, int> dat[(1 << 18) * 2];
  void update(int k, long long v, int id) {
    k += (1 << 18);
    dat[k] = {v, id};
    while (k > 1) {
      k >>= 1;
      dat[k] = min(dat[k * 2], dat[k * 2 + 1]);
    }
  }
  pair<long long, int> query(int l, int r) {
    l += (1 << 18);
    r += (1 << 18);
    pair<long long, int> res(inf, -1);
    while (l < r) {
      if (l & 1) res = min(res, dat[l++]);
      if (r & 1) res = min(res, dat[--r]);
      l >>= 1;
      r >>= 1;
    }
    return res;
  }
};
segtree L, R;
vector<int> dat[200000];
int par[200000];
int find(int u) {
  if (par[u] == u) return u;
  return par[u] = find(par[u]);
}
void unite(int u, int v) {
  u = find(u);
  v = find(v);
  if (dat[u].size() < dat[v].size()) {
    swap(u, v);
  }
  for (int e : dat[v]) {
    dat[u].push_back(e);
  }
  par[v] = u;
}
int N;
long long D;
long long A[100000];
int main() {
  scanf("%d %lld", &N, &D);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
    par[i] = i;
    dat[i].push_back(i);
  }
  int c = N;
  long long ans = 0;
  while (c >= 2) {
    for (int i = 0; i < N; i++) {
      L.update(i, A[i] - i * D, find(i));
      R.update(i, A[i] + i * D, find(i));
    }
    vector<long long> cost;
    vector<int> from;
    vector<int> to;
    for (int i = 0; i < N; i++) {
      if (find(i) != i) continue;
      pair<long long, int> mn(inf, -1);
      for (int j : dat[i]) {
        L.update(j, inf, find(j));
        R.update(j, inf, find(j));
      }
      for (int j : dat[i]) {
        auto x = L.query(0, j);
        auto y = R.query(j, N);
        x.first += A[j] + j * D;
        y.first += A[j] - j * D;
        mn = min(mn, x);
        mn = min(mn, y);
      }
      for (int j : dat[i]) {
        L.update(j, A[j] - j * D, find(j));
        R.update(j, A[j] + j * D, find(j));
      }
      cost.push_back(mn.first);
      from.push_back(i);
      to.push_back(mn.second);
    }
    for (int i = 0; i < cost.size(); i++) {
      if (find(from[i]) == find(to[i])) continue;
      unite(from[i], to[i]);
      ans += cost[i];
      c--;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
