#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) std::cerr<< #x <<": "<<x<<"\n"
#define debug2(x,y) std::cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<"\n"
 
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector<std::vector<int> > vvi;
typedef std::vector<ll> vll;
typedef std::vector<std::vector<ll> > vvll;
typedef std::deque<bool> db;
template<class T> using vv=std::vector<std::vector< T > >;

// cout vector
template<typename T> std::ostream& operator<<(std::ostream& s, const std::vector<T>& v) {
  int len=v.size();s<<"\n";rep(i,len){s<<v[i];if(i<len-1){s << "\t";}}s<<"\n";return s; }
// cout 2-dimentional vector
template<typename T> std::ostream& operator<<(std::ostream& s, const std::vector<std::vector<T> >& vv) {
  int len=vv.size();rep(i,len){s<<vv[i];} return s; }
// cout deque
template<typename T> std::ostream& operator<<(std::ostream& s, const std::deque<T>& v) {
  int len=v.size();s<<"\n";rep(i,len){s<<v[i];if(i<len-1){s << "\t";}}s<<"\n";return s; }
// cout 2-dimentional deque
template<typename T> std::ostream& operator<<(std::ostream& s, const std::deque<std::deque<T> >& vv) {
  int len=vv.size();rep(i,len){s<<vv[i];} return s; }
// cout set<cout-able>
template<typename T> std::ostream& operator<<(std::ostream& s, const std::set<T>& v) {
  s<<"\n";for(auto elm : v){s<<elm<<"\t";}s<<"\n";return s; }

inline void scan(int&a){scanf("%d",&a);}
inline void scan(int&a,int&b){scanf("%d%d",&a,&b);}
inline void scan(int&a,int&b,int&c){scanf("%d%d%d",&a,&b,&c);}
inline void scan(int&a,int&b,int&c,int&d){scanf("%d%d%d%d",&a,&b,&c,&d);}
inline void scan(std::vector<int>&v){int sz=v.size();rep(i,sz){scan(v[i]);}}
inline void scan(std::vector<std::vector<int> >&v){int sz=v.size();rep(i,sz){scan(v[i]);}}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(ll&a,ll&b){scanf("%lld%lld",&a,&b);}
inline void scan(ll&a,ll&b,ll&c){scanf("%lld%lld%lld",&a,&b,&c);}
inline void scan(ll&a,ll&b,ll&c,ll&d){scanf("%lld%lld%lld%lld",&a,&b,&c,&d);}
inline void scan(std::vector<ll>&v){int sz=v.size();rep(i,sz){scan(v[i]);}}
inline void scan(std::vector<std::vector<ll> >&v){int sz=v.size();rep(i,sz){scan(v[i]);}}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(std::vector<char>&v){int sz=v.size();rep(i,sz){scan(v[i]);}}
inline void scan(std::vector<std::vector<char> >&v){int sz=v.size();rep(i,sz){scan(v[i]);}}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}

inline void print(int a){printf("%d\n",a);}
inline void print(int a,int b){printf("%d %d\n",a,b);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(ll a,ll b){printf("%lld %lld\n",a,b);}
inline void print(std::string s){std::cout << s << "\n";}
inline void print_yn(bool flg){if(flg){printf("Yes\n");}else{printf("No\n");}}

using namespace std;

class UF {
private:
  vector<int> data; // parent or size
  vector<int> next;
  vector<int> last;
  void init(int n) {
    data.assign(n, -1);
    next.assign(n, -1);
    last.resize(n);
    for (int i = 0; i < n; ++i) {
      last[i] = i;
    }
  }

public:
  UF() {}
  UF(int n) {
    init(n);
  }
  int root(int x) {
    if (data[x] < 0) return x;
    return data[x] = root(data[x]);
  }
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (data[x] > data[y]) swap(x, y); // data[x] and data[y] are negative.
    data[x] += data[y];
    data[y] = x;
    next[last[x]] = y;
    last[x] = last[y];
    return true;
  }
  int size(int x) {
    return -data[root(x)];
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  int get_next(int x) {
    return next[x];
  }
};

struct Monoid_Struct {
  using T = pair<int, ll>; // type or class of monoid
  T operator()(const T& left, const T& right) {
    return left.second < right.second ? left : right; // definition of operator
  }
  static constexpr T identity() { return (pair<int, ll>){-1, LLONG_MAX}; }
};

template<class Monoid>
class SegTree {
private:
  using T = typename Monoid::T;
  Monoid op;
  const int n;
  vector<T> t;

  void propagate_to(int i) { t[i] = op(t[2*i], t[2*i+1]); }

public:
  SegTree(int n_) : n(n_), t(2*n, op.identity()) {}
  SegTree(const vector<T>& v) : n(v.size()), t(2*n) {
    copy(begin(v), end(v), begin(t) + n);
    for (int i = n-1; i > 0; --i) {
      propagate_to(i);
    }
  }

  void set(int i, const T& x) {
    t[i += n] = x;
    while (i >>= 1) {
      propagate_to(i);
    }
  }

  T get(int i) { return t[i + n]; }

  T accumulate(int l, int r) {
    T accl = op.identity(), accr = op.identity();
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) accl = op(accl, t[l++]);
      if (r & 1) accr = op(t[r-1], accr);
    }
    return op(accl, accr);
  }
};

