#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int src, dst;
  int64_t weight;
  Edge(int src, int dst, int64_t weight) : src(src), dst(dst), weight(weight) {}
};
bool operator<(const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight
         : e.src != f.src     ? e.src < f.src
                              : e.dst < f.dst;
}
struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) {}
  bool unionSet(int x, int 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(int x, int y) { return root(x) == root(y); }
  int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
  int size(int x) { return -data[root(x)]; }
};
pair<int64_t, vector<Edge> > minimumSpanningTree(const vector<vector<Edge> > &g,
                                                 int r = 0) {
  int n = g.size();
  vector<Edge> T;
  int64_t total = 0;
  vector<bool> visited(n);
  priority_queue<Edge> Q;
  Q.push(Edge(-1, r, 0));
  while (!Q.empty()) {
    Edge e = Q.top();
    Q.pop();
    if (visited[e.dst]) continue;
    T.push_back(e);
    total += e.weight;
    visited[e.dst] = true;
    for (auto f = g[e.dst].begin(); f != g[e.dst].end(); f++) {
      if (!visited[f->dst]) Q.push(*f);
    }
  }
  return pair<int64_t, vector<Edge> >(total, T);
}
int main() {
  int n, d;
  cin >> n >> d;
  vector<int64_t> a;
  int64_t minai = 10000000000LL;
  int minid = -1;
  for (int i = 0; i < n; ++i) {
    int64_t ai;
    cin >> ai;
    a.push_back(ai);
    if (ai < minai) {
      minai = ai;
      minid = i;
    }
  }
  vector<vector<Edge> > graph(n);
  int st = 0;
  for (int en = 1; en < n; ++en) {
    int64_t cost = abs(st - en) * d + a[st] + a[en];
    graph[en].push_back(Edge(en, st, cost));
    graph[st].push_back(Edge(st, en, cost));
    if (a[st] + abs(en - st) * d > a[en]) {
      st = en;
    }
  }
  st = n - 1;
  for (int en = st - 1; en >= 0; --en) {
    int64_t cost = abs(st - en) * d + a[st] + a[en];
    graph[en].push_back(Edge(en, st, cost));
    graph[st].push_back(Edge(st, en, cost));
    if (a[st] + abs(en - st) * d > a[en]) {
      st = en;
    }
  }
  auto res = minimumSpanningTree(graph, minid);
  cout << res.first << endl;
  return 0;
}
