#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:880999999")
using namespace std;
typedef vector<vector<pair<long long, pair<long long, long long>>>> gosh;
const long long mod = 1e9 + 7;
const long double eps = 1e-9;
const long long settled = 400007;
gosh DnC(vector<long long> a, long long d, long long st = 0) {
  gosh ed(1);
  if (a.size() == 1) return ed;
  vector<long long> le, ri;
  le = vector<long long>(a.begin(), a.begin() + a.size() / 2);
  ri = vector<long long>(a.begin() + a.size() / 2, a.end());
  gosh fir = DnC(le, d, st);
  gosh sec = DnC(ri, d, st + a.size() / 2);
  ed = fir;
  ed.insert(ed.end(), sec.begin(), sec.end());
  long long lem = 0, rim = 0;
  for (long long i = 0; i < le.size(); i++) {
    le[i] = le[i] - d * i;
    if (le[lem] > le[i]) lem = i;
  }
  for (long long i = 0; i < ri.size(); i++) {
    ri[i] = ri[i] + d * (le.size() + i);
    if (ri[rim] > ri[i]) rim = i;
  }
  for (long long i = 0; i < le.size(); i++) {
    long long cost, start, end;
    cost = le[i] + ri[rim];
    start = i + st;
    end = rim + st + le.size();
    ed[i].push_back(make_pair(cost, make_pair(start, end)));
    if (i == lem) continue;
    ed[rim + le.size()].push_back(make_pair(cost, make_pair(end, start)));
  }
  for (long long i = 0; i < ri.size(); i++) {
    long long cost, start, end;
    cost = le[lem] + ri[i];
    start = i + st + le.size();
    end = lem + st;
    ed[i + le.size()].push_back(make_pair(cost, make_pair(start, end)));
    if (i == rim) continue;
    ed[lem].push_back(make_pair(cost, make_pair(end, start)));
  }
  return ed;
}
long long MSTcost(gosh ed) {
  long long ret = 0;
  set<pair<long long, pair<long long, long long>>> pile;
  vector<long long> used(ed.size(), 0);
  long long cost = 0, sum = 0;
  pile.insert(make_pair(0, make_pair(0, 0)));
  while (pile.size()) {
    pair<long long, pair<long long, long long>> cur;
    cur = *pile.begin();
    pile.erase(pile.begin());
    if (used[cur.second.second]) continue;
    used[cur.second.second] = 1;
    cost += cur.first;
    for (pair<long long, pair<long long, long long>> edge :
         ed[cur.second.second]) {
      pile.insert(edge);
    }
  }
  ret = cost;
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(NULL);
  long long n, d;
  cin >> n >> d;
  vector<long long> a(n, 0);
  for (long long i = 0; i < n; i++) cin >> a[i];
  auto graph = DnC(a, d);
  long long val = MSTcost(graph);
  vector<long long> test;
  for (long long i = 0; i < 1e7; i++) test.push_back(i);
  cout << val;
  return 0;
}
