#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
char *ch, buf[2049];
inline char get_char() {
  if (*ch == 0) {
    ch = buf;
    fread(buf, sizeof(char), 2048, stdin);
  }
  return *(ch++);
}
inline void next_int(int &ans) {
  ans = 0;
  char ch;
  while ((ch = get_char()) < '0' || ch > '9')
    ;
  do {
    ans = ans * 10 + ch - '0';
  } while ((ch = get_char()) >= '0' && ch <= '9');
}
int a, b, c, d, i, j, n, m, k, t, row;
int mas[1001][1001], csh[1001][1001];
long long cs[1001][1001];
multiset<int> s;
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    q;
pair<long long, int> ord[1000001];
bool u[1001][1001];
inline long long sum(int i, int j) {
  if (i < 0 || j < 0)
    return 0;
  else
    return cs[i][j];
}
pair<int, long long> ans[1000001];
int main() {
  ch = buf;
  next_int(n);
  next_int(m);
  next_int(a);
  next_int(b);
  for (int _n((n)-1), i(0); i <= _n; ++i) {
    while (!q.empty()) q.pop();
    for (int _n((m)-1), j(0); j <= _n; ++j) {
      next_int(mas[i][j]);
      q.push(make_pair(mas[i][j], j));
      int rr = 0;
      while (1) {
        if (q.top().second <= j - b) {
          q.pop();
          continue;
        }
        rr = q.top().first;
        break;
      }
      csh[i][j] = rr;
      if (!i && !j)
        cs[i][j] = mas[i][j];
      else if (!i)
        cs[i][j] = mas[i][j] + cs[i][j - 1];
      else if (!j)
        cs[i][j] = mas[i][j] + cs[i - 1][j];
      else
        cs[i][j] = mas[i][j] + cs[i - 1][j] + cs[i][j - 1] - cs[i - 1][j - 1];
    }
  }
  k = 0;
  for (int _n((m)-1), j(0); j <= _n; ++j) {
    while (!q.empty()) q.pop();
    for (int _n((n)-1), i(0); i <= _n; ++i) {
      q.push(make_pair(csh[i][j], i));
      c = 0;
      while (1) {
        if (q.top().second <= i - a) {
          q.pop();
          continue;
        }
        c = q.top().first;
        break;
      }
      long long rr = sum(i, j) - sum(i - a, j) - sum(i, j - b) +
                     sum(i - a, j - b) - (long long)c * a * b;
      ord[k++] = make_pair(rr, i * m + j);
    }
  }
  sort(ord, ord + k);
  for (int _n((k)-1), i(0); i <= _n; ++i) {
    int first = ord[i].second / m, second = ord[i].second % m;
    if (first - a + 1 < 0 || second - b + 1 < 0) continue;
    if (u[first][second] || u[first - a + 1][second - b + 1] ||
        u[first - a + 1][second] || u[first][second - b + 1])
      continue;
    for (int _n(first), z(first - a + 1); z <= _n; ++z)
      for (int _n(second), o(second - b + 1); o <= _n; ++o) u[z][o] = 1;
    ans[t++] = make_pair((first - a + 1) * m + second - b + 1, ord[i].first);
  }
  printf("%d\n", t);
  for (int _n((t)-1), i(0); i <= _n; ++i) {
    printf("%d %d %I64d\n", ans[i].first / m + 1, ans[i].first % m + 1,
           ans[i].second);
  }
}
