#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + c - '0';
    c = getchar();
  }
  return x * f;
}
const int MAX_N = 1e3 + 10;
int H[MAX_N][MAX_N], CM[MAX_N][MAX_N], TM[MAX_N][MAX_N], N, M, A, B, SUM = 0;
long long S[MAX_N][MAX_N];
bool vis[MAX_N][MAX_N];
vector<pair<long long, pair<int, int> > > V, Ans;
struct MY_QUEUE {
  deque<pair<int, int> > Q;
  inline void reset() { Q.clear(); }
  inline void push(int val, int mark) {
    pair<int, int> now = make_pair(val, mark);
    while (Q.size() && Q.back().first > val) Q.pop_back();
    Q.push_back(make_pair(val, mark));
  }
  inline void pop(int mark) {
    if (Q.front().second == mark) Q.pop_front();
  }
  inline int get() { return Q.front().first; }
};
inline bool check_X(int x) { return x >= 0 && x < N; }
inline bool check_Y(int y) { return y >= 0 && y < M; }
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  N = read();
  M = read();
  A = read();
  B = read();
  for (int i = 0; i < N; i++)
    for (int j = 0; j < M; j++) H[i][j] = read();
  for (int i = 0; i < M; i++) {
    MY_QUEUE QUEUE;
    for (int j = 0; j < N; j++) {
      QUEUE.push(H[j][i], j);
      if (j >= A) QUEUE.pop(j - A);
      if (j >= A - 1) CM[j - A + 1][i] = QUEUE.get();
    }
  }
  for (int i = 0; i < N; i++) {
    MY_QUEUE QUEUE;
    for (int j = 0; j < M; j++) {
      QUEUE.push(CM[i][j], j);
      if (j >= B) QUEUE.pop(j - B);
      if (j >= B - 1) TM[i][j - B + 1] = QUEUE.get();
    }
  }
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= M; j++)
      S[i][j] = (long long)S[i][j] + S[i][j - 1] + H[i - 1][j - 1];
  for (int i = 1; i <= M; i++)
    for (int j = 1; j <= N; j++) S[j][i] = (long long)S[j][i] + S[j - 1][i];
  for (int i = 0; i <= N - A; i++)
    for (int j = 0; j <= M - B; j++) {
      long long sum = (long long)S[i + A][j + B] - S[i + A][j] - S[i][j + B] +
                      S[i][j],
                dec = (long long)TM[i][j] * A * B;
      V.push_back(make_pair(sum - dec, make_pair(i, j)));
    }
  sort(V.begin(), V.end());
  for (int i = 0; i < V.size(); i++) {
    long long val = V[i].first;
    int X = V[i].second.first, Y = V[i].second.second;
    if (vis[X][Y]) continue;
    SUM++;
    Ans.push_back(make_pair(val, make_pair(X + 1, Y + 1)));
    for (int i = X - A + 1; i <= X + A - 1; i++)
      for (int j = Y - B + 1; j <= Y + B - 1; j++)
        if (check_X(i) && check_Y(j)) vis[i][j] = 1;
  }
  printf("%d\n", SUM);
  for (int i = 0; i < Ans.size(); i++)
    printf("%d %d %I64d\n", Ans[i].second.first, Ans[i].second.second,
           Ans[i].first);
  return 0;
}
