#include <bits/stdc++.h>
using namespace std;
pair<int, int> t;
int A[1010];
int nearest[1010];
int N, K;
int done[1010];
vector<int> V;
int val(int x, int y) { return A[x] + A[y] + K * abs(y - x); }
int main() {
  cin >> N >> K;
  for (int i = 1; i <= N; ++i) cin >> A[i];
  t = make_pair(1e9, -1);
  for (int i = N; i >= 1; --i) {
    nearest[i] = t.second;
    if (K * i + A[i] < t.first) {
      t = make_pair(K * i + A[i], i);
    }
  }
  int cur = 1;
  V.emplace_back(1);
  while (nearest[cur] != -1) {
    done[cur] = 1;
    cur = nearest[cur];
    V.emplace_back(cur);
  }
  done[cur] = 1;
  int ans = 0;
  int bestp = A[1] - K;
  for (int i = 1; i < (long long)V.size(); ++i) {
    ans += bestp + V[i] * K + A[V[i]];
    bestp = min(bestp, A[V[i]] - K * V[i]);
  }
  for (int i = 0; i < (long long)V.size() - 1; ++i) {
    for (int j = V[i] + 1; j < V[i + 1]; ++j) {
      ans += min(val(V[i], j), val(V[i + 1], j));
    }
  }
  cout << ans;
}