int main() {
  ll n, d;
  scan(n, d);
  vll a(n);
  scan(a);
  vi lowest_left(n, 0);
  FOR (i, 1, n) {
    ll cur_cost = a[lowest_left[i-1]] + d * (i - lowest_left[i-1]);
    ll new_cost = a[i];
    if (cur_cost < new_cost) {
      lowest_left[i] = lowest_left[i-1];
    } else {
      lowest_left[i] = i;
    }
  }
  vi lowest_right(n, n-1);
  for (int i = n-2; i >= 0; --i) {
    ll cur_cost = a[lowest_right[i+1]] + d * (lowest_right[i+1] - i);
    ll new_cost = a[i];
    if (cur_cost < new_cost) {
      lowest_right[i] = lowest_right[i+1];
    } else {
      lowest_right[i] = i;
    }
  }
  vector<pair<int, ll> > lefts(n), rights(n);
  rep (i, n) {
    lefts[i].first = i;
    rights[i].first = i;
    lefts[i].second = a[i] + d * (n-1 - i);
    rights[i].second = a[i] + d * i;
  }

  SegTree<Monoid_Struct> seg_left(lefts), seg_right(rights);
  UF uf(n);
  ll ans = 0;
  while (true) {
    vvi areas;
    rep (i, n) {
      int node = i;
      int ma = i;
      while (uf.get_next(node) != -1) {
        node = uf.get_next(node);
        ma = max(ma, node);
      }
      areas.push_back((vi){i, ma});
      i = ma;
    }
    if (areas.size() == 1) {
      break;
    }
    int m = areas.size();
    vector<bool> connected(m, false);
    rep (i, m) {
      if (connected[i]) { continue; }
      ll left_cost = LLONG_MAX;
      int left_node_left = -1;
      int left_node_right = -1;
      ll right_cost = LLONG_MAX;
      int right_node_left = -1;
      int right_node_right = -1;
      if (i != 0) {
        left_node_left = seg_left.accumulate(0, areas[i][0]).first;
        left_node_right = seg_right.accumulate(areas[i][0], areas[i][1] + 1).first;
        left_cost = d * (left_node_right - left_node_left) + a[left_node_left] + a[left_node_right];
      }
      if (i != m-1) {
        right_node_right = seg_right.accumulate(areas[i][1] + 1, n).first;
        right_node_left = seg_left.accumulate(areas[i][0], areas[i][1] + 1).first;
        right_cost = d * (right_node_right - right_node_left) + a[right_node_left] + a[right_node_right];
      }
      if (left_cost < right_cost) {
        ans += left_cost;
        uf.unite(left_node_left, left_node_right);
        //int left_area = lower_bound(all(areas), (vi){left_node_left}) - begin(areas);
      } else {
        ans += right_cost;
        uf.unite(right_node_left, right_node_right);
        int right_area = lower_bound(all(areas), (vi){right_node_right}) - begin(areas);
        connected[right_area] = true;
      }
    }
  }
  print(ans);

  return 0;
}
