#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;
}
struct UnionFind {
  vector<long long> par;
  UnionFind(long long n) : par(n, -1) {}
  void init(long long n) { par.assign(n, -1); }
  long long root(long long x) {
    if (par[x] < 0)
      return x;
    else
      return par[x] = root(par[x]);
  }
  bool issame(long long x, long long y) { return root(x) == root(y); }
  bool merge(long long x, long long y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (par[x] > par[y]) swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }
  long long size(long long x) { return -par[root(x)]; }
};
vector<pair<long long, long long> > edgs;
vector<long long> A;
long long N, D;
void addEdge(long long l, long long r) {
  if (r - l <= 1) return;
  long long m = (l + r) / 2;
  long long ridx = -1, rmin = LINF;
  for (long long i = (m); i < r; i++) {
    if (chmin(rmin, A[i] + i * D)) ridx = i;
  }
  for (long long i = (l); i < m; i++) edgs.push_back({i, ridx});
  long long lidx = -1, lmin = LINF;
  for (long long i = (l); i < m; i++) {
    if (chmin(lmin, A[i] - i * D)) lidx = i;
  }
  for (long long i = (m); i < r; i++) edgs.push_back({i, lidx});
  addEdge(l, m);
  addEdge(m, r);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N >> D;
  A = vector<long long>(N);
  for (long long i = 0; i < N; i++) cin >> A[i];
  addEdge(0, N);
  multimap<long long, pair<long long, long long> > m;
  for (auto e : edgs) {
    long long c = A[e.first] + A[e.second] + D * abs(e.first - e.second);
    m.insert({c, e});
  }
  long long ans = 0;
  auto uf = UnionFind(N);
  for (auto it = m.begin(); it != m.end(); it++) {
    long long f = it->second.first, s = it->second.second;
    if (uf.issame(f, s)) continue;
    uf.merge(f, s);
    ans += it->first;
  }
  cout << ans << endstr;
  return 0;
}
