#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f;
const long long inf2 = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-6;
const long long mod = 1000000007;
namespace fastio {
char in[100000];
long long itr = 0, llen = 0;
char get() {
  if (itr == llen) llen = fread(in, 1, 100000, stdin), itr = 0;
  if (llen == 0) return EOF;
  return in[itr++];
}
char out[100000];
long long itr2 = 0;
void put(char c) {
  out[itr2++] = c;
  if (itr2 == 100000) {
    fwrite(out, 1, 100000, stdout);
    itr2 = 0;
  }
}
long long clear() {
  fwrite(out, 1, itr2, stdout);
  itr2 = 0;
  return 0;
}
long long getint() {
  long long r = 0;
  bool ng = 0;
  char c;
  c = get();
  while (c != '-' && (c < '0' || c > '9')) c = get();
  if (c == '-') ng = 1, c = get();
  while (c >= '0' && c <= '9') r = r * 10 + c - '0', c = get();
  return ng ? -r : r;
}
string getstr() {
  string ret = "";
  char ch = get();
  while (ch == ' ' || ch == '\n') ch = get();
  while (ch != ' ' && ch != '\n') ret.push_back(ch), ch = get();
  return ret;
}
void putstr(string s) {
  for (long long i = 0; i < s.size(); i++) put(s[i]);
}
void putint(long long x) {
  if (x < 0) {
    put('-');
    x = -x;
  }
  if (x == 0) {
    put('0');
    return;
  }
  char c[20];
  long long pos = 0;
  while (x) {
    c[pos++] = '0' + x % 10;
    x /= 10;
  }
  for (long long i = pos - 1; i >= 0; i--) put(c[i]);
}
void getarr(long long arrname[], long long size) {
  for (long long i = 0; i < size; i++) arrname[i] = getint();
}
}  // namespace fastio
using namespace fastio;
struct UFS {
  long long par[200005];
  void init(long long n) {
    for (long long i = 0; i <= n; i++) par[i] = i;
  }
  long long find(long long x) {
    return x == par[x] ? x : par[x] = find(par[x]);
  }
  void unite(long long x, long long y) { par[find(x)] = find(y); }
  bool same(long long x, long long y) { return find(x) == find(y); }
} uf;
long long n, d;
long long a[200005];
struct Edge {
  long long val;
  long long x, y;
};
bool operator<(Edge a, Edge b) { return a.val < b.val; }
vector<Edge> edge;
void solve(long long l, long long r) {
  if (l == r) return;
  long long mid = l + r >> 1;
  solve(l, mid);
  solve(mid + 1, r);
  long long mn = inf, pl = -1;
  for (long long i = l; i <= mid; i++) {
    long long vl = a[i] - d * i;
    if (mn > vl) {
      mn = vl;
      pl = i;
    }
  }
  mn = inf;
  long long pr = -1;
  for (long long i = mid + 1; i <= r; i++) {
    long long vr = a[i] + d * i;
    if (mn > vr) {
      mn = vr;
      pr = i;
    }
  }
  for (long long i = l; i <= mid; i++) {
    long long vl = a[i] - d * i;
    long long vr = a[pr] + d * pr;
    edge.push_back((Edge){vl + vr, i, pr});
  }
  for (long long i = mid + 1; i <= r; i++) {
    long long vl = a[pl] - d * pl;
    long long vr = a[i] + d * i;
    edge.push_back((Edge){vl + vr, pl, i});
  }
}
signed main() {
  n = getint();
  d = getint();
  for (long long i = 0; i < n; i++) a[i] = getint();
  solve(0, n - 1);
  sort(edge.begin(), edge.end());
  uf.init(n + 2);
  long long ans = 0;
  for (long long i = 0; i < edge.size(); i++) {
    if (!uf.same(edge[i].x, edge[i].y)) {
      uf.unite(edge[i].x, edge[i].y);
      ans += edge[i].val;
    }
  }
  cout << ans << endl;
  return 0;
}
