#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f3f3f3f3f;
vector<long long> v[200100];
long long fa[200100], n, m, val[200100], res;
pair<long long, long long> operator+(const pair<long long, long long> &x,
                                     const pair<long long, long long> &y) {
  return min(x, y);
}
struct SegTree {
  pair<long long, long long> p[800100];
  void modify(long long x, long long l, long long r, long long P,
              long long val) {
    if (l > P || r < P) return;
    if (l == r) {
      p[x] = make_pair(val, l);
      return;
    }
    modify(x << 1, l, ((l + r) >> 1), P, val),
        modify(x << 1 | 1, ((l + r) >> 1) + 1, r, P, val),
        p[x] = p[x << 1] + p[x << 1 | 1];
  }
  pair<long long, long long> query(long long x, long long l, long long r,
                                   long long L, long long R) {
    if (l > R || r < L) return make_pair(INF, INF);
    if (L <= l && r <= R) return p[x];
    return query(x << 1, l, ((l + r) >> 1), L, R) +
           query(x << 1 | 1, ((l + r) >> 1) + 1, r, L, R);
  }
} seg[2];
long long find(long long x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
bool merge(long long x, long long y) {
  x = find(x), y = find(y);
  if (x == y) return false;
  if (v[x].size() < v[y].size()) swap(x, y);
  fa[y] = x;
  for (auto i : v[y]) v[x].push_back(i);
  v[y].clear();
  return true;
}
struct node {
  long long x, y, z;
  node(long long u = 0, long long v = 0, long long w = INF) {
    x = u, y = v, z = w;
  }
  friend bool operator<(const node &u, const node &v) { return u.z < v.z; }
};
inline void read(long long &x) {
  x = 0;
  char c = getchar();
  while (c > '9' || c < '0') c = getchar();
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
}
inline void print(long long x) {
  if (x <= 9)
    putchar('0' + x);
  else
    print(x / 10), putchar('0' + x % 10);
}
signed main() {
  read(n), read(m), memset(seg, 0x3f, sizeof(seg));
  for (long long i = 1; i <= n; i++)
    read(val[i]), fa[i] = i, v[i].push_back(i),
                  seg[0].modify(1, 1, n, i, val[i] - i * m),
                  seg[1].modify(1, 1, n, i, val[i] + i * m);
  while (v[find(1)].size() != n) {
    vector<node> edges;
    for (long long i = 1; i <= n; i++) {
      if (find(i) != i) continue;
      node ed;
      for (auto x : v[i])
        seg[0].modify(1, 1, n, x, INF), seg[1].modify(1, 1, n, x, INF);
      for (auto x : v[i]) {
        if (x > 1) {
          pair<long long, long long> p = seg[0].query(1, 1, n, 1, x - 1);
          long long y = p.second;
          ed = min(ed, node(y, x, val[y] + val[x] + (x - y) * m));
        }
        if (x < n) {
          pair<long long, long long> p = seg[1].query(1, 1, n, x + 1, n);
          long long y = p.second;
          ed = min(ed, node(x, y, val[x] + val[y] + (y - x) * m));
        }
      }
      for (auto x : v[i])
        seg[0].modify(1, 1, n, x, val[x] - x * m),
            seg[1].modify(1, 1, n, x, val[x] + x * m);
      edges.push_back(ed);
    }
    sort(edges.begin(), edges.end());
    for (auto i : edges)
      if (merge(i.x, i.y)) res += i.z;
  }
  print(res);
  return 0;
}
