#include <bits/stdc++.h>
using namespace std;
int n, m;
int a, b;
void Sumy(vector<vector<long long> >& p, vector<vector<long long> >& sumy) {
  vector<vector<long long> > s(n, vector<long long>(m, 0));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      s[i][j] = p[i][j];
      if (i != 0) s[i][j] += s[i - 1][j];
      if (j != 0) s[i][j] += s[i][j - 1];
      if (i != 0 && j != 0) s[i][j] -= s[i - 1][j - 1];
      if (i + 1 >= a && j + 1 >= b) {
        sumy[i][j] = s[i][j];
        if (i != a - 1) sumy[i][j] -= s[i - a][j];
        if (j != b - 1) sumy[i][j] -= s[i][j - b];
        if (i != a - 1 && j != b - 1) sumy[i][j] += s[i - a][j - b];
      }
    }
  }
}
void Miny(vector<vector<long long> >& p, vector<vector<long long> >& miny) {
  vector<vector<long long> > poz(n, vector<long long>(m, 0));
  for (int i = 0; i < n; ++i) {
    multiset<long long> S;
    for (int j = 0; j < m; ++j) {
      if (j + 1 <= b)
        S.insert(p[i][j]);
      else {
        S.erase(S.find(p[i][j - b]));
        S.insert(p[i][j]);
      }
      if (j + 1 >= b) poz[i][j] = *S.begin();
    }
  }
  vector<vector<long long> > pio(n, vector<long long>(m, 0));
  for (int j = 0; j < m; ++j) {
    if (j + 1 >= b) {
      multiset<long long> S;
      for (int i = 0; i < n; ++i) {
        if (i + 1 <= a)
          S.insert(poz[i][j]);
        else {
          S.erase(S.find(poz[i - a][j]));
          S.insert(poz[i][j]);
        }
        if (i + 1 >= a) pio[i][j] = *S.begin();
      }
    }
  }
  miny = pio;
}
int main() {
  scanf("%d %d %d %d", &n, &m, &a, &b);
  vector<vector<long long> > p(n, vector<long long>(m));
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) scanf("%I64d", &p[i][j]);
  vector<vector<long long> > sumy(n, vector<long long>(m, 0));
  Sumy(p, sumy);
  vector<vector<long long> > miny(n, vector<long long>(m));
  Miny(p, miny);
  vector<vector<long long> > W(n, vector<long long>(m, 0));
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (i + a - 1 <= n - 1 && j + b - 1 <= m - 1)
        W[i][j] =
            sumy[i + a - 1][j + b - 1] - a * b * miny[i + a - 1][j + b - 1];
  vector<pair<long long, pair<int, int> > > S;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (i + a - 1 <= n - 1 && j + b - 1 <= m - 1)
        S.push_back(make_pair(W[i][j], make_pair(i, j)));
  sort(S.begin(), S.end());
  vector<pair<int, pair<int, long long> > > odp;
  vector<vector<bool> > bylo(n, vector<bool>(m, false));
  for (int akt = 0; akt < S.size(); ++akt) {
    pair<long long, pair<int, int> > t = S[akt];
    int x = t.second.first;
    int y = t.second.second;
    long long usu = t.first;
    if (bylo[x][y]) continue;
    for (int i = max(0, x - a + 1); i <= x + a - 1; ++i)
      for (int j = max(0, y - b + 1); j <= y + b - 1; ++j) bylo[i][j] = true;
    odp.push_back(make_pair(x, make_pair(y, usu)));
  }
  printf("%d\n", odp.size());
  for (int i = 0; i < odp.size(); ++i)
    printf("%d %d %I64d\n", odp[i].first + 1, odp[i].second.first + 1,
           odp[i].second.second);
  return 0;
}
