#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
struct hhh {
  long long x;
  long long y;
  long long v;
} c[1000001];
bool operator<(hhh a, hhh b) {
  return (a.v != b.v ? a.v > b.v : (a.x != b.x ? a.x > b.x : a.y > b.y));
}
vector<hhh> v;
long long n, m, a, b, h[1001][1001], g[1001][1001], mi[1001][1001],
    minf[1001][1001], k;
bool f[1001][1001];
long long pre[3][1001][1001];
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
bool check(hhh t) {
  if (f[t.x][t.y]) {
    return 0;
  }
  for (long long i = max(t.x - a + 1, (long long)1); i <= t.x + a - 1; i++) {
    for (long long j = max(t.y - b + 1, (long long)1); j <= t.y + b - 1; j++) {
      f[i][j] = 1;
    }
  }
  return 1;
}
int main() {
  n = read();
  m = read();
  a = read();
  b = read();
  for (long long i = 1; i <= (n); i++) {
    for (long long j = 1; j <= (m); j++) {
      h[i][j] = read();
    }
  }
  for (long long i = 1; i <= (n); i++) {
    for (long long j = 1; j <= (m); j++) {
      pre[1][i][j] = pre[1][i][j - 1] + h[i][j];
      pre[2][i][j] = pre[2][i - 1][j] + h[i][j];
    }
  }
  for (long long i = 1; i <= (a); i++) {
    g[1][1] += pre[1][i][b];
  }
  for (long long i = 2; i <= m - b + 1; i++) {
    g[1][i] = g[1][i - 1] + pre[2][a][i + b - 1] - pre[2][a][i - 1];
  }
  for (long long i = 2; i <= n - a + 1; i++) {
    for (long long j = 1; j <= (m - b + 1); j++) {
      g[i][j] = g[i - 1][j] + pre[1][i + a - 1][j + b - 1] -
                pre[1][i + a - 1][j - 1] - pre[1][i - 1][j + b - 1] +
                pre[1][i - 1][j - 1];
    }
  }
  for (long long i = 1; i <= (n); i++) {
    long long s = 1;
    long long t = 0;
    long long que[1001];
    que[0] = INF;
    for (long long j = 1; j <= (m); j++) {
      while (s <= t && h[i][que[t]] >= h[i][j]) {
        t--;
      }
      que[++t] = j;
      if (j - b >= 0) {
        mi[i][j - b + 1] = h[i][que[s]];
      }
      if (que[s] == j - b + 1) {
        s++;
      }
    }
  }
  for (long long j = 1; j <= (m - b + 1); j++) {
    long long s = 1;
    long long t = 0;
    long long que[1001];
    que[0] = INF;
    for (long long i = 1; i <= (n); i++) {
      while (s <= t && mi[que[t]][j] >= mi[i][j]) {
        t--;
      }
      que[++t] = i;
      if (i - a >= 0) {
        minf[i - a + 1][j] = mi[que[s]][j];
      }
      if (que[s] == i - a + 1) {
        s++;
      }
    }
  }
  for (long long i = 1; i <= (n - a + 1); i++) {
    for (long long j = 1; j <= (m - b + 1); j++) {
      g[i][j] -= a * b * minf[i][j];
      hhh t;
      t.x = i;
      t.y = j;
      t.v = g[i][j];
      v.push_back(t);
    }
  }
  make_heap(v.begin(), v.end());
  while (!v.empty()) {
    hhh t = v.front();
    pop_heap(v.begin(), v.end());
    v.pop_back();
    if (check(t)) {
      c[++k] = t;
    }
  }
  cout << k << endl;
  for (long long i = 1; i <= (k); i++) {
    printf("%I64d %I64d %I64d\n", c[i].x, c[i].y, c[i].v);
  }
  return 0;
}
