#include <bits/stdc++.h>
using namespace std;
int v[1000][1000], vis[1000][1000];
int dp[1000][1000][10];
int po[10], vr[2 * 1000], vl[1000], ar[4 * 1000];
long long int sum[1000][1000];
void build(int l, int h, int p) {
  if (l == h)
    ar[p] = vl[l];
  else {
    int q = (l + h) / 2;
    build(l, q, 2 * p + 1);
    build(q + 1, h, 2 * p + 2);
    ar[p] = min(ar[2 * p + 1], ar[2 * p + 2]);
  }
  return;
}
int c, d;
int query(int l, int h, int p) {
  if (c > h || d < l) return 1e9;
  if (c <= l && d >= h) return ar[p];
  int q = (l + h) / 2;
  return min(query(l, q, 2 * p + 1), query(q + 1, h, 2 * p + 2));
}
int main() {
  int n, m, i, j, k, p, q, a, b, x, z;
  scanf("%d", &n), scanf("%d", &m), scanf("%d", &a), scanf("%d", &b);
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      scanf("%d", &v[i][j]);
      sum[i][j] = v[i][j];
      if (i > 0) sum[i][j] += sum[i - 1][j];
      if (j > 0) sum[i][j] += sum[i][j - 1];
      if (i > 0 & j > 0) sum[i][j] -= sum[i - 1][j - 1];
    }
  }
  vr[1] = 0, k = 1, po[0] = 1;
  while (k < 1000) {
    for (i = k + 1; i < 2 * k; i++) vr[i] = vr[k];
    vr[2 * k] = 1 + vr[k], k *= 2;
  }
  x = 1 + vr[n];
  for (i = 1; i < 10; i++) po[i] = 2 * po[i - 1];
  for (j = 0; j < m; j++) {
    for (i = 0; i < n; i++) dp[j][i][0] = v[i][j];
    for (k = 1; k < x; k++) {
      for (i = 0; i + po[k] <= n; i++)
        dp[j][i][k] = min(dp[j][i][k - 1], dp[j][i + po[k - 1]][k - 1]);
    }
  }
  k = (n - a + 1) * (m - b + 1);
  vector<pair<long long int, pair<int, int> > > vp(k), ans(k);
  long long int t, tp;
  k = 0;
  for (i = 0; i + a <= n; i++) {
    z = vr[a], c = a - po[z];
    for (j = 0; j < m; j++) vl[j] = min(dp[j][i][z], dp[j][i + c][z]);
    for (j = 0; j < 4 * 1000; j++) ar[j] = 0;
    build(0, m - 1, 0);
    for (j = 0; j + b <= m; j++) {
      t = sum[i + a - 1][j + b - 1];
      if (i > 0) t -= sum[i - 1][j + b - 1];
      if (j > 0) t -= sum[i + a - 1][j - 1];
      if (i > 0 & j > 0) t += sum[i - 1][j - 1];
      c = j, d = j + b - 1;
      x = query(0, m - 1, 0);
      tp = x, tp *= a, tp *= b;
      vp[k].first = t - tp, vp[k].second.first = i, vp[k].second.second = j;
      k++;
    }
  }
  x = 0;
  sort(vp.begin(), vp.end());
  for (z = 0; z < k; z++) {
    i = vp[z].second.first, j = vp[z].second.second;
    if (!vis[i][j]) {
      ans[x].first = vp[z].first, ans[x].second.first = 1 + vp[z].second.first,
      ans[x].second.second = 1 + vp[z].second.second;
      x++, c = min(n, i + a), d = min(m, j + b);
      for (p = max(0, i - a + 1); p < c; p++) {
        for (q = max(0, j - b + 1); q < d; q++) vis[p][q] = 1;
      }
    }
  }
  printf("%d\n", x);
  for (i = 0; i < x; i++)
    printf("%d ", ans[i].second.first), printf("%d ", ans[i].second.second),
        printf("%I64d\n", ans[i].first);
  return 0;
}
