#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int N = 2e5;
ll le[N + 1], ri[N + 1];
pair<ll, int> le2[N + 1], ri2[N + 1];
ll a[N];
ll n, d;
template <class T, class U>
inline void smin(T &a, const U &b) {
  a = a < (T)b ? a : b;
}
template <class T, class U>
inline void smax(T &a, const U &b) {
  a = a < (T)b ? b : a;
}
struct UF {
  int n;
  vector<int> par;
  UF(int n) : n(n), par(n, -1) {}
  int find(int x) { return par[x] < 0 ? x : par[x] = find(par[x]); }
  int size(int x) { return -par[find(x)]; }
  bool same(int a, int b) { return find(a) == find(b); }
  void unite(int a, int b) {
    a = find(a);
    b = find(b);
    if (a == b) return;
    if (par[a] < par[b]) swap(a, b);
    par[b] += par[a];
    par[a] = b;
  }
};
int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    le[i] = ri[i] = a[i];
    le[i] += -i * d;
    ri[i] += i * d;
    le2[i] = make_pair(le[i], i);
    ri2[i] = make_pair(ri[i], i);
  }
  for (int i = 1; i < n; i++) smin(le2[i], le2[i - 1]);
  for (int i = n - 2; i >= 0; i--) smin(ri2[i], ri2[i + 1]);
  ll ans = 0;
  vector<tuple<ll, int, int>> v;
  for (int i = 0; i < n; i++) {
    if (i != 0) v.emplace_back(le2[i - 1].first + ri[i], le2[i - 1].second, i);
    if (i != n - 1)
      v.emplace_back(ri2[i + 1].first + le[i], ri2[i + 1].second, i);
  }
  sort(v.begin(), v.end());
  UF uf(n);
  for (int i = 0; i < v.size(); i++) {
    ll z;
    int x, y;
    tie(z, x, y) = v[i];
    if (!uf.same(x, y)) {
      uf.unite(x, y);
      ans += z;
    }
  }
  cout << ans << endl;
  return 0;
}
