#include <bits/stdc++.h>
using namespace std;
const int mx = 212345;
const long long inf = 0x3f3f3f3f3f3f3f3f;
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]; }
int n;
pair<long long, int> t1[2 * mx], t2[2 * mx];
void update(pair<long long, int> t[], int p, pair<long long, int> value) {
  for (t[p += n] = value; p > 1; p >>= 1) t[p >> 1] = min(t[p], t[p ^ 1]);
}
pair<long long, int> query(pair<long long, int> t[], int l, int r) {
  pair<long long, int> res = {inf, -1};
  for (l += n, r += n + 1; l < r; l >>= 1, r >>= 1) {
    if (l & 1) res = min(res, t[l++]);
    if (r & 1) res = min(res, t[--r]);
  }
  return res;
}
vector<int> G[mx];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int m, D;
  cin >> n >> D;
  for (int i = 0; i < n; i++) {
    cin >> U[i];
  }
  int ntrees = n;
  for (int i = 0; i < n; i++) {
    update(t1, i, pair<long long, int>{1LL * i * D + U[i], i});
    update(t2, i, pair<long long, int>{1LL * (n - 1 - i) * D + U[i], i});
  }
  iota(arr, arr + n, 0);
  unsigned long long ans = 0;
  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]) {
        update(t1, a, pair<long long, int>{inf, a});
        update(t2, a, pair<long long, int>{inf, a});
      }
      for (auto a : G[i]) {
        pair<long long, int> r1 = query(t1, a + 1, n - 1);
        r1.first += -1LL * a * D + U[a];
        pair<long long, int> r2 = query(t2, 0, a - 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]) {
        update(t1, a, pair<long long, int>{1LL * a * D + U[a], a});
        update(t2, a, pair<long long, int>{1LL * (n - 1 - a) * D + U[a], a});
      }
    }
    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;
}
