#include <bits/stdc++.h>
using namespace std;
struct segmn {
  long long nn;
  long long dat[(2 * (1 << 18)) - 1];
  void init(long long n1) {
    nn = 1;
    while (nn < n1) nn *= 2;
    for (long long i = 0; i < 2 * nn - 1; i++) {
      dat[i] = 1000000000000000000LL;
    }
  }
  void update(long long k, long long a) {
    k += nn - 1;
    dat[k] = a;
    while (k > 0) {
      k = (k - 1) / 2;
      dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }
  long long query(long long a, long long b, long long k, long long l,
                  long long r) {
    if (r <= a || b <= l) return 1000000000000000000LL;
    if (a <= l && r <= b) {
      return dat[k];
    } else {
      long long vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
      long long vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
      return min(vl, vr);
    }
  }
  long long query(long long a, long long b) { return query(a, b, 0, 0, nn); }
} segmn1, segmn2;
pair<long long, long long> d1[200100];
pair<long long, long long> d2[200100];
vector<int> uf, usz;
int nc;
void init(int n) {
  vector<int> uf_(n);
  vector<int> usz_(n, 1);
  uf = uf_;
  usz = usz_;
  nc = n;
  for (int i = 0; i < uf.size(); i++) {
    uf[i] = i;
  }
}
int find(int a) { return (uf[a] == a) ? a : uf[a] = find(uf[a]); }
void union_(int a, int b) {
  a = find(a);
  b = find(b);
  if (a != b) {
    if (usz[a] >= usz[b]) {
      swap(a, b);
    }
    uf[a] = b;
    usz[b] += usz[a];
    nc--;
  }
}
int check(int a, int b) { return (find(a) == find(b)) ? 1 : 0; }
int get_size(int a) { return usz[find(a)]; }
long long minST(vector<pair<long long, pair<long long, long long> > > &v,
                long long V) {
  init(V);
  long long ret = 0;
  sort(v.begin(), v.end());
  for (long long i = 0; i < v.size(); i++) {
    long long from = v[i].second.first;
    long long to = v[i].second.second;
    long long cost = v[i].first;
    if (check(from, to) == 0) {
      union_(from, to);
      ret += cost;
    }
  }
  return ret;
}
int main() {
  long long n, d;
  cin >> n >> d;
  vector<long long> v;
  for (long long i = (0); i < (n); ++i) {
    long long a;
    cin >> a;
    v.push_back(a);
  }
  for (long long i = (0); i < (n); ++i) {
    segmn1.update(i, d * i + v[i]);
  }
  for (long long i = n - 1LL; i >= (0); --i) {
    segmn2.update(i, d * (n - 1 - i) + v[i]);
  }
  vector<pair<long long, pair<long long, long long> > > vv;
  for (long long i = (0); i < (n - 1); ++i) {
    long long mn1 = segmn1.query(i + 1, n);
    long long low = i + 1;
    long long high = n - 1;
    while (low < high) {
      long long mid = (high + low + 1) >> 1;
      if (mn1 == segmn1.query(i + 1, mid + 1)) {
        low = mid;
      } else {
        high = mid - 1;
      }
    }
    d1[i] = make_pair(low, mn1);
    vv.push_back(make_pair(mn1, make_pair(i, low)));
  }
  for (long long i = (1); i < (n); ++i) {
    long long mn2 = segmn2.query(0, i);
    long long low = 0;
    long long high = i - 1;
    while (low < high) {
      long long mid = (high + low) >> 1;
      if (mn2 == segmn2.query(0, mid + 1)) {
        high = mid;
      } else {
        low = mid + 1;
      }
    }
    d2[i] = make_pair(low, mn2);
    vv.push_back(make_pair(mn2, make_pair(i, low)));
  }
  printf("%lld\n", minST(vv, n * 2 + 1));
  return 0;
}
