#include <bits/stdc++.h>
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;
const int MAX_N = 2 * 1e5 + 1;
#pragma warning(disable : 4996)
using namespace std;
long long n;
struct RMQ {
  long long n;
  pair<long long, long long> dat[MAX_N * 2 - 1];
  void init(long long& n_) {
    n = 1;
    while (n < n_) n *= 2;
    for (long long i = 0; i < (2 * n - 1); i++)
      dat[i] = {LLONG_MAX / 3, LLONG_MAX / 3};
  }
  void update(long long i, pair<long long, long long> x) {
    i += n - 1;
    dat[i] = x;
    while (i > 0) {
      i = (i - 1) / 2;
      dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]);
    }
  }
  pair<long long, long long> query(long long a, long long b, long long k,
                                   long long l, long long r) {
    if (r <= a || b <= l) return {LLONG_MAX / 3, LLONG_MAX / 3};
    if (a <= l && r <= b)
      return dat[k];
    else {
      pair<long long, long long> vl =
          query(a, b, k * 2 + 1, l, l + (r - l) / 2);
      pair<long long, long long> vr =
          query(a, b, k * 2 + 2, l + (r - l) / 2, r);
      return min(vl, vr);
    }
  }
  pair<long long, long long> query(long long a, long long b) {
    return query(a, b, 0, 0, n);
  }
};
long long a[200000];
bool used[200000];
signed main() {
  long long d;
  cin >> n >> d;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  RMQ X, Y;
  X.init(n);
  Y.init(n);
  for (long long i = 0; i < n; i++) {
    X.update(i, {d * i + a[i], i});
    Y.update(i, {d * (n - i - 1) + a[i], i});
  }
  long long ans = 0;
  priority_queue<pair<long long, pair<long long, long long>>,
                 vector<pair<long long, pair<long long, long long>>>,
                 greater<pair<long long, pair<long long, long long>>>>
      Q;
  Q.push({0, {0, 0}});
  X.update(0, {LLONG_MAX / 3, 0});
  Y.update(0, {LLONG_MAX / 3, 0});
  while (Q.size()) {
    pair<long long, pair<long long, long long>> t = Q.top();
    Q.pop();
    pair<long long, long long> k = X.query(0, t.second.second + 1);
    if (t.second.first == t.second.second) goto l;
    if (!used[k.second]) {
      Q.push({abs(t.second.second - k.second) * d + a[t.second.second] +
                  a[k.second],
              {k.second, t.second.second}});
    }
    k = Y.query(t.second.second, n);
    if (!used[k.second]) {
      Q.push({abs(t.second.second - k.second) * d + a[t.second.second] +
                  a[k.second],
              {k.second, t.second.second}});
    }
    if (used[t.second.first]) {
      continue;
    }
  l:;
    ans += t.first;
    used[t.second.first] = true;
    X.update(t.second.first, {LLONG_MAX / 3, t.second.first});
    Y.update(t.second.first, {LLONG_MAX / 3, t.second.first});
    k = X.query(0, t.second.first + 1);
    if (!used[k.second]) {
      Q.push(
          {abs(t.second.first - k.second) * d + a[t.second.first] + a[k.second],
           {k.second, t.second.first}});
    }
    k = Y.query(t.second.first, n);
    if (!used[k.second]) {
      Q.push(
          {abs(t.second.first - k.second) * d + a[t.second.first] + a[k.second],
           {k.second, t.second.first}});
    }
  }
  cout << ans << endl;
}
