#include <bits/stdc++.h>
using namespace std;
long long mod(long long a) {
  long long c = a % (long long)(1E9 + 7);
  if (c >= 0)
    return c;
  else
    return c + (long long)(1E9 + 7);
}
long long inf = (long long)1E12;
long long max(long long a, long long b) {
  if (a < b)
    return b;
  else
    return a;
}
long long min(long long a, long long b) {
  if (a > b)
    return b;
  else
    return a;
}
void Max(long long* pos, long long val) { *pos = max(*pos, val); }
void Min(long long* pos, long long val) { *pos = min(*pos, val); }
void Add(long long* pos, long long val) { *pos = mod(*pos + val); }
const long double EPS = 1E-8;
const long long MAX_N = 1 << 20;
long long n, dat1[2 * MAX_N - 1], dat2[2 * MAX_N - 1];
void init1(long long n_) {
  n = 1;
  while (n < n_) n *= 2;
  for (long long i = 0; i < 2 * n - 1; i++) dat1[i] = inf;
}
void update1(long long k, long long a) {
  k += n - 1;
  dat1[k] = a;
  while (k > 0) {
    k = (k - 1) / 2;
    dat1[k] = min(dat1[k * 2 + 1], dat1[k * 2 + 2]);
  }
}
long long query1(long long a, long long b, long long k, long long l,
                 long long r) {
  if (r <= a || b <= l) return inf;
  if (a <= l && r <= b)
    return dat1[k];
  else {
    long long vl = query1(a, b, k * 2 + 1, l, (l + r) / 2);
    long long vr = query1(a, b, k * 2 + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
}
long long que1(long long a, long long b) { return query1(a, b, 0, 0, n); }
void init2(long long n_) {
  n = 1;
  while (n < n_) n *= 2;
  for (long long i = 0; i < 2 * n - 1; i++) dat2[i] = inf;
}
void update2(long long k, long long a) {
  k += n - 1;
  dat2[k] = a;
  while (k > 0) {
    k = (k - 1) / 2;
    dat2[k] = min(dat2[k * 2 + 1], dat2[k * 2 + 2]);
  }
}
long long query2(long long a, long long b, long long k, long long l,
                 long long r) {
  if (r <= a || b <= l) return inf;
  if (a <= l && r <= b)
    return dat2[k];
  else {
    long long vl = query2(a, b, k * 2 + 1, l, (l + r) / 2);
    long long vr = query2(a, b, k * 2 + 2, (l + r) / 2, r);
    return min(vl, vr);
  }
}
long long que2(long long a, long long b) { return query2(a, b, 0, 0, n); }
int main() {
  long long n, d;
  cin >> n >> d;
  long long a[n];
  for (long long i = 0; i <= n - 1; i++) cin >> a[i];
  init1(n);
  init2(n);
  for (long long i = 0; i <= n - 1; i++) {
    update1(i, -i * d + a[i]);
  }
  for (long long i = 0; i <= n - 1; i++) {
    update2(i, i * d + a[i]);
  }
  vector<pair<long long, long long> > v;
  for (long long i = 0; i <= n - 1; i++) {
    long long m1, m2;
    m1 = que1(0, i) + i * d;
    m2 = que2(i + 1, n) - i * d;
    v.push_back(pair<long long, long long>(a[i] + min(m1, m2), i));
  }
  sort(v.begin(), v.end());
  long long ans = 0;
  for (long long i = 1; i <= n - 1; i++) {
    ans += v[i].first;
  }
  cout << ans << endl;
  return 0;
}
