#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
using ll = long long;
const char E = '\n';
const int N = 1005;
const ll mod = 1e9 + 7;
ll n, m, A, B, pref[N][N], a[N][N];
void gorizontal() {
  for (int i = 1; i <= n; i++) {
    deque<pair<int, int> > mn;
    for (int j = 1; j <= m; j++) {
      while (mn.size() && a[i][j] < mn.front().first) {
        mn.pop_front();
      }
      mn.push_front({a[i][j], j});
      while (mn.size() && j - mn.back().second + 1 > B) {
        mn.pop_back();
      }
      if (j >= B) a[i][j - B + 1] = mn.back().first;
    }
  }
  m = m - B + 1;
}
void vertical() {
  for (int j = 1; j <= m; j++) {
    deque<pair<int, int> > mn;
    for (int i = 1; i <= n; i++) {
      while (mn.size() && a[i][j] < mn.front().first) {
        mn.pop_front();
      }
      mn.push_front({a[i][j], i});
      while (mn.size() && i - mn.back().second + 1 > A) {
        mn.pop_back();
      }
      if (i >= A) a[i - A + 1][j] = mn.back().first;
    }
  }
  n = n - A + 1;
}
void calc() {
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      a[i][j] = -1 * A * B * a[i][j] + pref[i + A - 1][j + B - 1] +
                pref[i - 1][j - 1] - pref[i + A - 1][j - 1] -
                pref[i - 1][j + B - 1];
    }
  }
}
int t[N][4 * N], o[N][4 * N];
void push(int v, int l, int r, int line) {
  if (l != r) {
    t[line][v * 2] += o[line][v];
    t[line][v * 2 + 1] += o[line][v];
    o[line][v * 2] += o[line][v];
    o[line][v * 2 + 1] += o[line][v];
    o[line][v] = 0;
  }
}
void update(int v, int l, int r, int tl, int tr, int line) {
  if (tl > tr || l > r || r < tl || l > tr) return;
  if (tl == l && r == tr) {
    t[line][v]++;
    o[line][v]++;
    return;
  }
  push(v, l, r, line);
  int mid = (l + r) >> 1;
  update(v * 2, l, mid, tl, min(mid, tr), line);
  update(v * 2 + 1, mid + 1, r, max(mid + 1, tl), tr, line);
  t[line][v] = t[line][v * 2] + t[line][v * 2 + 1];
}
int get(int v, int l, int r, int pos, int line) {
  if (l > pos || r < pos || l > r) return 0;
  if (l == r && l == pos) return t[line][v];
  push(v, l, r, line);
  int mid = (l + r) >> 1;
  if (mid >= pos) return get(v * 2, l, mid, pos, line);
  return get(v * 2 + 1, mid + 1, r, pos, line);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> A >> B;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
      pref[i][j] =
          a[i][j] + pref[i][j - 1] + pref[i - 1][j] - pref[i - 1][j - 1];
    }
  }
  gorizontal();
  vertical();
  calc();
  vector<pair<ll, pair<int, int> > > s;
  vector<pair<ll, pair<int, int> > > ans;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      s.push_back({a[i][j], {i, j}});
    }
  }
  sort(s.begin(), s.end());
  for (int i = 0; i < n * m; i++) {
    if (get(1, 1, m, s[i].second.second, s[i].second.first)) continue;
    int tl = max(1ll, s[i].second.second - B + 1);
    int tr = min(m, s[i].second.second + B - 1);
    for (int j = max(1ll, s[i].second.first - A + 1);
         j <= min(n, s[i].second.first + A - 1); j++) {
      update(1, 1, m, tl, tr, j);
    }
    ans.push_back(s[i]);
  }
  cout << ans.size() << E;
  for (auto i : ans) {
    cout << i.second.first << " " << i.second.second << " " << i.first << E;
  }
  return 0;
}
