#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int N, D;
  cin >> N >> D;
  vector<int> A;
  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    A.push_back(tmp);
  }
  long long ans = (long long)9223372036854775807;
  for (int i = 0; i < N; i++) {
    int now = i;
    long long answer = 0;
    for (int i = now + 1; i < N; i++) {
      answer += (i - now) * D + A[now] + A[i];
      if ((now - i) * D - A[now] + A[i] < 0) {
        now = i;
      }
    }
    for (int i = now - 1; i >= 0; i--) {
      answer += (now - i) * D + A[now] + A[i];
      if ((i - now) * D - A[now] + A[i] < 0) {
        now = i;
      }
    }
    ans = min(ans, answer);
  }
  cout << ans << endl;
  return 0;
}
