#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using pcc = pair<char, char>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using tuplis = pair<ll, pll>;
const ll LINF = 0x1fffffffffffffff;
const ll MOD = 1000000007;
const ll MODD = 0x3b800001;
const int INF = 0x3fffffff;
const double DINF = numeric_limits<double>::infinity();
const vector<pii> four = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
__attribute__((constructor)) void SETTINGS() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
};
template <class T>
inline constexpr T gcd(T a, T b) {
  if (!a || !b) return 0;
  return a % b ? gcd(b, a % b) : b;
}
template <class T>
inline constexpr T lcm(T a, T b) {
  return a * b / gcd(a, b);
}
template <class T>
inline constexpr T min(vector<T>& v) {
  return *min_element((v).begin(), (v).end());
}
inline char min(string& v) { return *min_element((v).begin(), (v).end()); }
template <class T>
inline constexpr T max(vector<T>& v) {
  return *max_element((v).begin(), (v).end());
}
inline char max(string& v) { return *max_element((v).begin(), (v).end()); }
inline ll pow(ll a, ll b) {
  if (b == 0) return 1;
  ll ans = pow(a, b / 2);
  return ans * ans * (b & 1 ? a : 1);
}
inline ll modpow(ll a, ll b, ll mod) {
  if (b == 0) return 1;
  ll ans = pow(a, b / 2);
  return ans * ans * (b & 1 ? a : 1) % mod;
}
template <typename T>
inline bool update_min(T& mn, const T& cnt) {
  if (mn > cnt) {
    mn = cnt;
    return 1;
  } else
    return 0;
}
template <typename T>
inline bool update_max(T& mx, const T& cnt) {
  if (mx < cnt) {
    mx = cnt;
    return 1;
  } else
    return 0;
}
inline void in() {}
template <class T>
istream& operator>>(istream& is, vector<T>& vec);
template <class T, size_t size>
istream& operator>>(istream& is, array<T, size>& vec);
template <class T, class L>
istream& operator>>(istream& is, pair<T, L>& p);
template <class T>
ostream& operator<<(ostream& os, vector<T>& vec);
template <class T, class L>
ostream& operator<<(ostream& os, pair<T, L>& p);
template <class T>
istream& operator>>(istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x;
  return is;
}
template <class T, class L>
istream& operator>>(istream& is, pair<T, L>& p) {
  is >> p.first;
  is >> p.second;
  return is;
}
template <class T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  os << vec[0];
  for (ll i = 1; i < vec.size(); ++i) {
    os << ' ' << vec[i];
  }
  return os;
}
template <class T>
ostream& operator<<(ostream& os, deque<T>& deq) {
  os << deq[0];
  for (ll i = 1; i < deq.size(); ++i) {
    os << ' ' << deq[i];
  }
  return os;
}
template <class T, class L>
ostream& operator<<(ostream& os, pair<T, L>& p) {
  os << p.first << " " << p.second;
  return os;
}
template <class T, class L>
pair<T, L> operator+(pair<T, L> a, pair<T, L> b) {
  return {a.first + b.first, a.second + b.second};
}
template <class Head, class... Tail>
inline void in(Head&& head, Tail&&... tail) {
  cin >> head;
  in(move(tail)...);
}
template <class T>
inline bool out(T t) {
  cout << t << '\n';
  return 0;
}
inline bool out() {
  cout << '\n';
  return 0;
}
template <class Head, class... Tail>
inline bool out(Head head, Tail... tail) {
  cout << head << ' ';
  out(move(tail)...);
  return 0;
}
template <class T>
inline void err(T t) {
  cerr << t << '\n';
}
inline void err() { cerr << '\n'; }
template <class Head, class... Tail>
inline void err(Head head, Tail... tail) {
  cerr << head << ' ';
  out(move(tail)...);
}
class UnionFind {
 public:
  vector<ll> data;
  UnionFind(ll n) : data(n, -1) {}
  bool Union(ll a, ll b) {
    a = root(a);
    b = root(b);
    if (a == b) return 1;
    if (data[a] > data[b]) swap(a, b);
    data[a] += data[b];
    data[b] = a;
    return 0;
  }
  bool Find(ll a, ll b) { return root(a) == root(b); }
  ll root(ll a) { return data[a] < 0 ? a : root(data[a]); }
};
signed main() {
  ll n, d;
  in(n, d);
  vector<ll> a(n);
  in(a);
  vector<pll> s(n), t(n);
  for (ll i = 0; i < n; ++i) s[i] = {a[i] + d * i, i};
  for (ll i = 0; i < n; ++i) t[i] = {a[i] + d * (n - 1 - i), i};
  for (ll i = n - 1 - 1; i >= 0; i--) update_min(s[i], s[i + 1]);
  for (ll i = 0; i < n - 1; ++i) update_min(t[i + 1], t[i]);
  vector<unordered_map<ll, ll>> g(n);
  for (ll i = 0; i < n - 1; ++i) {
    g[i][s[i + 1].second] = g[s[i + 1].second][i] =
        a[s[i + 1].second] + a[i] + abs(s[i + 1].second - i) * d;
    g[i + 1][t[i].second] = g[t[i].second][i + 1] =
        a[t[i].second] + a[i + 1] + abs(t[i].second - (i + 1)) * d;
  }
  ll ans = 0;
  vector<bool> used(n);
  priority_queue<tuplis, vector<tuplis>, greater<tuplis>> q;
  UnionFind uf(n);
  used[0] = 1;
  for (auto&& i : g[0]) q.push({i.second, {0, i.first}});
  while (!q.empty()) {
    auto cost = q.top().first, x = q.top().second.first,
         y = q.top().second.second;
    q.pop();
    if (uf.Find(x, y)) continue;
    uf.Union(x, y);
    ans += cost;
    for (auto&& i : g[y])
      if (!uf.Find(y, i.first)) q.push({i.second, {y, i.first}});
  }
  out(ans);
}
