#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;
ll d, v, ans;
P l[MX], r[MX], lo[MX], ro[MX];
priority_queue<T, vector<T>, greater<T>> qu;
int find(int x) { return (p[x] < 0 ? x : p[x] = find(p[x])); }
void uni(T t) {
  tie(v, x, y) = t;
  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;
    n--;
  }
}
int main() {
  scanf("%d%lld", &n, &d);
  for (int i = 0; i < (n); i++) {
    scanf("%lld", &v);
    ro[i] = r[i] = P(i * d + v, i);
    lo[i] = l[i] = P(-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++) qu.push(T(v + lo[y].first, x, y));
  for (int i = 0; i < (n); i++)
    for (tie(v, x) = l[i]; y > x; y--) qu.push(T(v + ro[y].first, x, y));
  fill(p, p + n, -1);
  for (n--; n; qu.pop()) uni(qu.top());
  printf("%lld\n", ans);
}
