#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e5 + 9;
int par[N];
long long a[N];
int fin(int x) {
  if (par[x] == x) return x;
  return par[x] = fin(par[x]);
}
bool unite(int a, int b) {
  a = fin(a);
  b = fin(b);
  if (a == b) return false;
  if (rand() % 2)
    par[a] = b;
  else
    par[b] = a;
  return true;
}
struct Edge {
  int ai;
  int bi;
  long long wi;
  bool operator<(const Edge &T) const { return wi < T.wi; }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long d;
  int n;
  cin >> n >> d;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    par[i] = i;
  }
  pair<long long, int> best = make_pair(a[1] - d, 1);
  vector<Edge> shit;
  for (int i = 2; i <= n; i++) {
    shit.push_back({best.second, i, a[i] + i * 1ll * d + best.first});
    best = min(best, make_pair(a[i] - i * 1ll * d, i));
  }
  best = make_pair(a[n] + n * 1ll * d, n);
  for (int i = n - 1; i >= 1; i--) {
    shit.push_back({best.second, i, a[i] - i * 1ll * d + best.first});
    best = min(best, make_pair(a[i] + i * 1ll * d, i));
  }
  sort(shit.begin(), shit.end());
  long long ans = 0;
  for (auto p : shit) {
    ans += p.wi * unite(p.ai, p.bi);
  }
  cout << ans << "\n";
  return 0;
}
