#include <bits/stdc++.h>
using namespace std;
int K, N;
int A[100000];
int T[100001];
int main() {
  cin >> N >> K;
  int mia = N;
  T[0] = -1;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    mia = min(mia, A[i]);
  }
  int t = 0;
  for (int i = 0; i < N; i++) {
    if (A[i] == mia) {
      T[t] = i;
      T[t + 1] = -1;
    }
  }
  int st = -1;
  int go = T[0];
  int res = 0;
  t = 0;
  while (st < N) {
    if (go - st != 1) {
      res += (go - st + 1) / (K - 1);
    }
    cout << st << " " << go << " " << res << endl;
    t++;
    st = go + 1;
    if (T[t] == -1)
      go = N - 1;
    else
      go = T[t] - 1;
  }
  cout << res << endl;
  return 0;
}
