#include <iostream>
#include <deque>
using namespace std;
long long c401401;
deque <long long> Q;
int op, n, m, k;
int main(){ cin >> op >> n >> m >> k; for(int i = 1; i <= n; i++) for(int j = 1; j <=m; j++) cin >> c[i][j];
long long maxi = -1LL << 63, up, down, left, right; if(op == 1){ for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) c[i][j] += c[i-1][j] + c[i][j-1] – c[i-1][j-1]; for(int i = k; i <= n; i++) for(int j = k; j <= m; j++){ long long s = c[i][j] – c[i-k][j] – c[i][j-k] + c[i-k][j-k]; if(s > maxi){ maxi = s; up = i – k + 1; down = i; left = j – k + 1; right = j; } } cout << maxi << ‘\n’; cout << up << ‘ ‘ << left << ‘ ‘ << down << ‘ ‘ << right; } else{ for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) c[i][j] += c[i-1][j]; for(int i = 1; i <= n; i++) for(int j = i; j <= n && j <= i + k – 1; j ++){ long long H401; H0 = 0; while(Q.size()) Q.pop_back(); for(int f = 1; f <= m; f++) H[f] = H[f – 1] + c[j][f] – c[i – 1][f]; for(int f = 1; f <= m; f++){ while(Q.size() && H[Q.back()] >= H[f]) Q.pop_back(); Q.push_back(f); while(Q.front() < f – k) Q.pop_front(); if(H[f] – H[Q.front()] >= maxi){ maxi = H[f] – H[Q.front()]; up = i; left = Q.front() + 1; down = j; right = f; } } } cout << maxi << “\n” << up << ‘ ‘ << left << ‘ ‘ << down << ‘ ‘ << right; } return 0; }