#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 1010000000;
const double EPS = 1e-10;
const array<pair<long long, long long>, 4> fd{
    make_pair(1, 0), make_pair(-1, 0), make_pair(0, 1), make_pair(0, -1)};
signed main() {
  long long n, d;
  cin >> n >> d;
  long long a[200000];
  for (long long i = (0); i < (n); i++) cin >> a[i];
  long long ans = d * (n - 1) + a[0] + a[n - 1];
  for (long long i = (1); i < (n - 1); i++) ans += 2 * a[i];
  cout << ans << endl;
  pair<long long, long long> toF[200000], toB[200000];
  for (long long i = (0); i < (n); i++) {
    toF[i] = {d * i + a[0] - a[i], i};
    toB[i] = {d * (n - i - 1) + a[n - 1] - a[i], i};
  }
  sort(toF, toF + n);
  sort(toB, toB + n);
  if (toF[0].second != toB[0].second) {
    ans += min((long long)0, toF[0].first);
    ans += min((long long)0, toB[0].first);
  } else if (toF[1].first < toB[1].first) {
    ans += min((long long)0, toF[1].first);
    ans += min((long long)0, toB[0].first);
  } else {
    ans += min((long long)0, toF[0].first);
    ans += min((long long)0, toB[1].first);
  }
  cout << ans << endl;
}
