#include <bits/stdc++.h>
using namespace std;
char _buf[1048576], *_is = _buf, *_it = _buf;
inline char rdc() {
  if (_is == _it) _it = (_is = _buf) + fread(_buf, 1, 1048576, stdin);
  return *_is++;
}
inline void rdi(int &x) {
  int f = 0;
  register char ch = rdc();
  while ((ch < '0' or ch > '9') and (ch ^ '-')) ch = rdc();
  if (ch == '-') f = 1, ch = rdc();
  while (ch >= '0' and ch <= '9')
    x = (x << 3) + (x << 1) + (ch ^ '0'), ch = rdc();
  if (f) x = -x;
}
inline void rdi(long long &x) {
  long long f = 0;
  register char ch = rdc();
  while ((ch < '0' or ch > '9') and (ch ^ '-')) ch = rdc();
  if (ch == '-') f = 1, ch = rdc();
  while (ch >= '0' and ch <= '9')
    x = (x << 3) + (x << 1) + (ch ^ '0'), ch = rdc();
  if (f) x = -x;
}
inline void write(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
inline void _write(int x) {
  write(x);
  putchar(' ');
}
inline void print(int x) {
  write(x);
  putchar('\n');
}
inline void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
inline void _write(long long x) {
  write(x);
  putchar(' ');
}
inline void print(long long x) {
  write(x);
  putchar('\n');
}
struct ufs {
  int par[200200];
  inline void init(int _n) {
    for (int i = 0; i < _n; ++i) par[i] = i;
  }
  inline int find(int now) {
    if (par[now] == now) return now;
    return par[now] = find(par[now]);
  }
  inline bool unite(int a, int b) {
    int Pa(find(a)), Pb(find(b));
    if (Pa == Pb) return false;
    par[Pa] = Pb;
    return true;
  }
} my;
int n, d;
int a[200200];
vector<pair<int, pair<int, int> > > v;
inline void solve(int l, int r) {
  if (l >= r) return;
  int m((l + r) >> 1);
  int mnL(1e9), mnposL;
  for (int i = l; i <= m; ++i) {
    if (a[i] - d * (i + 1) < mnL) {
      mnL = a[i] - d * (i + 1);
      mnposL = i;
    }
  }
  int mnR(1e9), mnposR;
  for (int i = m + 1; i <= r; ++i) {
    if (a[i] + d * (i + 1) < mnR) {
      mnR = a[i] + d * (i + 1);
      mnposR = i;
    }
  }
  for (int i = m + 1; i <= r; ++i)
    v.push_back(make_pair(mnL + a[i] + d * (i + 1), make_pair(mnposL, i)));
  for (int i = l; i <= m; ++i)
    v.push_back(make_pair(mnR + a[i] - d * (i + 1), make_pair(i, mnposR)));
  solve(l, m);
  solve(m + 1, r);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> d;
  my.init(n);
  int i, j;
  for (i = 0; i < n; ++i) cin >> a[i];
  solve(0, n - 1);
  sort(v.begin(), v.end());
  int ans(0);
  for (i = 0; i < v.size(); ++i) {
    if (my.find(v[i].second.first) != my.find(v[i].second.second)) {
      ans += v[i].first;
      my.unite(v[i].second.first, v[i].second.second);
    }
  }
  cout << ans << endl;
  return 0;
}
