#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, int>;
using T = tuple<ll, int, int>;
const int MX = 200005;
int n, p[MX], x, y, t;
ll d, v, ans, lo[MX], ro[MX];
P l[MX], r[MX];
T tp[MX * 2];
int find(int x) { return (p[x] < 0 ? x : p[x] = find(p[x])); }
int main() {
  scanf("%d%lld", &n, &d);
  for (int i = 0; i < (n); i++) {
    scanf("%lld", &v);
    r[i] = P(ro[i] = i * d + v, i);
    l[i] = P(lo[i] = -i * d + v, i);
  }
  sort(r, r + n);
  sort(l, l + n);
  for (int i = 0; i < (n); i++)
    for (tie(v, x) = r[i]; y < x; y++) tp[t++] = T(v + lo[y], x, y);
  for (int i = 0; i < (n); i++)
    for (tie(v, x) = l[i]; y > x; y--) tp[t++] = T(v + ro[y], x, y);
  fill(p, p + n, -1);
  sort(tp, tp + t);
  for (int i = 0; i < (t); i++) {
    tie(v, x, y) = tp[i];
    x = find(x);
    y = find(y);
    if (x != y) {
      if (p[x] > p[y]) swap(x, y);
      p[x] += p[y];
      p[y] = x;
      ans += v;
    }
  }
  printf("%lld\n", ans);
}
