#include<bits/stdc++.h>
using namespace std;
const int N = 1e3;
int n, k, r, p;
long long ans;
long long a[N][N];
struct rect {
int x1, x2, y1, y2;
rect(int u, int v, int x, int y) {
x1=u; y1=v; x2=x; y2=y;
}
};
rect intersect(rect u, rect v) {
rect ans = rect(1, 1, n, n);
ans.x1 = max(u.x1, v.x1);
ans.x2 = min(u.x2, v.x2);
ans.y1 = max(u.y1, v.y1);
ans.y2 = min(u.y2, v.y2);
return ans;
}
long long get(rect u) {
if (u.x2 < u.x1 || u.y2 < u.y1) return 0;
return a[u.x2][u.y2]-a[u.x2][u.y1-1]-a[u.x1-1][u.y2]+a[u.x1-1][u.y1-1];
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> k >> r >> p;
for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) {
cin >> a[i][j];
a[i][j] += a[i][j-1]+a[i-1][j]-a[i-1][j-1];
}
ans = -1e9;
for (int i = 1; i <= k; i++) {
long long sum = 0;
vector<rect> rs;
for (int i = 1; i <= p; i++) {
int x, y; cin >> x >> y;
rs.push_back(rect(x, y, x+r-1, y+r-1));
}
for (int i = 1; i < (1 << p); i++) { //00001 -> 11111
int sign = (__builtin_popcount(i)&1)? 1: -1;
rect area = rect(1, 1, n, n);
for (int j = 0; j < p; j++) if (i&(1 << j)) { // 00001 00010 00100 01000 10000
area = intersect(area, rs[j]);
}
sum += sign*get(area)*1LL;
}
ans = max(ans, sum);
}
cout << ans << endl;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmNvbnN0IGludCBOID0gMWUzOwppbnQgbiwgaywgciwgcDsKbG9uZyBsb25nIGFuczsKbG9uZyBsb25nIGFbTl1bTl07CgpzdHJ1Y3QgcmVjdCB7CiAgICBpbnQgeDEsIHgyLCB5MSwgeTI7CiAgICByZWN0KGludCB1LCBpbnQgdiwgaW50IHgsIGludCB5KSB7CiAgICAgICAgeDE9dTsgeTE9djsgeDI9eDsgeTI9eTsKICAgIH0KfTsKCnJlY3QgaW50ZXJzZWN0KHJlY3QgdSwgcmVjdCB2KSB7CiAgICByZWN0IGFucyA9IHJlY3QoMSwgMSwgbiwgbik7CiAgICBhbnMueDEgPSBtYXgodS54MSwgdi54MSk7CiAgICBhbnMueDIgPSBtaW4odS54Miwgdi54Mik7CiAgICBhbnMueTEgPSBtYXgodS55MSwgdi55MSk7CiAgICBhbnMueTIgPSBtaW4odS55Miwgdi55Mik7CiAgICByZXR1cm4gYW5zOwp9Cgpsb25nIGxvbmcgZ2V0KHJlY3QgdSkgewogICAgaWYgKHUueDIgPCB1LngxIHx8IHUueTIgPCB1LnkxKSByZXR1cm4gMDsKICAgIHJldHVybiBhW3UueDJdW3UueTJdLWFbdS54Ml1bdS55MS0xXS1hW3UueDEtMV1bdS55Ml0rYVt1LngxLTFdW3UueTEtMV07Cn0KCmludCBtYWluKCkgewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbygwKTsgY2luLnRpZSgwKTsgY291dC50aWUoMCk7CiAgICBjaW4gPj4gbiA+PiBrID4+IHIgPj4gcDsKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IG47IGkrKykgZm9yIChpbnQgaiA9IDE7IGogPD0gbjsgaisrKSB7CiAgICAgICAgY2luID4+IGFbaV1bal07CiAgICAgICAgYVtpXVtqXSArPSBhW2ldW2otMV0rYVtpLTFdW2pdLWFbaS0xXVtqLTFdOwogICAgfQoKICAgIGFucyA9IC0xZTk7CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBrOyBpKyspIHsKICAgICAgICBsb25nIGxvbmcgc3VtID0gMDsKICAgICAgICB2ZWN0b3I8cmVjdD4gcnM7CiAgICAgICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gcDsgaSsrKSB7CiAgICAgICAgICAgIGludCB4LCB5OyBjaW4gPj4geCA+PiB5OwogICAgICAgICAgICBycy5wdXNoX2JhY2socmVjdCh4LCB5LCB4K3ItMSwgeStyLTEpKTsKICAgICAgICB9CiAgICAgICAgZm9yIChpbnQgaSA9IDE7IGkgPCAoMSA8PCBwKTsgaSsrKSB7IC8vMDAwMDEgLT4gMTExMTEKICAgICAgICAgICAgaW50IHNpZ24gPSAoX19idWlsdGluX3BvcGNvdW50KGkpJjEpPyAxOiAtMTsKICAgICAgICAgICAgcmVjdCBhcmVhID0gcmVjdCgxLCAxLCBuLCBuKTsKCiAgICAgICAgICAgIGZvciAoaW50IGogPSAwOyBqIDwgcDsgaisrKSBpZiAoaSYoMSA8PCBqKSkgeyAvLyAwMDAwMSAwMDAxMCAwMDEwMCAwMTAwMCAxMDAwMAogICAgICAgICAgICAgICAgYXJlYSA9IGludGVyc2VjdChhcmVhLCByc1tqXSk7CiAgICAgICAgICAgIH0KCiAgICAgICAgICAgIHN1bSArPSBzaWduKmdldChhcmVhKSoxTEw7CiAgICAgICAgfQoKICAgICAgICBhbnMgPSBtYXgoYW5zLCBzdW0pOwogICAgfQogICAgY291dCA8PCBhbnMgPDwgZW5kbDsKfQ==