intinp(){ char c = getchar(); while(c < '0' || c > '9') c = getchar(); int sum = 0; while(c >= '0' && c <= '9'){ sum = sum * 10 + c - '0'; c = getchar(); } return sum; }
int f[1010][1010][12]; std::multiset<ll> s2; int ans1[1000010], ans2[1000010], h[1010][1010]; ll ans3[1000010], sum[1010][1010], val[1010][1010]; bool used[1010][1010]; std::pair<int, int> s[1000010];
ll query(int x, int l, int r){ int lg = log2(r - l + 1); returnstd::min(f[x][l][lg], f[x][r - (1 << lg) + 1][lg]); }
boolcmp(std::pair<int, int> a, std::pair<int, int> b){ if(val[a.first][a.second] == val[b.first][b.second]) return a < b; return val[a.first][a.second] < val[b.first][b.second]; }
intmain(){ int n = inp(); int m = inp(); int a = inp(); int b = inp(); for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) f[i][j][0] = h[i][j] = inp(); for(int i = 1; i <= n; i++) for(int u = 1; u <= 10; u++) for(int j = 1; j <= m; j++) if(j + (1 << u) - 1 <= m) f[i][j][u] = std::min(f[i][j][u - 1], f[i][j + (1 << (u - 1))][u - 1]); for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + h[i][j]; for(int j = 1; j <= m - b + 1; j++){ s2.clear(); for(int i = 1; i <= a; i++) s2.insert(query(i, j, j + b - 1)); for(int i = 1; i <= n - a + 1; i++){ val[i][j] = sum[i + a - 1][j + b - 1] + sum[i - 1][j - 1] - sum[i + a - 1][j - 1] - sum[i - 1][j + b - 1] - (*(s2.begin())) * (a * b); s2.erase(s2.find(query(i, j, j + b - 1))); if(i + a <= n) s2.insert(query(i + a, j, j + b - 1)); } } int cc = 0; for(int i = 1; i <= n - a + 1; i++) for(int j = 1; j <= m - b + 1; j++) s[++cc] = std::make_pair(i, j); std::sort(s + 1, s + cc + 1, cmp); int cnt = 0; for(int u = 1; u <= cc; u++){ if(used[s[u].first][s[u].second]) continue; cnt++; ans1[cnt] = s[u].first; ans2[cnt] = s[u].second; ans3[cnt] = val[s[u].first][s[u].second]; for(int i = ans1[cnt] - a + 1; i <= ans1[cnt] + a - 1; i++) for(int j = ans2[cnt] - b + 1; j <= ans2[cnt] + b - 1; j++) if(i > 0 && j > 0 && !used[i][j] && i <= n - a + 1 && j <= m - b + 1) used[i][j] = true; } printf("%d\n", cnt); for(int i = 1; i <= cnt; i++) printf("%d %d %I64d\n", ans1[i], ans2[i], ans3[i]); }