#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
void __never(int a) { printf("\nOPS %d", a); }
int n, m, A, B;
int M[1024][1024];
long long S[1024][1024];
int minH[1024][1024];
long long dp1[1024][1024];
int dp2[1024][1024];
int T[1024][1024];
pair<long long, pair<int, int> > S2[1024 * 1024];
int s2sz = 0;
bool F[1024 * 1024];
void xset(int x, int y) {
  for (int a = x; a <= n; a |= (a + 1))
    for (int b = y; b <= m; b |= (b + 1)) T[a][b]++;
}
int xget(int x, int y) {
  int re = 0;
  for (int a = x; a >= 0; a = (a & (a + 1)) - 1)
    for (int b = y; b >= 0; b = (b & (b + 1)) - 1) re += T[a][b];
  return re;
}
void sol() {
  multiset<int> Set;
  for (int a = (1); a <= (n); a++) {
    Set.clear();
    for (int b = (1); b <= (m); b++) {
      Set.insert(M[a][b]);
      if ((int)((Set).size()) > B) Set.erase(Set.find(M[a][b - B]));
      if ((int)((Set).size()) == B) minH[a][b] = (*Set.begin());
    }
  }
  for (int b = (1); b <= (m); b++) {
    Set.clear();
    for (int a = (1); a <= (n); a++) {
      Set.insert(minH[a][b]);
      if ((int)((Set).size()) > A) Set.erase(Set.find(minH[a - A][b]));
      if ((int)((Set).size()) == A) dp2[a][b] = (*Set.begin());
    }
  }
  for (int a = (1); a <= (n); a++)
    for (int b = (1); b <= (m); b++)
      S[a][b] = S[a - 1][b] + S[a][b - 1] - S[a - 1][b - 1] + M[a][b];
  for (int a = (A); a <= (n); a++)
    for (int b = (B); b <= (m); b++)
      dp1[a][b] = S[a][b] - S[a - A][b] - S[a][b - B] + S[a - A][b - B];
  for (int a = (A); a <= (n); a++)
    for (int b = (B); b <= (m); b++)
      S2[s2sz++] = (make_pair(
          dp1[a][b] - (long long)dp2[a][b] * (long long)A * (long long)B,
          make_pair(a, b)));
  sort(S2, S2 + s2sz);
  int ans = 0;
  for (int i = (0); i <= (s2sz - 1); i++) {
    int x = S2[i].second.first;
    int y = S2[i].second.second;
    if (xget(x, y) - xget(x - A, y) - xget(x, y - B) + xget(x - A, y - B) ==
        0) {
      ans++;
      F[i] = true;
      for (int a = (x - A + 1); a <= (x); a++)
        for (int b = (y - B + 1); b <= (y); b++) xset(a, b);
    }
  }
  printf("%d\n", ans);
  for (int a = (0); a <= (s2sz - 1); a++)
    if (F[a]) {
      int x = S2[a].second.first;
      int y = S2[a].second.second;
      long long ea = S2[a].first;
      printf("%d %d %lld\n", x - A + 1, y - B + 1, ea);
    }
}
int main() {
  scanf("%d%d%d%d", &n, &m, &A, &B);
  for (int a = (1); a <= (n); a++)
    for (int b = (1); b <= (m); b++) scanf("%d", &M[a][b]);
  sol();
  return 0;
}
