#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> dat[1000000];
long long u;
long long inf = 1000000000000000000;
long long par[200010];
long long len[200010];
void init(long long n) {
  for (long long i = 0; i < n; i++) {
    par[i] = i;
    len[i] = 0;
  }
}
long long root(long long n) {
  if (par[n] == n) return n;
  return par[n] = root(par[n]);
}
void unit(long long a, long long b) {
  a = root(a);
  b = root(b);
  if (a == b) return;
  if (len[a] > len[b])
    par[b] = a;
  else {
    par[a] = b;
    if (len[a] == len[b]) len[b]++;
  }
}
void add(long long n, long long x) {
  long long now = n + u - 1;
  dat[now] = make_pair(x, now - u + 1);
  while (now > 0) {
    now = (now - 1) / 2;
    dat[now] = min(dat[2 * now + 1], dat[2 * now + 2]);
  }
}
pair<long long, long long> que(long long a, long long b, long long k,
                               long long l, long long r) {
  if (a >= r || b <= l) return make_pair(inf, 0);
  if (a <= l && b >= r) return dat[k];
  pair<long long, long long> c = que(a, b, 2 * k + 1, l, (l + r) / 2);
  pair<long long, long long> d = que(a, b, 2 * k + 2, (l + r) / 2, r);
  return min(c, d);
}
int main() {
  long long n, d;
  cin >> n >> d;
  for (long long i = 0;; i++) {
    long long j = pow(2, i);
    if (j >= n - 1) {
      u = j;
      break;
    }
  }
  init(n);
  fill(dat, dat + 2 * u, make_pair(inf, 0));
  long long a[n];
  vector<pair<long long, long long> > ai(n), aj(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    ai[i] = make_pair(a[i] - i * d, i);
    aj[i] = make_pair(a[i] + i * d, i);
  }
  sort(aj.begin(), aj.end());
  long long num[n];
  for (long long i = 0; i < n - 1; i++) {
    for (long long j = 0; j < n; j++) {
      if (aj[j].second > i) {
        num[i] = j;
        break;
      }
    }
  }
  for (long long i = 0; i < n - 1; i++) {
    add(i, aj[num[i]].first + ai[i].first);
  }
  long long now = 1;
  long long ans = 0;
  for (;;) {
    pair<long long, long long> p = que(0, n, 0, 0, n);
    long long ps = p.second;
    long long pf = p.first;
    long long nj = aj[num[ps]].second;
    cout << ps << " " << nj << endl;
    if (root(nj) != root(ps)) {
      ans += pf;
      unit(ps, nj);
      now++;
      long long nu = -1;
      for (long long i = num[ps] + 1; i < n; i++) {
        if (aj[i].second > ps) {
          num[ps] = i;
          break;
        }
      }
      if (nu == -1) {
        add(0, inf);
      } else {
        add(ps, aj[num[ps]].first + ai[ps].first);
      }
    }
    if (now == n) {
      break;
    }
  }
  cout << ans << endl;
}
