#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); }
};
using pll = pair<ll, ll>;
using ll3 = tuple<ll, ll, ll>;
int N, D;
vector<int> A;
void dfs(int l, int r, vector<ll3> &edge) {
  if (r - l <= 1) return;
  int m = (l + r) / 2;
  pll mn(longINF, -1);
  for (int i = (m); i < (r); ++i) chmin(mn, pll(A[i] + (ll)i * D, i));
  for (int i = (0); i < (m); ++i)
    edge.emplace_back(A[i] - (ll)i * D + mn.first, i, mn.second);
  mn = pll(longINF, -1);
  for (int i = (0); i < (m); ++i) chmin(mn, pll(A[i] - (ll)i * D, i));
  for (int i = (m); i < (r); ++i)
    edge.emplace_back(A[i] + (ll)i * D + mn.first, i, mn.second);
  dfs(l, m, edge);
  dfs(m, r, edge);
}
int main() {
  cin >> N >> D;
  A.resize(N);
  for (int i = (0); i < (N); ++i) scanf("%d", &A[i]);
  vector<ll3> edge;
  dfs(0, N, edge);
  sort(begin(edge), end(edge));
  UnionFind uf(N);
  ll ans = 0;
  for (ll3 &cur : edge) {
    ll cost, x, y;
    tie(cost, x, y) = cur;
    if (uf[x] == uf[y]) continue;
    uf.unite(x, y);
    ans += cost;
  }
  cout << ans << endl;
}
