#include <bits/stdc++.h>
using namespace std;
namespace {
template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()) {
  v.assign(a, vector<T>(b, t));
}
template <class T>
inline T &chmin(T &x, const T &y) {
  return x = min(x, y);
}
template <class T>
inline T &chmax(T &x, const T &y) {
  return x = max(x, y);
}
template <class F, class T>
void convert(const F &f, T &t) {
  stringstream ss;
  ss << f;
  ss >> t;
}
struct union_find {
  vector<int> par;
  unsigned grs;
  explicit union_find(unsigned n = 0) { init(n); }
  void init(unsigned n) {
    par.assign(n, -1);
    grs = n;
  }
  unsigned find(unsigned x) {
    if (par[x] < 0) {
      return x;
    }
    return par[x] = find(par[x]);
  }
  unsigned size(unsigned x) { return -par[find(x)]; }
  unsigned groups() { return grs; }
  bool unite(unsigned x, unsigned y) {
    x = find(x);
    y = find(y);
    if (x == y) {
      return false;
    }
    if (par[x] < par[y]) {
      swap(x, y);
    }
    par[y] += par[x];
    par[x] = y;
    --grs;
    return true;
  }
  bool same(unsigned x, unsigned y) { return find(x) == find(y); }
  bool is_root(unsigned x) { return find(x) == x; }
};
void mainmain() {
  const long long INF = 1LL << 60;
  int n;
  long long d;
  scanf("%d%lld", &n, &d);
  vector<long long> as(n);
  for (int i = 0; i < n; ++i) {
    scanf("%lld", &as[i]);
  }
  union_find uf(n);
  long long ans = 0;
  vector<pair<long long, long long> > dp1, dp2;
  vector<pair<long long, long long> > top2;
  vector<pair<long long, long long> > es;
  const pair<long long, long long> def(INF, -1);
  while (uf.groups() > 1) {
    dp1.assign(n, def);
    dp2.assign(n, def);
    top2.clear();
    for (int i = n - 1; i >= 0; --i) {
      int u = uf.find(i);
      for (cauto t : top2) {
        if (t.second != u) {
          dp1[i] =
              pair<long long, long long>(t.first + as[i] - i * d, t.second);
          break;
        }
      }
      pair<long long, long long> p(as[i] + i * d, u);
      top2.insert(lower_bound((top2).begin(), (top2).end(), p), p);
      for (int j = 0; j < (int)top2.size(); ++j) {
        for (int k = j + 1; k < (int)top2.size(); ++k) {
          if (top2[j].second == top2[k].second) {
            top2[k] = def;
          }
        }
      }
      top2.erase(remove((top2).begin(), (top2).end(), def), top2.end());
      if (top2.size() > 2) {
        top2.pop_back();
      }
    }
    top2.clear();
    for (int i = 0; i < n; ++i) {
      int u = uf.find(i);
      for (cauto t : top2) {
        if (t.second != u) {
          dp2[i] =
              pair<long long, long long>(t.first + as[i] + i * d, t.second);
          break;
        }
      }
      pair<long long, long long> p(as[i] - i * d, u);
      top2.insert(lower_bound((top2).begin(), (top2).end(), p), p);
      for (int j = 0; j < (int)top2.size(); ++j) {
        for (int k = j + 1; k < (int)top2.size(); ++k) {
          if (top2[j].second == top2[k].second) {
            top2[k] = def;
          }
        }
      }
      top2.erase(remove((top2).begin(), (top2).end(), def), top2.end());
      if (top2.size() > 2) {
        top2.pop_back();
      }
    }
    es.assign(n, def);
    for (int i = 0; i < n; ++i) {
      pair<long long, long long> p = min(dp1[i], dp2[i]);
      int u = uf.find(i);
      chmin(es[u], p);
    }
    sort((es).begin(), (es).end());
    for (int i = 0; i < n; ++i) {
      cauto t = es[i];
      if (t.second >= 0) {
        if (uf.unite(i, t.second)) {
          ans += t.first;
        }
      }
    }
  }
  printf("%lld\n", ans);
}
}  // namespace
int main() try {
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(4);
  mainmain();
} catch (...) {
}
