#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pli = pair<ll, int>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdi = pair<double, int>;
using pdd = pair<double, double>;
int N, D;
vector<int> A;
int main() {
  cin >> N >> D;
  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    A.push_back(tmp);
  }
  set<pli> rDpAr;
  for (int r = 0; r < N; r++) {
    rDpAr.insert(pli(r * D + A[r], r));
  }
  ll m = 0;
  for (int l = 0; l < N - 1; l++) {
    rDpAr.erase(pli(l * D + A[l], l));
    ll test = rDpAr.rbegin()->first;
    ll test2 = (A[l] - l * D);
    m = max(m, (rDpAr.rbegin())->first + (A[l] - l * D));
  }
  ll sumA = 0;
  for (int i = 0; i < N; i++) {
    sumA += A[i];
  }
  ll ans = 2 * (N - 1) * D + 2 * sumA - m;
  cout << ans << endl;
}
