#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = (long long)1000000007 * 1000000007;
const long double eps = 1e-8;
const long double pi = acos(-1.0);
template <typename T>
struct Kruskal {
  struct edge {
    int from, to;
    T cost;
    int used;
    edge(int from, int to, T cost) : from(from), to(to), cost(cost), used(0) {}
    bool operator<(const edge &e) const { return cost < e.cost; }
  };
  vector<int> r, p;
  vector<edge> es;
  vector<vector<pair<int, T>>> G;
  Kruskal() {}
  Kruskal(int n) : r(n, 1), p(n), G(n) { iota(p.begin(), p.end(), 0); }
  int find(int x) { return (x == p[x] ? x : p[x] = find(p[x])); }
  bool same(int x, int y) { return find(x) == find(y); }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (r[x] < r[y]) swap(x, y);
    r[x] += r[y];
    p[y] = x;
  }
  void add_edge(int u, int v, T c) { es.emplace_back(u, v, c); }
  T build() {
    sort(es.begin(), es.end());
    T res = 0;
    for (auto &e : es) {
      cout << e.from << " " << e.to << " " << e.cost << endl;
      if (!same(e.from, e.to)) {
        res += e.cost;
        unite(e.from, e.to);
        G[e.from].push_back(make_pair(e.to, e.cost));
        G[e.to].push_back(make_pair(e.from, e.cost));
        e.used = 1;
      }
    }
    return res;
  }
  vector<vector<pair<int, T>>> graph() { return G; }
};
int n;
long long d, a[200010];
vector<vector<pair<int, long long>>> G;
void rec(int l, int r, Kruskal<long long> &k) {
  if (r - l <= 1) return;
  int mid = (l + r) / 2;
  long long mi1 = INF;
  int idx1 = -1;
  for (int i = l; i < mid; i++) {
    if (mi1 > a[i] - d * (long long)i) {
      mi1 = a[i] - d * (long long)i;
      idx1 = i;
    }
  }
  for (int i = mid; i < r; i++) {
    k.add_edge(i, idx1, mi1 + a[i] + d * (long long)i);
  }
  long long mi2 = INF;
  int idx2 = -1;
  for (int i = mid; i < r; i++) {
    if (mi2 > a[i] + d * (long long)i) {
      mi2 = a[i] + d * (long long)i;
      idx2 = i;
    }
  }
  for (int i = l; i < mid; i++) {
    k.add_edge(i, idx2, mi2 + a[i] - d * (long long)i);
  }
  rec(l, mid, k);
  rec(mid, r, k);
}
void solve() {
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  Kruskal<long long> K(n);
  rec(0, n, K);
  cout << K.build() << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(50);
  solve();
}
