#include <bits/stdc++.h>
using namespace std;
long long n, d;
long long a[200001];
unordered_set<int> tree;
unordered_set<int> rest;
map<long long, queue<pair<int, int>>> path;
long long calc(int i, int j) { return abs(i - j) * d + a[i] + a[j]; }
long long add(int i) {
  rest.erase(i);
  for (auto j : rest) {
    long long dist = calc(i, j);
    auto iter = path.find(dist);
    if (iter != end(path))
      path[dist].push(make_pair(i, j));
    else {
      queue<pair<int, int>> vii;
      vii.push(make_pair(i, j));
      path[dist] = vii;
    }
  }
  tree.emplace(i);
}
int main(void) {
  cin >> n >> d;
  for (int i = (0), ilen = (n); i < ilen; ++i) {
    cin >> a[i];
    rest.emplace(i);
  }
  add(0);
  long long res = 0;
  while (rest.size() > 0) {
    auto vii = path.begin();
    auto dist = vii->first;
    auto p = vii->second.front();
    vii->second.pop();
    if (vii->second.size() <= 0) path.erase(dist);
    auto iter1 = tree.find(p.first);
    auto iter2 = tree.find(p.second);
    if (iter1 != tree.end() && iter2 != tree.end())
      continue;
    else if (iter1 != tree.end()) {
      add(p.second);
      res += dist;
    } else if (iter2 != tree.end()) {
      add(p.first);
      res += dist;
    } else {
      cout << "undefined" << endl;
      return -1;
    }
  }
  cout << res << endl;
  return 0;
}
