#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#pragma GCC optimize(3)
#pragma G++ optimize(3)
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
using namespace std;
const int INF = 2147483647;
inline void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
inline int pt(int a[], int l, int r) {
  int p, i, j;
  p = a[l];
  i = l;
  j = r + 1;
  for (;;) {
    while (a[++i] < p)
      if (i >= r) break;
    while (a[--j] > p)
      if (j <= l) break;
    if (i >= j)
      break;
    else
      swap(a[i], a[j]);
  }
  if (j == l) return j;
  swap(a[l], a[j]);
  return j;
}
inline void q_sort(int a[], int l, int r) {
  int q;
  if (r > l) {
    q = pt(a, l, r);
    q_sort(a, l, q - 1);
    q_sort(a, q + 1, r);
  }
}
inline void write(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
inline void rd(long long &val) {
  long long x = 0;
  int f = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') {
    f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  val = x * f;
}
inline void rd(int &val) {
  int x = 0;
  int f = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') {
    f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  val = x * f;
}
inline void _write(long long x) {
  write(x);
  putchar(' ');
}
inline void print(long long x) {
  write(x);
  putchar('\n');
}
int n, m, a, b;
int x[1002][1002], ok[1002][1002];
long long s[1002][1002];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int i, j, f, p, q;
  rd(n), rd(m), rd(a), rd(b);
  for (i = 1; i <= n; i++) {
    deque<pair<int, int> > deq;
    for (j = 1; j <= m; j++) {
      rd(x[i][j]);
      while (deq.size() && deq[0].second + b <= j) deq.pop_front();
      while (deq.size() && x[i][j] <= deq.back().first) deq.pop_back();
      deq.push_back({x[i][j], j});
      s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + x[i][j];
      x[i][j] = deq[0].first;
    }
  }
  for (j = 1; j <= m; j++) {
    deque<pair<int, int> > deq;
    for (i = 1; i <= n; i++) {
      while (deq.size() && deq[0].second + a <= i) deq.pop_front();
      while (deq.size() && x[i][j] <= deq.back().first) deq.pop_back();
      deq.push_back(make_pair(x[i][j], i));
      x[i][j] = deq[0].first;
    }
  }
  deque<pair<long long, pair<int, int> > > ans, deq;
  long long sum;
  for (i = a; i <= n; i++) {
    for (j = b; j <= m; j++) {
      sum = s[i][j] - s[i - a][j] - s[i][j - b] + s[i - a][j - b];
      deq.push_back(make_pair(sum - 1ll * x[i][j] * a * b, make_pair(i, j)));
    }
  }
  sort(deq.begin(), deq.end());
  for (auto it : deq) {
    p = it.second.first;
    q = it.second.second;
    if (ok[p][q]) continue;
    for (i = p - a + 1; i < p + a; i++)
      for (j = q - b + 1; j < q + b; j++) ok[i][j] = 1;
    ans.push_back(make_pair(it.first, make_pair(p - a + 1, q - b + 1)));
  }
  print(ans.size());
  for (auto it : ans)
    _write(it.second.first), _write(it.second.second), print(it.first);
  return 0;
}
