#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
const long long LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
template <typename T>
T gcd(T a, T b) {
  return (a == 0) ? b : gcd(b % a, a);
}
template <typename T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
bool p_comp_fs(const pair<long long, long long> p1,
               const pair<long long, long long> p2) {
  return p1.first < p2.first;
};
bool p_comp_fg(const pair<long long, long long> p1,
               const pair<long long, long long> p2) {
  return p1.first > p2.first;
};
bool p_comp_ss(const pair<long long, long long> p1,
               const pair<long long, long long> p2) {
  return p1.second < p2.second;
};
bool p_comp_sg(const pair<long long, long long> p1,
               const pair<long long, long long> p2) {
  return p1.second > p2.second;
};
template <typename T>
vector<T> uniquen(vector<T> vec) {
  sort((vec).begin(), (vec).end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return vec;
}
inline long long popcnt(long long x) {
  return __builtin_popcountll((unsigned long long)x);
};
template <class T>
bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename Monoid>
struct SegmentTree {
  using F = function<Monoid(Monoid, Monoid)>;
  long long sz;
  vector<Monoid> seg;
  const F f;
  const Monoid M1;
  SegmentTree(long long n, const F f, const Monoid &M1) : f(f), M1(M1) {
    sz = 1;
    while (sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }
  void set(long long k, const Monoid &x) { seg[k + sz] = x; }
  void build() {
    for (long long k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }
  void update(long long k, const Monoid &x) {
    k += sz;
    seg[k] = x;
    while (k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }
  Monoid query(long long a, long long b) {
    Monoid L = M1, R = M1;
    for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if (a & 1) L = f(L, seg[a++]);
      if (b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }
  Monoid operator[](const long long &k) const { return seg[k + sz]; }
};
struct UnionFind {
  vector<long long> par;
  vector<long long> rank;
  map<long long, long long> size;
  UnionFind(long long N) : par(N, 0), rank(N, 0) {
    for (long long i = 0; i < N; i++) {
      par[i] = i;
      size[i] = 1;
    }
  }
  long long root(long long x) {
    if (par[x] == x)
      return x;
    else {
      par[x] = root(par[x]);
      return par[x];
    }
  }
  void unite(long long x, long long y) {
    long long rx = root(x);
    long long ry = root(y);
    if (rx == ry) return;
    if (rank[rx] < rank[ry]) swap(rx, ry);
    if (rank[rx] == rank[ry]) ++rank[rx];
    par[ry] = rx;
    if (rx != ry)
      size[rx] = size[rx] + size[ry];
    else {
      size[rx] = max(size[rx], size[ry]);
    }
  }
  long long get_size(long long x) { return size[root(x)]; }
  bool same(long long x, long long y) { return root(x) == root(y); }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  long long N, D;
  cin >> N >> D;
  vector<long long> A(N);
  for (long long i = 0; i < N; i++) cin >> A[i];
  auto min_func = [](pair<long long, long long> l,
                     pair<long long, long long> r) {
    if (l.first <= r.first)
      return l;
    else
      return r;
  };
  auto lseg = SegmentTree<pair<long long, long long> >(N, min_func, {LINF, -1});
  auto rseg = SegmentTree<pair<long long, long long> >(N, min_func, {LINF, -1});
  for (long long i = 0; i < N; i++) {
    rseg.update(i, {A[i] + i * D, i});
    lseg.update(i, {A[i] - i * D, i});
  }
  multimap<long long, pair<long long, long long> > m;
  for (long long i = 0; i < N; i++) {
    if (i < N - 1) {
      auto idx = rseg.query(i + 1, N).second;
      m.insert({A[i] + A[idx] + D * abs(i - idx), {i, idx}});
    }
    if (i > 0) {
      auto idx = lseg.query(0, i).second;
      m.insert({A[i] + A[idx] + D * abs(i - idx), {i, idx}});
    }
  }
  long long ans = 0;
  auto uf = UnionFind(N);
  for (auto it = m.begin(); it != m.end(); it++) {
    auto p = it->second;
    if (uf.same(p.first, p.second)) continue;
    ans += it->first;
    uf.unite(p.first, p.second);
  }
  cout << ans << endstr;
  return 0;
}
