#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll MOD = 1000000007;
const ll root = 62;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
ll binpow(ll a, ll b) {
  ll res = 1;
  while (b) {
    if (b & 1) res = (res * a) % MOD;
    a = (a * a) % MOD;
    b >>= 1;
  }
  return res;
}
ll modInv(ll a) { return binpow(a, MOD - 2); }
const double PI = acos(-1);
const double eps = -1e6;
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll NINFLL = 0xc0c0c0c0c0c0c0c0;
const int mxN = 200001;
ll arr[mxN];
int n;
ll d;
int dsu[mxN];
int find(int a) { return a == dsu[a] ? a : dsu[a] = find(dsu[a]); }
bool merge(int a, int b) {
  a = find(a);
  b = find(b);
  if (a == b) return false;
  dsu[b] = a;
  return true;
}
vector<pair<ll, pair<int, int>>> edges;
void solve(int l, int r) {
  if (r - l < 1) return;
  int mid = (l + r) / 2;
  pair<ll, int> mn1 = {INFLL, 0};
  pair<ll, int> mn2 = {INFLL, 0};
  for (int i = (l); i < (mid + 1); ++i) {
    mn1 = min(mn1, {arr[i] - d * i, i});
  }
  for (int i = (mid + 1); i < (r + 1); ++i) {
    mn2 = min(mn2, {arr[i] + d * i, i});
  }
  for (int i = (0); i < (mid + 1); ++i) {
    edges.push_back({mn2.first + arr[i] - d * i, {mn2.second, i}});
  }
  for (int i = (mid + 1); i < (r + 1); ++i) {
    edges.push_back({mn1.first + arr[i] + d * i, {mn1.second, i}});
  }
  solve(l, mid);
  solve(mid + 1, r);
}
int main() {
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  cin.tie(0)->sync_with_stdio(0);
  cin >> n >> d;
  for (int i = (0); i < (n); ++i) {
    dsu[i] = i;
  }
  ll ans = 0;
  for (int i = (0); i < (n); ++i) {
    cin >> arr[i];
  }
  solve(0, n - 1);
  sort(edges.begin(), edges.end());
  for (auto p : edges) {
    if (merge(p.second.first, p.second.second)) {
      ans += p.first;
    }
  }
  cout << ans << "\n";
  return 0;
}
