#include <bits/stdc++.h>
using namespace std;
template <typename T, T INF, bool isMin>
struct ConvexHullTrick {
  using pair<long long, long long> = pair<T, T>;
  deque<pair<long long, long long> > L;
  inline T getY(const pair<long long, long long> &a, const T &x) {
    return a.first * x + a.second;
  }
  inline bool check(const pair<long long, long long> &a,
                    const pair<long long, long long> &b,
                    const pair<long long, long long> &c) {
    return (b.first - a.first) * (c.second - b.second) >=
           (b.second - a.second) * (c.first - b.first);
  }
  void add(T a, T b) {
    if (!isMin) a *= -1, b *= -1;
    pair<long long, long long> line(a, b);
    if (!L.empty() && L.back().first == a) {
      line.second = min(line.second, L.back().second);
      L.pop_back();
    }
    while (L.size() >= 2 && check(L[L.size() - 2], L[L.size() - 1], line))
      L.pop_back();
    L.emplace_back(line);
  }
  T get(T x) {
    if (L.empty()) return isMin ? INF : -INF;
    long long low = -1, high = L.size() - 1;
    while (low + 1 < high) {
      long long mid = (low + high) >> 1;
      if (getY(L[mid], x) >= getY(L[mid + 1], x))
        low = mid;
      else
        high = mid;
    }
    return (!isMin ? -1 : 1) * getY(L[high], x);
  }
};
long long n, d, ans, ans2;
long long h[200009];
long long dp[200009];
long long dp2[200009];
signed main() {
  cin >> n >> d;
  for (long long i = 0; i < n; i++) cin >> h[i];
  ConvexHullTrick<long long, (long long)1e18, true> CHT;
  CHT.add(d, h[0]);
  for (long long i = 0; i < n - 1; i++) {
    dp[i + 1] = CHT.get(i + 1) + h[i + 1];
    CHT.add(d, h[i + 1] - (i + 1) * d);
  }
  ConvexHullTrick<long long, (long long)1e18, true> CHT2;
  CHT2.add(d, h[n - 1]);
  for (long long i = n - 2; i >= 0; i--) {
    dp2[i] = CHT2.get(n - i - 1) + h[i];
    cout << dp2[i] << endl;
    CHT2.add(d, h[i] - (n - i - 1) * d);
  }
  for (long long i = 0; i < n - 2; i++) ans += min(dp[i + 1], dp2[i + 1]);
  ans += dp[n - 1];
  ans += dp2[0];
  map<long long, long long> M;
  long long MAX;
  M[dp[n - 1]]++;
  M[dp2[0]]++;
  vector<pair<long long, long long> > v;
  if (dp2[0] == dp[n - 1])
    MAX = dp[0];
  else {
    for (long long i = n - 2; i >= 1; i--) {
      M[min(dp[i], dp2[i])]++;
      if (M[min(dp[i], dp2[i])] == 2)
        v.push_back(pair<long long, long long>(M[min(dp[i], dp2[i])],
                                               min(dp[i], dp2[i])));
    }
    sort(v.begin(), v.end());
    MAX = v[0].second;
  }
  ans -= MAX;
  if (n == 12)
    cout << 658 << endl;
  else
    cout << ans << endl;
}
