#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
inline bool chmax(A &a, B b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename A, typename B>
inline bool chmin(A &a, B b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll << 30;
constexpr ll longINF = 1ll << 60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
struct UnionFind {
  vector<int> par, rank;
  UnionFind(int n) {
    par.resize(n);
    rank.resize(n);
    for (int i = (0); i < (n); i++) {
      par[i] = i;
      rank[i] = 0;
    }
  }
  int operator[](int x) { return find(x); }
  int find(int x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) swap(x, y);
    par[y] = x;
    if (rank[x] == rank[y]) rank[x]++;
  }
  bool same(int x, int y) { return find(x) == find(y); }
};
ll N, D;
ll A[212345];
int main() {
  cin >> N >> D;
  for (int i = (0); i < (N); i++) scanf("%lld", A + i);
  using pll = pair<ll, ll>;
  using ll3 = tuple<ll, ll, ll>;
  set<pii> itv_ss;
  multiset<pll> ss;
  for (int i = N - 1; i >= 0; i--) ss.insert(pll(i * D + A[i], i));
  for (int i = (0); i < (N - 1); i++) {
    auto it = ss.begin();
    if (it->second == i) ++it;
    itv_ss.insert(pii(it->second, i));
    ss.erase(pll(i * D + A[i], i));
  }
  ss.clear();
  for (int i = (0); i < (N); i++) ss.insert(pll((N - i - 1) * D + A[i], i));
  for (int i = N - 1; i > 0; i--) {
    auto it = ss.begin();
    if (it->second == i) ++it;
    itv_ss.insert(pii(it->second, i));
    ss.erase(pll((N - i - 1) * D + A[i], i));
  }
  vector<ll3> v;
  for (pii cur : itv_ss)
    v.emplace_back(
        abs(cur.first - cur.second) * D + A[cur.first] + A[cur.second],
        cur.first, cur.second);
  sort(begin(v), end(v));
  UnionFind uf(N);
  ll ans = 0;
  for (ll3 &cur : v) {
    ll cost, x, y;
    tie(cost, x, y) = cur;
    if (uf[x] == uf[y]) continue;
    uf.unite(x, y);
    ans += cost;
  }
  cout << ans << endl;
  return 0;
}
