#include <bits/stdc++.h>
using namespace std;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
  std::fill((T*)array, (T*)(array + N), val);
}
pair<long long, long long> Dir[8] = {{0, 1}, {-1, 0}, {1, 0},  {0, -1},
                                     {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
struct segtree {
  long long N, dat[2 * 300000];
  segtree() {}
  segtree(long long n) {
    N = 1;
    while (N < n) N *= 2;
    for (long long i = 0; i < 2 * N - 1; i++) dat[i] = 10000000000000000LL;
  }
  void update(long long k, long long a) {
    k += N - 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) { return query(a, b, 0, 0, N); }
  long long query(long long a, long long b, long long k, long long l,
                  long long r) {
    if (r <= a || b <= l) return 10000000000000000LL;
    if (a <= l && r <= b) return dat[k];
    long long m = (l + r) / 2;
    return min(query(a, b, k * 2 + 1, l, m), query(a, b, k * 2 + 2, m, r));
  }
};
class Graph {
 public:
  long long vn;
  vector<vector<pair<long long, long long>>> g;
  Graph(long long n) {
    vn = n;
    g.resize(n);
  }
  virtual void con(long long a, long long b, long long w) = 0;
};
class BiDGraph : public Graph {
 public:
  BiDGraph(long long n) : Graph(n) {}
  void con(long long a, long long b, long long w = 1) {
    g[a].push_back({b, w});
    g[b].push_back({a, w});
  }
};
struct UnionFind {
  vector<long long> data;
  UnionFind(long long size) : data(size, -1) {}
  bool unionSet(long long x, long long y) {
    x = root(x);
    y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }
  bool findSet(long long x, long long y) { return root(x) == root(y); }
  long long root(long long x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  bool isroot(long long x) { return data[x] < 0; }
  long long size(long long x) { return -data[root(x)]; }
};
long long Prim(BiDGraph g, long long s = 0) {
  priority_queue<pair<long long, pair<long long, long long>>,
                 vector<pair<long long, pair<long long, long long>>>,
                 greater<pair<long long, pair<long long, long long>>>>
      cand;
  vector<bool> al(g.vn);
  long long alcou = 0;
  long long sum = 0;
  BiDGraph MST(g.vn);
  for (pair<long long, long long> ed : g.g[s]) {
    cand.push({ed.second, {s, ed.first}});
  }
  alcou = 1;
  al[s] = true;
  while (alcou < g.vn) {
    pair<long long, pair<long long, long long>> cur = cand.top();
    cand.pop();
    if (al[cur.second.second]) {
      continue;
    }
    MST.con(cur.second.first, cur.second.second);
    sum += cur.first;
    al[cur.second.second] = true;
    alcou++;
    for (pair<long long, long long> ed : g.g[cur.second.second]) {
      if (al[ed.first] == false)
        cand.push({ed.second, {cur.second.second, ed.first}});
    }
  }
  return sum;
}
signed main(void) {
  long long n, d;
  cin >> n >> d;
  vector<long long> a(n), Aar(n), Bar(n);
  BiDGraph g(n);
  for (long long i = (0); (n) > i; i++) {
    cin >> a[i];
    Aar[i] = d * (i + 1) + a[i];
    Bar[i] = -d * (i + 1) + a[i];
  }
  auto addedge = [](long long n, long long d, BiDGraph& g,
                    vector<long long>& Aar, vector<long long>& Bar) {
    vector<long long> rui(n + 1);
    set<pair<long long, long long>> bset;
    segtree B(n);
    for (long long i = (0); (n) > i; i++) {
      bset.insert({Bar[i], i});
      B.update(i, Bar[i]);
      rui[i + 1] = rui[i] + Aar[i];
    }
    {
      long long Minval = 10000000000000000LL, Minind = n;
      for (long long i = n - 2; 0 <= i; i--) {
        if (Aar[i + 1] < Minval) {
          Minind = i + 1;
          Minval = Aar[i + 1];
        }
        g.con(i, Minind, Minval + Bar[i]);
      }
    }
    long long border = n - 1;
    while (border > 0) {
      long long Minval = B.query(0, n);
      auto Minitr = bset.lower_bound(make_pair((Minval), (-1)));
      long long Minind = Minitr->second;
      bset.erase(Minitr);
      if (border > Minind) {
        for (long long i = (Minind + 1); (border + 1) > i; i++) {
          g.con(Minind, i, Minval + Aar[i]);
        }
        border = Minind;
      }
      B.update(Minind, 10000000000000000LL);
    }
  };
  addedge(n, d, g, Aar, Bar);
  long long ans = Prim(g);
  cout << ans << endl;
  return 0;
}
