#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;
int A[N];
int f[N];
int find(int x) {
  if (f[x] != f[f[x]]) f[x] = find(f[x]);
  return f[x];
}
int main() {
  int n;
  long long D;
  scanf("%d%lld", &n, &D);
  for (int i = 0; i < n; ++i) scanf("%d", &A[i]);
  long long best = 1LL << 60, best_k = -1;
  vector<pair<int, int> > e;
  for (int i = 0; i < n; ++i) {
    if (best_k >= 0) {
      e.emplace_back(best_k, i);
    }
    long long cur = A[i] - D * i;
    if (best > cur) {
      best = cur;
      best_k = i;
    }
  }
  best = 1LL << 60;
  best_k = -1;
  for (int i = n - 1; i >= 0; --i) {
    if (best_k >= 0) {
      e.emplace_back(best_k, i);
    }
    long long cur = A[i] + D * i;
    if (best > cur) {
      best = cur;
      best_k = i;
    }
  }
  sort(e.begin(), e.end(),
       [&](const pair<int, int>& u, const pair<int, int>& v) {
         long long L = A[u.first] + A[u.second] + D * abs(u.first - u.second);
         long long R = A[v.first] + A[v.second] + D * abs(v.first - v.second);
         return L < R;
       });
  for (int i = 0; i < n; ++i) f[i] = i;
  long long ret = 0, cnt = 0;
  for (auto& it : e) {
    int x = it.first, y = it.second;
    int rx = find(x), ry = find(y);
    if (rx != ry) {
      ++cnt;
      ret += A[x] + A[y] + D * abs(x - y);
      f[ry] = rx;
    }
    if (cnt == n - 1) break;
  }
  printf("%lld\n", ret);
  return 0;
}
