#include <bits/stdc++.h>
using namespace std;
int a, b, n, m;
int t[1002][1002];
long long s[1002][1002];
int g[1002][1002];
bool f[1002][1002];
struct elem {
  int xm, m;
  long long s, xs;
  elem(int xm_, long long xs_, int m_, long long s_) {
    xm = xm_;
    xs = xs_;
    m = m_;
    s = s_;
  }
  elem(int xm_, long long xs_) {
    xm = m = xm_;
    xs = s = xs_;
  }
};
stack<elem> s1, s2;
void clear() {
  while (!s1.empty()) s1.pop();
  while (!s2.empty()) s2.pop();
}
void add(long long xs, int xm) {
  if (s1.empty())
    s1.push(elem(xm, xs));
  else {
    elem temp = s1.top();
    s1.push(elem(xm, xs, (xm < temp.m ? xm : temp.m), 1ll * xs + temp.s));
  }
}
void remove() {
  if (s2.empty()) {
    elem temp = s1.top(), temp2 = elem(temp.xm, temp.xs);
    s1.pop();
    s2.push(temp2);
    while (!s1.empty()) {
      temp = s1.top();
      s1.pop();
      temp2 = elem(temp.xm, temp.xs, (temp.xm < temp2.m ? temp.xm : temp2.m),
                   1ll * temp.xs + temp2.s);
      s2.push(temp2);
    }
  }
  s2.pop();
}
long long stsum() {
  return (s1.empty() ? 0 * 1ll : s1.top().s) +
         (s2.empty() ? 0 * 1ll : s2.top().s);
}
int stmin() {
  return ((s1.empty() ? (int)(1E9 + 1) : s1.top().m) <
                  (s2.empty() ? (int)(1E9 + 1) : s2.top().m)
              ? (s1.empty() ? (int)(1E9 + 1) : s1.top().m)
              : (s2.empty() ? (int)(1E9 + 1) : s2.top().m));
}
bool cmp(pair<int, int> i, pair<int, int> j) {
  if (s[i.first][i.second] < s[j.first][j.second]) return true;
  if (s[i.first][i.second] > s[j.first][j.second]) return false;
  if (i.first < j.first) return true;
  if (i.first > j.first) return false;
  if (i.second < j.second) return true;
  if (i.second > j.second) return false;
}
int main() {
  scanf("%d%d%d%d", &n, &m, &a, &b);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) scanf("%d", &t[i][j]);
  for (int i = 0; i < n; i++) {
    clear();
    for (int j = 0; j < b; j++) add(t[i][j], t[i][j]);
    for (int j = 0; j <= m - b; j++) {
      s[i][j] = stsum();
      g[i][j] = stmin();
      remove();
      add(t[i][j + b], t[i][j + b]);
    }
  }
  for (int j = 0; j <= m - b; j++) {
    clear();
    for (int i = 0; i < a; i++) add(s[i][j], g[i][j]);
    for (int i = 0; i <= n - a; i++) {
      s[i][j] = stsum();
      g[i][j] = stmin();
      remove();
      add(s[i + a][j], g[i + a][j]);
    }
  }
  int k = a * b;
  for (int i = 0; i <= n - a; i++)
    for (int j = 0; j <= m - b; j++) s[i][j] -= k * 1ll * g[i][j];
  vector<pair<int, int> > res((n - a + 1) * (m - b + 1));
  k = 0;
  for (int i = 0; i <= n - a; i++)
    for (int j = 0; j <= m - b; j++) res[k] = make_pair(i, j), k++;
  sort(res.begin(), res.end(), cmp);
  vector<pair<int, int> > print;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) f[i][j] = false;
  for (k = 0; k < res.size(); k++) {
    int i = res[k].first, j = res[k].second;
    if (f[i][j]) continue;
    print.push_back(res[k]);
    for (int i1 = i + a - 1; i1 >= i - a + 1 && i1 >= 0; i1--)
      for (int j1 = j + b - 1; j1 >= j - b + 1 && j1 >= 0; j1--)
        f[i1][j1] = true;
  }
  printf("%d\n", print.size());
  for (int i = 0; i < print.size(); i++)
    printf("%d %d %I64d\n", print[i].first + 1, print[i].second + 1,
           s[print[i].first][print[i].second]);
  return 0;
}
