#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
const long long inf = 1e18;
int n, D, s[N];
struct node {
  int x, y;
  pair<long long, int> p;
  long long s;
  pair<long long, int> s1[2], s2[2];
} a[N * 5];
void pushup(int t) {
  int l = t << 1, r = l | 1;
  pair<long long, int> pp;
  long long ss;
  for (int d = 0; d <= 1; ++d) a[t].s1[d] = min(a[l].s1[d], a[r].s1[d]);
  for (int d = 0; d <= 1; ++d) a[t].s2[d] = min(a[l].s2[d], a[r].s2[d]);
  if (a[l].s < a[r].s)
    a[t].p = a[l].p, a[t].s = a[l].s;
  else
    a[t].p = a[r].p, a[t].s = a[r].s;
  pp = make_pair(a[l].s2[0].second, a[r].s1[1].second);
  ss = a[l].s2[0].first + a[r].s1[1].first;
  if (ss < a[t].s) a[t].p = pp, a[t].s = ss;
  pp = make_pair(a[r].s1[0].second, a[l].s2[1].second);
  ss = a[l].s2[1].first + a[r].s1[0].first;
  if (ss < a[t].s) a[t].p = pp, a[t].s = ss;
}
void build(int x, int y, int t) {
  a[t].x = x;
  a[t].y = y;
  if (x == y) {
    a[t].p = make_pair(0, 0);
    a[t].s = inf;
    a[t].s1[0] = make_pair(s[x] + (long long)D * x, x);
    a[t].s1[1] = make_pair(inf, 0);
    a[t].s2[0] = make_pair(s[x] - (long long)D * x, x);
    a[t].s2[1] = make_pair(inf, 0);
    return;
  }
  int m = (x + y) >> 1;
  build(x, m, t << 1);
  build(m + 1, y, t << 1 | 1);
  pushup(t);
}
void update(int x, int y, int t, int p) {
  if (x == y) {
    swap(a[t].s1[0], a[t].s1[1]);
    swap(a[t].s2[0], a[t].s2[1]);
    return;
  }
  int m = (x + y) >> 1;
  if (p <= m)
    update(x, m, t << 1, p);
  else
    update(m + 1, y, t << 1 | 1, p);
  pushup(t);
}
int main() {
  cin >> n >> D;
  for (int i = 1; i <= n; ++i) cin >> s[i];
  build(1, n, 1);
  update(1, n, 1, 1);
  long long ans = 0;
  for (int i = 1; i <= n - 1; ++i) {
    pair<long long, int> p = a[1].p;
    long long s = a[1].s;
    update(1, n, 1, p.first);
    ans += s;
  }
  cout << ans << endl;
}
