#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, d;
  cin >> n >> d;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  long long ans = -1;
  for (int i = 1; i < n; i++) {
    long long cost = i * d + a[0] + a[i];
    for (int j = 1; j < n; j++) {
      if (j != i) {
        int costAdd = abs(i - j) * d + a[i] + a[j];
        for (int k = 0; k < j; k++) {
          costAdd = min(costAdd, abs(k - j) * d + a[k] + a[j]);
        }
        cost += costAdd;
      }
    }
    if (ans == -1 || ans > cost) ans = cost;
  }
  cout << ans << "\n";
  return 0;
}
