#include <bits/stdc++.h>
using namespace std;
const long long LINF = 1e18;
template <typename T>
struct SegmentTree {
  using F = function<T(T, T)>;
  long long n;
  F f;
  T ti;
  vector<T> dat;
  SegmentTree(){};
  SegmentTree(F f, T ti) : f(f), ti(ti) {}
  SegmentTree(F f, T ti, long long n_) : f(f), ti(ti) {
    n = 1;
    while (n < n_) n <<= 1;
    dat.assign(n << 1, ti);
  }
  SegmentTree(F f, T ti, const vector<T> &v) : f(f), ti(ti) {
    long long n_ = v.size();
    n = 1;
    while (n < n_) n <<= 1;
    dat.assign(n << 1, ti);
    for (long long i = 0; i < n_; i++) dat[n + i] = v[i];
    for (long long i = n - 1; i; i--)
      dat[i] = f(dat[(i << 1) | 0], dat[(i << 1), 1]);
  }
  T get(long long x) { return dat[x + n]; }
  void init(long long n_) {
    n = 1;
    while (n < n_) n <<= 1;
    dat.assign(n << 1, ti);
  }
  void build(const vector<T> &v) {
    long long n_ = v.size();
    init(n_);
    for (long long i = 0; i < n_; i++) dat[n + i] = v[i];
    for (long long i = n - 1; i; i--)
      dat[i] = f(dat[(i << 1) | 0], dat[(i << 1) | 1]);
  }
  void set_val(long long k, T x) {
    dat[k += n] = x;
    while (k >>= 1) dat[k] = f(dat[(k << 1) | 0], dat[(k << 1) | 1]);
  }
  T query(long long a, long long b) {
    T vl = ti, vr = ti;
    for (long long l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) vl = f(vl, dat[l++]);
      if (r & 1) vr = f(dat[--r], vr);
    }
    return f(vl, vr);
  }
  template <typename C>
  long long find(long long st, C &check, T &acc, long long k, long long l,
                 long long r) {
    if (l + 1 == r) {
      acc = f(acc, dat[k]);
      return check(acc) ? k - n : -1;
    }
    long long m = (l + r) >> 1;
    if (m <= st) return find(st, check, acc, (k << 1) | 1, m, r);
    if (st <= l && !check(f(acc, dat[k]))) {
      acc = f(acc, dat[k]);
      return -1;
    }
    long long vl = find(st, check, acc, (k << 1) | 0, l, m);
    if (~vl) return vl;
    return find(st, check, acc, (k << 1) | 1, m, r);
  }
  template <typename C>
  long long find(long long st, C &check) {
    T acc = ti;
    return find(st, check, acc, 1, 0, n);
  }
};
long long n, d;
vector<long long> v;
auto f = [](pair<long long, long long> a, pair<long long, long long> b) {
  if (a.first < b.first) return a;
  return b;
};
SegmentTree<pair<long long, long long>> seg1(f, pair<long long, long long>(LINF,
                                                                           -1)),
    seg2(f, pair<long long, long long>(LINF, -1));
pair<pair<long long, long long>, long long> asore(long long a) {
  pair<long long, long long> tmp1 = seg1.query(a + 1, n);
  tmp1.first -= a * d;
  pair<long long, long long> tmp2 = seg2.query(0, a);
  tmp2.first -= (n - 1 - a) * d;
  tmp1 = f(tmp1, tmp2);
  tmp1.first += v[a];
  return pair<pair<long long, long long>, long long>(tmp1, a);
}
signed main() {
  cin >> n >> d;
  v.resize(n);
  for (long long i = 0; i < n; i++) cin >> v[i];
  seg1.init(n);
  seg2.init(n);
  for (long long i = 0; i < n; i++)
    seg1.set_val(i, pair<long long, long long>(v[i] + d * i, i));
  for (long long i = 0; i < n; i++)
    seg2.set_val(i, pair<long long, long long>(v[i] + d * (n - 1 - i), i));
  long long ans = 0;
  priority_queue<pair<pair<long long, long long>, long long>,
                 vector<pair<pair<long long, long long>, long long>>,
                 greater<pair<pair<long long, long long>, long long>>>
      que;
  que.push(pair<pair<long long, long long>, long long>(
      pair<long long, long long>(0, 0), -1));
  vector<long long> used(n, 0);
  long long cnt = 0;
  while (cnt < n) {
    pair<pair<long long, long long>, long long> p = que.top();
    que.pop();
    long long co = p.first.first, to = p.first.second, from = p.second;
    if (used[to]) {
      que.push(asore(from));
      continue;
    }
    ans += co;
    seg1.set_val(to, pair<long long, long long>(LINF, -1));
    seg2.set_val(to, pair<long long, long long>(LINF, -1));
    used[to] = 1;
    if (~from) que.push(asore(from));
    que.push(asore(to));
    cnt++;
  }
  cout << ans << endl;
}
