#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:200000000")
const double EPS = 1E-9;
const int INF = 1000000000;
const long long INF64 = (long long)1E18;
const double PI = 3.1415926535897932384626433832795;
int h[1100][1100], mi[1100][1100], f[1100][1100];
long long sum[1100][1100], sum2[1100][1100];
bool pres[1100];
deque<pair<int, int> > st;
void add(int val, int id) {
  while (!st.empty() && st.back().first >= val) {
    pres[st.back().second] = false;
    st.pop_back();
  }
  st.push_back(make_pair(val, id));
  pres[id] = true;
}
void del(int val, int id) {
  if (!pres[id]) return;
  pres[id] = false;
  st.pop_front();
}
int n, m;
int f_sum(int x, int y) {
  int res = 0;
  for (int i = x; i >= 0; i = (i & (i + 1)) - 1)
    for (int j = y; j >= 0; j = (j & (j + 1)) - 1) res += f[i][j];
  return res;
}
void f_add(int x, int y) {
  for (int i = x; i < n; i = (i | (i + 1)))
    for (int j = y; j < m; j = (j | (j + 1))) f[i][j]++;
}
int f_sum(int x1, int y1, int x2, int y2) {
  int res = f_sum(x2, y2);
  if (x1) res -= f_sum(x1 - 1, y2);
  if (y1) res -= f_sum(x2, y1 - 1);
  if (x1 && y1) res += f_sum(x1 - 1, y1 - 1);
  return res;
}
int main() {
  int a, b;
  scanf("%d%d%d%d", &n, &m, &a, &b);
  for (int i = 0; i < (int)(n); i++)
    for (int j = 0; j < (int)(m); j++) scanf("%I64d", &h[i][j]);
  for (int i = 0; i < (int)(n); i++)
    for (int j = 0; j < (int)(m); j++) {
      sum2[i][j] = h[i][j];
      if (i) sum2[i][j] += sum2[i - 1][j];
      if (j) sum2[i][j] += sum2[i][j - 1];
      if (i && j) sum2[i][j] -= sum2[i - 1][j - 1];
    }
  for (int i = 0; i < (int)(n); i++)
    for (int j = 0; j < (int)(m); j++) {
      sum[i][j] = sum2[i][j];
      if (i - a >= 0) sum[i][j] -= sum2[i - a][j];
      if (j - b >= 0) sum[i][j] -= sum2[i][j - b];
      if (i - a >= 0 && j - b >= 0) sum[i][j] += sum2[i - a][j - b];
    }
  for (int y = 0; y < (int)(m); y++) {
    memset(pres, 0, sizeof(pres));
    st.clear();
    for (int x = 0; x < (int)(a); x++) add(h[x][y], x);
    mi[a - 1][y] = st[0].first;
    for (int x = (int)(a); x < (int)(n); x++) {
      add(h[x][y], x);
      del(h[x - a][y], x - a);
      mi[x][y] = st[0].first;
    }
  }
  vector<pair<long long, pair<int, int> > > ev;
  ev.reserve(n * m);
  for (int x = (int)(a - 1); x < (int)(n); x++) {
    memset(pres, 0, sizeof(pres));
    st.clear();
    for (int i = 0; i < (int)(b); i++) add(mi[x][i], i);
    ev.push_back(make_pair(sum[x][b - 1] - st[0].first * 1LL * a * 1LL * b,
                           make_pair(x, b - 1)));
    for (int y = (int)(b); y < (int)(m); y++) {
      add(mi[x][y], y);
      del(mi[x][y - b], y - b);
      ev.push_back(make_pair(sum[x][y] - st[0].first * 1LL * a * 1LL * b,
                             make_pair(x, y)));
    }
  }
  sort(ev.begin(), ev.end());
  vector<pair<pair<int, int>, long long> > e;
  for (int i = 0; i < (int)(ev.size()); i++) {
    int x = ev[i].second.first;
    int y = ev[i].second.second;
    int ss = f_sum(x - a + 1, y - b + 1, x, y);
    if (ss) continue;
    e.push_back(
        make_pair(make_pair(x - a + 1 + 1, y - b + 1 + 1), ev[i].first));
    f_add(x - a + 1, y - b + 1);
    f_add(x - a + 1, y);
    f_add(x, y - b + 1);
    f_add(x, y);
  }
  printf("%d\n", e.size());
  for (int i = 0; i < (int)(e.size()); i++)
    printf("%d %d %I64d\n", e[i].first.first, e[i].first.second, e[i].second);
  return 0;
}
