#include <bits/stdc++.h>
using namespace std;
const int MX = 1003;
int ans[MX * MX][2];
int a[MX][MX], bit[MX][MX];
int cm[MX][MX], mn[MX][MX];
;
long long cs[MX][MX], sum[MX][MX];
pair<long long, pair<int, int>> ar[MX * MX];
void upd(int i, int j, int n, int m) {
  while (i <= n) {
    int k = j;
    while (k <= m) {
      bit[i][k]++;
      k += k & -k;
    }
    i += i & -i;
  }
}
int qry(int i, int j) {
  int s = 0;
  while (i > 0) {
    int k = j;
    while (k > 0) {
      s += bit[i][k];
      k -= k & -k;
    }
    i -= i & -i;
  }
  return s;
}
int summ(int u, int l, int d, int r) {
  int x = qry(d, r);
  x -= qry(d, l - 1) + qry(u - 1, r);
  return x + qry(u - 1, l - 1);
}
void col_min(int n, int c, int k) {
  deque<int> q;
  for (int i = 0; i < n; i++) {
    if (!q.empty() && q.front() <= i - k) q.pop_front();
    while (!q.empty() && a[q.back()][c] > a[i][c]) q.pop_back();
    q.push_back(i);
    if (i >= k - 1) cm[i - k + 1][c] = a[q.front()][c];
  }
}
void row_min(int n, int r, int k) {
  deque<int> q;
  for (int i = 0; i < n; i++) {
    if (!q.empty() && q.front() <= i - k) q.pop_front();
    while (!q.empty() && cm[r][q.back()] > cm[r][i]) q.pop_back();
    q.push_back(i);
    if (i >= k - 1) mn[r][i - k + 1] = cm[r][q.front()];
  }
}
void calc(int n, int m, int p, int q) {
  for (int i = 0; i < m; i++) col_min(n, i, p);
  for (int i = 0; i < n; i++) row_min(m, i, q);
  for (int j = 0; j < m; j++) {
    for (int i = n - 1; i >= 0; i--) {
      cs[i][j] = (long long)a[i][j] + cs[i + 1][j];
      if (i + p < n) cs[i][j] -= a[i + p][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = m - 1; j >= 0; j--) {
      sum[i][j] = cs[i][j] + sum[i][j + 1];
      if (j + q < m) sum[i][j] -= cs[i][j + q];
    }
  }
}
int main() {
  int n, m, p, q, k = 0, l = 0;
  scanf("%d %d %d %d", &n, &m, &p, &q);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  calc(n, m, p, q);
  for (int i = 0; i + p <= n; i++) {
    for (int j = 0; j + q <= m; j++) {
      long long c = sum[i][j] - (long long)(p * q) * (long long)mn[i][j];
      ar[l++] = {c, {i, j}};
    }
  }
  sort(ar, ar + l);
  for (int z = 0; z < l; z++) {
    pair<long long, pair<int, int>> pr = ar[z];
    int i = pr.second.first;
    int j = pr.second.second;
    int v = summ(i + 1, j + 1, i + p, j + q);
    if (v == 0) {
      ans[k][0] = i;
      ans[k++][1] = j;
      upd(i + 1, j + 1, n, m);
      upd(i + 1, j + q, n, m);
      upd(i + p, j + 1, n, m);
      upd(i + p, j + q, n, m);
    }
  }
  printf("%d\n", k);
  for (int z = 0; z < k; z++) {
    int i = ans[z][0], j = ans[z][1];
    long long c = sum[i][j] - (long long)(p * q) * (long long)mn[i][j];
    printf("%d %d %lld\n", i + 1, j + 1, c);
  }
  return 0;
}
