#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
const long long int mod = 1000000007;
const long long int big = 2.19e18 + 1;
const long double pai = 3.141592653589793238462643383279502884197;
const long double eps = 1e-15;
template <class T, class U>
bool mineq(T& a, U b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T, class U>
bool maxeq(T& a, U b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
long long int gcd(long long int a, long long int b) {
  if (a % b == 0) {
    return b;
  } else
    return gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
  if (a == 0) {
    return b;
  }
  return a / gcd(a, b) * b;
}
template <class T>
void SO(T& ve) {
  sort(ve.begin(), ve.end());
}
template <class T>
void REV(T& ve) {
  reverse(ve.begin(), ve.end());
}
template <class T>
long long int LBI(vector<T>& ar, T in) {
  return lower_bound(ar.begin(), ar.end(), in) - ar.begin();
}
template <class T>
long long int UBI(vector<T>& ar, T in) {
  return upper_bound(ar.begin(), ar.end(), in) - ar.begin();
}
int main(void) {
  cin.tie(0);
  long long int n, D, ans = 0, i;
  cin >> n >> D;
  vector<long long int> a(n);
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> uni(n);
  for (i = 0; i < n; i++) {
    uni[i] = i;
  }
  vector<int> ran(n, 1);
  while (-1) {
    pair<long long int, int> saf = make_pair(a[0], uni[0]);
    pair<long long int, int> sac = make_pair(big, 0);
    vector<tuple<long long int, int, int>> go(n, make_tuple(big, -1, -1));
    for (i = 1; i < n; i++) {
      pair<long long int, int> ter = saf;
      if (saf.second == uni[i]) {
        ter = sac;
      }
      mineq(go[uni[i]],
            make_tuple(ter.first + a[i] + D * i, ter.second, uni[i]));
      if (uni[i] == sac.second) {
        mineq(saf, make_pair(a[i] - D * i, uni[i]));
      } else {
        mineq(sac, make_pair(a[i] - D * i, uni[i]));
        if (saf > sac) {
          swap(saf, sac);
        }
      }
    }
    saf = make_pair(a[n - 1] + D * (n - 1), uni[n - 1]);
    sac = make_pair(big, 0);
    for (i = n - 2; i >= 0; i--) {
      pair<long long int, int> ter = saf;
      if (saf.second == uni[i]) {
        ter = sac;
      }
      mineq(go[uni[i]],
            make_tuple(ter.first + a[i] - D * i, ter.second, uni[i]));
      if (uni[i] == sac.second) {
        mineq(saf, make_pair(a[i] + D * i, uni[i]));
      } else {
        mineq(sac, make_pair(a[i] + D * i, uni[i]));
        if (saf > sac) {
          swap(saf, sac);
        }
      }
    }
    for (auto it : go) {
      long long int cost, x, y;
      tie(cost, x, y) = it;
      if (cost >= big) {
        continue;
      }
      while (x != uni[x]) {
        x = uni[x];
      }
      while (y != uni[y]) {
        y = uni[y];
      }
      if (x == y) {
        continue;
      }
      if (ran[x] < ran[y]) {
        swap(x, y);
      }
      uni[y] = x;
      ran[x] += ran[y];
      ans += cost;
    }
    for (i = 0; i < n; i++) {
      int x = i;
      while (x != uni[x]) {
        x = uni[x];
      }
      uni[i] = x;
    }
    bool can = 1;
    for (i = 1; i < n; i++) {
      if (uni[i] != uni[0]) {
        can = 0;
        break;
      }
    }
    if (can) {
      break;
    }
  }
  cout << ans << endl;
}
