#include <bits/stdc++.h>
using namespace std;
bool isZero(int i) { return i == 0; }
int main(int argc, char** argv) {
  int N, D;
  cin >> N >> D;
  std::vector<int> V(N);
  std::vector<int> Ans;
  for (int i = 0; i < N; ++i) cin >> V[i];
  for (int i = 0; i < N; ++i) {
    for (int j = i + 1; j < N; ++j) {
      Ans.push_back((abs(i - j) * D) + V[i] + V[j]);
    }
  }
  auto newIter = std::remove_if(Ans.begin(), Ans.end(), isZero);
  Ans.resize(newIter - Ans.begin());
  std::sort(Ans.begin(), Ans.end());
  int lnAns = 0;
  for (int i = 0; i < N - 1; ++i) lnAns += Ans[i];
  std::cout << lnAns;
}
