#include <bits/stdc++.h>
using namespace std;
template <class S, class T>
pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) {
  return pair<S, T>(s.first + t.first, s.second + t.second);
}
template <class S, class T>
pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) {
  return pair<S, T>(s.first - t.first, s.second - t.second);
}
template <class S, class T>
ostream &operator<<(ostream &os, pair<S, T> p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long inf = 1000000001;
const long long INF = 1e18;
const long long MOD = 1000000007;
const double pi = 3.14159265358979323846;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx2[8] = {1, 1, 0, -1, -1, -1, 0, 1}, dy2[8] = {0, 1, 1, 1, 0, -1, -1, -1};
class LazySegmentTree {
 public:
  int n;
  vector<pair<long long, long long> > node, lazy;
  bool ismax;
  LazySegmentTree(vector<long long> a, bool _ismax) {
    ismax = _ismax;
    int _n = a.size();
    n = 1;
    while (n < _n) n *= 2;
    node.resize(2 * n - 1);
    fill(node.begin(), node.end(),
         pair<long long, long long>(INF * (1 - (int)ismax * 2), -1));
    lazy.resize(2 * n - 1);
    for (int i = 0; i < _n; i++)
      node[i + n - 1] = pair<long long, long long>(a[i], i);
    for (int i = n - 2; i >= 0; i--) {
      if (ismax)
        node[i] = max(node[i * 2 + 1], node[i * 2 + 2]);
      else
        node[i] = min(node[i * 2 + 1], node[i * 2 + 2]);
    }
  }
  inline void eval(int k, int l, int r) {
    if (lazy[k].first != 0) {
      node[k] = node[k] + lazy[k];
      if (r - l > 1) {
        lazy[2 * k + 1] = lazy[2 * k + 1] + lazy[k];
        lazy[2 * k + 2] = lazy[2 * k + 1] + lazy[k];
      }
      lazy[k] = pair<long long, long long>(0, 0);
    }
  }
  void add(int a, int b, long long x, int k, int l, int r) {
    eval(k, l, r);
    if (b <= l || r <= a) return;
    if (a <= l && r <= b) {
      lazy[k].first += x;
      eval(k, l, r);
    } else {
      add(a, b, x, 2 * k + 1, l, (l + r) / 2);
      add(a, b, x, 2 * k + 2, (l + r) / 2, r);
      if (ismax)
        node[k] = max(node[2 * k + 1], node[2 * k + 2]);
      else
        node[k] = min(node[2 * k + 1], node[2 * k + 2]);
    }
  }
  pair<long long, long long> getmax(int a, int b, int k, int l, int r) {
    eval(k, l, r);
    if (b <= l || r <= a)
      return (ismax ? pair<long long, long long>(-INF, -1)
                    : pair<long long, long long>(INF, -1));
    if (a <= l && r <= b) return node[k];
    pair<long long, long long> resl = getmax(a, b, 2 * k + 1, l, (l + r) / 2);
    pair<long long, long long> resr = getmax(a, b, 2 * k + 2, (l + r) / 2, r);
    if (ismax)
      return max(resl, resr);
    else
      return min(resl, resr);
  }
};
int main() {
  long long n, d;
  cin >> n >> d;
  vector<long long> a(n);
  long long mi = INF, mii = -1;
  for (int i = 0; i < (n); i++) {
    cin >> a[i];
    if (mi > a[i]) {
      mi = a[i];
      mii = i;
    }
  }
  LazySegmentTree lst(vector<long long>(n, 0), false);
  for (int i = 0; i < (n); i++) {
    if (i == mii) {
      lst.add(i, i + 1, INF, 0, 0, lst.n);
    } else {
      lst.add(i, i + 1, abs(i - mii) * d + a[mii], 0, 0, lst.n);
    }
  }
  long long ans = 0;
  for (int aaa = 0; aaa < (n - 1); aaa++) {
    pair<long long, long long> mi = lst.getmax(0, n, 0, 0, lst.n);
    ans += mi.first + a[mi.second];
    int i = mi.second;
    if (a[i] < mi.first) {
      int ok = i, ng = n;
      while (ok + 1 < ng) {
        int mid = (ok + ng) / 2;
        pair<long long, long long> mi2 = lst.getmax(mid, mid + 1, 0, 0, lst.n);
        long long mi3 = a[i] + d * abs(i - mid);
        if (mi3 <= mi2.first) {
          ok = mid;
        } else {
          ng = mid;
        }
      }
      lst.add(i, ok + 1, a[i] - mi.first, 0, 0, lst.n);
      ok = i;
      ng = -1;
      while (ng + 1 < ok) {
        int mid = (ok + ng) / 2;
        pair<long long, long long> mi2 = lst.getmax(mid, mid + 1, 0, 0, lst.n);
        long long mi3 = a[i] + d * abs(i - mid);
        if (mi3 <= mi2.first) {
          ok = mid;
        } else {
          ng = mid;
        }
      }
      lst.add(ok, i, a[i] - mi.first, 0, 0, lst.n);
    }
  }
  cout << ans << endl;
}
