#include <bits/stdc++.h>
using namespace std;
struct UnionFind {
  vector<int> data;
  UnionFind(int sz) { data.assign(sz, -1); }
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return (false);
    if (data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
  int find(int k) {
    if (data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
  int size(int k) { return (-data[find(k)]); }
};
template <typename T, typename F>
T boruvka(int N, F f) {
  vector<int> rev(N), belong(N);
  UnionFind uf(N);
  T ret = T();
  while (uf.size(0) != N) {
    int ptr = 0;
    for (int i = 0; i < N; i++) {
      if (uf.find(i) == i) {
        belong[i] = ptr++;
        rev[belong[i]] = i;
      }
    }
    for (int i = 0; i < N; i++) {
      belong[i] = belong[uf.find(i)];
    }
    auto v = f(ptr, belong);
    bool update = false;
    for (int i = 0; i < ptr; i++) {
      if (~v[i].second && uf.unite(rev[i], rev[v[i].second])) {
        ret += v[i].first;
        update = true;
      }
    }
    if (!update) return -1;
  }
  return ret;
}
using int64 = long long;
const int INF = 1LL << 60;
int main() {
  int64 N, D, A[200000];
  cin >> N >> D;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  using pii = pair<pair<int64, int>, pair<int64, int> >;
  using pi = pair<int64, int>;
  auto f1 = [](pii a, const pi &p) {
    if (a.first.second == p.second) {
      a.first.first = min(a.first.first, p.first);
    } else if (a.second.second == p.second) {
      a.second.first = min(a.second.first, p.first);
      if (a.first > a.second) swap(a.first, a.second);
    } else {
      if (p < a.first) {
        a.second = a.first;
        a.first = p;
      } else if (p < a.second) {
        a.second = p;
      }
    }
    return a;
  };
  function<vector<pair<int64, int> >(int, vector<int>)> f =
      [&](int sz, vector<int> belong) {
        vector<pair<int64, int> > ret(sz, {INF, -1});
        {
          pii uku(make_pair(INF, -1), make_pair(INF, -1));
          for (int i = 0; i < N; i++) {
            auto e = uku.first.second == belong[i] ? uku.second : uku.first;
            e.first += A[i];
            e.first += i * D;
            ret[belong[i]] = min(ret[belong[i]], e);
            uku = f1(uku, pi(-i * D + A[i], belong[i]));
          }
        }
        {
          pii uku(make_pair(INF, -1), make_pair(INF, -1));
          for (int i = N - 1; i >= 0; i--) {
            auto e = uku.first.second == belong[i] ? uku.second : uku.first;
            e.first += A[i];
            e.first -= i * D;
            ret[belong[i]] = min(ret[belong[i]], e);
            uku = f1(uku, pi(i * D + A[i], belong[i]));
          }
        }
        return ret;
      };
  cout << boruvka<int64, decltype(f)>(N, f) << endl;
}
