#include <bits/stdc++.h>
using namespace std;
const int mx = 252345;
const long long inf = 0x3f3f3f3f3f3f3f3f;
struct T {
  pair<long long, int> seg[2 * mx];
  pair<long long, int> query(int L, int R, int idx, int l, int r) {
    int mid = (l + r) / 2, left = 2 * idx + 1, right = 2 * idx + 2;
    if (R < l || L > r) return pair<long long, int>{inf, -1};
    if (L <= l && r <= R) return seg[idx];
    return min(query(L, R, left, l, mid), query(L, R, right, mid + 1, r));
  }
  void update(pair<long long, int> V, int I, int idx, int l, int r) {
    int mid = (l + r) / 2, left = 2 * idx + 1, right = 2 * idx + 2;
    if (l > I || r < I) return;
    if (l == r) {
      seg[idx] = V;
      return;
    }
    update(V, I, left, l, mid);
    update(V, I, right, mid + 1, r);
    seg[idx] = min(seg[left], seg[right]);
  }
} t1, t2;
int arr[mx];
int root(int first) {
  return first == arr[first] ? first : arr[first] = root(arr[first]);
}
void join(int a, int b) {
  a = root(a);
  b = root(b);
  if (a == b) return;
  arr[a] = b;
}
int U[mx], best[mx];
;
long long f(int a, int b, int D) { return 1LL * abs(a - b) * D + U[a] + U[b]; }
vector<int> G[mx];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m, D;
  cin >> n >> D;
  for (int i = 0; i < n; i++) {
    cin >> U[i];
  }
  long long ans = 0;
  int ntrees = n;
  iota(arr, arr + n, 0);
  ans = 0;
  for (int i = 0; i < n; i++) {
    t1.update(pair<long long, int>{1LL * i * D + U[i], i}, i, 0, 0, n - 1);
    t2.update(pair<long long, int>{1LL * (n - 1 - i) * D + U[i], i}, i, 0, 0,
              n - 1);
  }
  while (ntrees > 1) {
    memset(best, -1, sizeof best);
    for (int i = 0; i < n; i++) G[i].clear();
    for (int i = 0; i < n; i++) {
      G[root(i)].push_back(i);
    }
    for (int i = 0; i < n; i++) {
      for (auto a : G[i]) {
        t1.update({inf, a}, a, 0, 0, n - 1);
        t2.update({inf, a}, a, 0, 0, n - 1);
      }
      for (auto a : G[i]) {
        pair<long long, int> r1 = t1.query(a + 1, n - 1, 0, 0, n - 1);
        r1.first += -1LL * a * D + U[a];
        pair<long long, int> r2 = t2.query(0, a - 1, 0, 0, n - 1);
        r2.first += -1LL * (n - 1 - a) * D + U[a];
        pair<long long, int> r = min(r1, r2);
        int b = r.second;
        if (b == -1) continue;
        if (best[a] == -1 || f(a, best[a], D) > r.first) best[a] = b;
        if (best[b] == -1 || f(b, best[b], D) > r.first) best[b] = a;
      }
      for (auto a : G[i]) {
        t1.update(pair<long long, int>{1LL * a * D + U[a], a}, a, 0, 0, n - 1);
        t2.update(pair<long long, int>{1LL * (n - 1 - a) * D + U[a], a}, a, 0,
                  0, n - 1);
      }
    }
    for (int i = 0; i < n; i++) {
      if (~best[i]) {
        int a = root(i);
        int b = root(best[i]);
        if (a == b) continue;
        ans += f(a, best[i], D);
        join(a, b);
        ntrees--;
      }
    }
  }
  cout << ans << endl;
}
