#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;

#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define bpp __builtin_popcount
#define sqr(x) ((x) * (x))
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;

const int mod = (int)1e9 + 7;
const int N = (int)2e5 + 123;
const ll inf = (ll)3e18 + 1;

const double pi = acos(-1.0);
const double eps = 1e-7;
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, m, k, p, a[1001][1001], add[4004], add1[4004], ans, c, r;
pii row[4004], col[4004];

void push (int v, int tl, int tr) {
	if (add[v] == 0) return;
	row[v].F += add[v];
	if (tl != tr) {
		add[v + v] += add[v];
		add[v + v + 1] += add[v];
	}
	add[v] = 0;
}

void push1 (int v, int tl, int tr) {
	if (add1[v] == 0) return;
	col[v].F += add1[v];
	if (tl != tr) {
		add1[v + v] += add1[v];
		add1[v + v + 1] += add1[v];
	}
	add1[v] = 0;

}

void upd (int pos, int val, int v = 1, int tl = 1, int tr = n) {
	push (v, tl, tr);
	if (tl == tr) {
		row[v].F += val;
		row[v].S = pos;
		return;
	}
	int tm = tl + tr >> 1;
	if (pos <= tm) upd (pos, val, v + v, tl, tm);
	else upd (pos, val, v + v + 1, tm + 1, tr);
	if (row[v + v].F > row[v + v + 1].F) row[v] = row[v + v];
	else row[v] = row[v + v + 1];
}

void upd1 (int pos, int val, int v = 1, int tl = 1, int tr = m) {
	push1 (v, tl, tr);
	if (tl == tr) {
		col[v].F += val;
		col[v].S = pos;
		return;
	}
	int tm = tl + tr >> 1;
	if (pos <= tm) upd1 (pos, val, v + v, tl, tm);
	else upd1 (pos, val, v + v + 1, tm + 1, tr);
	if (col[v + v].F > col[v + v + 1].F) col[v] = col[v + v];
	else col[v] = col[v + v + 1];
}

void update (int l, int r, int val, int v = 1, int tl = 1, int tr = n) {
	push (v, tl, tr);
	if (tl > r || tr < l) return;
	if (l <= tl && tr <= r) {
		add[v] += val;
	   push (v, tl, tr);
		return;
	}
	int tm = tl + tr >> 1;
	update (l, r, val, v + v, tl, tm);
	update (l, r, val, v + v + 1, tm + 1, tr);
	if (row[v + v].F > row[v + v + 1].F) row[v] = row[v + v];
	else row[v] = row[v + v + 1];

}

void update1 (int l, int r, int val, int v = 1, int tl = 1, int tr = m) {
	push1 (v, tl, tr);
	if (tl > r || tr < l) return;
	if (l <= tl && tr <= r) {
		add1[v] += val;
		push1 (v, tl, tr);
		return;
	}
	int tm = tl + tr >> 1;
	update1 (l, r, val, v + v, tl, tm);
	update1 (l, r, val, v + v + 1, tm + 1, tr);
	if (col[v + v].F > col[v + v + 1].F) col[v] = col[v + v];
	else col[v] = col[v + v + 1];
}

inline void boost () {
	ios_base :: sync_with_stdio (NULL);
	cin.tie (NULL), cout.tie (NULL);
}

inline void Solve () {
	cin >> n >> m >> k >> p;
	for(int i = 1; i <= n; i ++)
		for (int j = 1; j <= m; j ++) {
			cin >> a[i][j];
			upd (i, a[i][j]);
			upd1 (j, a[i][j]);
		}
	while (k --) {

		update (1, 1, 0);
		update (n, n, 0);
		update1 (1, 1, 0);
		update1 (m, m, 0);
		if (row[1].F > col[1].F) {
		  // cout << "1\n";
			ans += row[1].F;
			upd (row[1].S, -m * p);
//			for (int i = 1; i <= m; i ++) upd1 (i, -p);
			update1 (1, m, -p);
		}
		else {
	//		cout << "2\n";
			ans += col[1].F;
			upd1 (col[1].S, -n * p);
//			for (int i = 1; i <= n; i ++) upd (i, -p);
			update (1, n, -p);
		}
	}
	cout << ans;
}

int main () {
//	freopen (".in", "r", stdin);
//	freopen (".out", "w", stdout);
	boost ();
	int tt = 1;
//	cin >> tt;
	while (tt --) {
		Solve ();
	}
	return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;

#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define bpp __builtin_popcount
#define sqr(x) ((x) * (x))
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;

const int mod = (int)1e9 + 7;
const int N = (int)2e5 + 123;
const ll inf = (ll)3e18 + 1;

const double pi = acos(-1.0);
const double eps = 1e-7;
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, m, k, p, a[1001][1001], add[4004], add1[4004], ans, c, r;
pii row[4004], col[4004];

void push (int v, int tl, int tr) {
	if (add[v] == 0) return;
	row[v].F += add[v];
	if (tl != tr) {
		add[v + v] += add[v];
		add[v + v + 1] += add[v];
	}
	add[v] = 0;
}

void push1 (int v, int tl, int tr) {
	if (add1[v] == 0) return;
	col[v].F += add1[v];
	if (tl != tr) {
		add1[v + v] += add1[v];
		add1[v + v + 1] += add1[v];
	}
	add1[v] = 0;

}

void upd (int pos, int val, int v = 1, int tl = 1, int tr = n) {
	push (v, tl, tr);
	if (tl == tr) {
		row[v].F += val;
		row[v].S = pos;
		return;
	}
	int tm = tl + tr >> 1;
	if (pos <= tm) upd (pos, val, v + v, tl, tm);
	else upd (pos, val, v + v + 1, tm + 1, tr);
	if (row[v + v].F > row[v + v + 1].F) row[v] = row[v + v];
	else row[v] = row[v + v + 1];
}

void upd1 (int pos, int val, int v = 1, int tl = 1, int tr = m) {
	push1 (v, tl, tr);
	if (tl == tr) {
		col[v].F += val;
		col[v].S = pos;
		return;
	}
	int tm = tl + tr >> 1;
	if (pos <= tm) upd1 (pos, val, v + v, tl, tm);
	else upd1 (pos, val, v + v + 1, tm + 1, tr);
	if (col[v + v].F > col[v + v + 1].F) col[v] = col[v + v];
	else col[v] = col[v + v + 1];
}

void update (int l, int r, int val, int v = 1, int tl = 1, int tr = n) {
	push (v, tl, tr);
	if (tl > r || tr < l) return;
	if (l <= tl && tr <= r) {
		add[v] += val;
	   push (v, tl, tr);
		return;
	}
	int tm = tl + tr >> 1;
	update (l, r, val, v + v, tl, tm);
	update (l, r, val, v + v + 1, tm + 1, tr);
	if (row[v + v].F > row[v + v + 1].F) row[v] = row[v + v];
	else row[v] = row[v + v + 1];

}

void update1 (int l, int r, int val, int v = 1, int tl = 1, int tr = m) {
	push1 (v, tl, tr);
	if (tl > r || tr < l) return;
	if (l <= tl && tr <= r) {
		add1[v] += val;
		push1 (v, tl, tr);
		return;
	}
	int tm = tl + tr >> 1;
	update1 (l, r, val, v + v, tl, tm);
	update1 (l, r, val, v + v + 1, tm + 1, tr);
	if (col[v + v].F > col[v + v + 1].F) col[v] = col[v + v];
	else col[v] = col[v + v + 1];
}

inline void boost () {
	ios_base :: sync_with_stdio (NULL);
	cin.tie (NULL), cout.tie (NULL);
}

inline void Solve () {
	cin >> n >> m >> k >> p;
	for(int i = 1; i <= n; i ++)
		for (int j = 1; j <= m; j ++) {
			cin >> a[i][j];
			upd (i, a[i][j]);
			upd1 (j, a[i][j]);
		}
	while (k --) {
		update (row[1].S, row[1].S, 0);
		update1 (col[1].S, col[1].S, 0);
		if (row[1].F > col[1].F) {
		  // cout << "1\n";
			ans += row[1].F;
			upd (row[1].S, -m * p);
//			for (int i = 1; i <= m; i ++) upd1 (i, -p);
			update1 (1, m, -p);
		}
		else {
	//		cout << "2\n";
			ans += col[1].F;
			upd1 (col[1].S, -n * p);
//			for (int i = 1; i <= n; i ++) upd (i, -p);
			update (1, n, -p);
		}
	}
	cout << ans;
}

int main () {
//	freopen (".in", "r", stdin);
//	freopen (".out", "w", stdout);
	boost ();
	int tt = 1;
//	cin >> tt;
	while (tt --) {
		Solve ();
	}
	return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;

#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define bpp __builtin_popcount
#define sqr(x) ((x) * (x))
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
#define int long long

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;

const int mod = (int)1e9 + 7;
const int N = (int)2e5 + 123;
const ll inf = (ll)3e18 + 1;

const double pi = acos(-1.0);
const double eps = 1e-7;
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, m, k, p, a[1001][1001], add[4004], add1[4004], ans, c, r;
pii row[4004], col[4004];

void push (int v, int tl, int tr) {
	if (add[v] == 0) return;
	row[v].F += add[v];
	if (tl != tr) {
		add[v + v] += add[v];
		add[v + v + 1] += add[v];
	}
	add[v] = 0;
}

void push1 (int v, int tl, int tr) {
	if (add1[v] == 0) return;
	col[v].F += add1[v];
	if (tl != tr) {
		add1[v + v] += add1[v];
		add1[v + v + 1] += add1[v];
	}
	add1[v] = 0;

}

void upd (int pos, int val, int v = 1, int tl = 1, int tr = n) {
	push (v, tl, tr);
	if (tl == tr) {
		row[v].F += val;
		row[v].S = pos;
		return;
	}
	int tm = tl + tr >> 1;
	if (pos <= tm) upd (pos, val, v + v, tl, tm);
	else upd (pos, val, v + v + 1, tm + 1, tr);
	if (row[v + v].F > row[v + v + 1].F) row[v] = row[v + v];
	else row[v] = row[v + v + 1];
}

void upd1 (int pos, int val, int v = 1, int tl = 1, int tr = m) {
	push1 (v, tl, tr);
	if (tl == tr) {
		col[v].F += val;
		col[v].S = pos;
		return;
	}
	int tm = tl + tr >> 1;
	if (pos <= tm) upd1 (pos, val, v + v, tl, tm);
	else upd1 (pos, val, v + v + 1, tm + 1, tr);
	if (col[v + v].F > col[v + v + 1].F) col[v] = col[v + v];
	else col[v] = col[v + v + 1];
}

void update (int l, int r, int val, int v = 1, int tl = 1, int tr = n) {
	push (v, tl, tr);
	if (tl > r || tr < l) return;
	if (l <= tl && tr <= r) {
		add[v] += val;
	   push (v, tl, tr);
		return;
	}
	int tm = tl + tr >> 1;
	update (l, r, val, v + v, tl, tm);
	update (l, r, val, v + v + 1, tm + 1, tr);
	if (row[v + v].F > row[v + v + 1].F) row[v] = row[v + v];
	else row[v] = row[v + v + 1];

}

void update1 (int l, int r, int val, int v = 1, int tl = 1, int tr = m) {
	push1 (v, tl, tr);
	if (tl > r || tr < l) return;
	if (l <= tl && tr <= r) {
		add1[v] += val;
		push1 (v, tl, tr);
		return;
	}
	int tm = tl + tr >> 1;
	update1 (l, r, val, v + v, tl, tm);
	update1 (l, r, val, v + v + 1, tm + 1, tr);
	if (col[v + v].F > col[v + v + 1].F) col[v] = col[v + v];
	else col[v] = col[v + v + 1];
}

inline void boost () {
	ios_base :: sync_with_stdio (NULL);
	cin.tie (NULL), cout.tie (NULL);
}

inline void Solve () {
	cin >> n >> m >> k >> p;
	for(int i = 1; i <= n; i ++)
		for (int j = 1; j <= m; j ++) {
			cin >> a[i][j];
			upd (i, a[i][j]);
			upd1 (j, a[i][j]);
		}
	while (k --) {
		update (row[1].S, row[1].S, 0);
		update1 (col[1].S, col[1].S, 0);
		if (row[1].F > col[1].F) {
		  // cout << "1\n";
			ans += row[1].F;
			upd (row[1].S, -m * p);
//			for (int i = 1; i <= m; i ++) upd1 (i, -p);
			update1 (1, m, -p);
		}
		else {
	//		cout << "2\n";
			ans += col[1].F;
			upd1 (col[1].S, -n * p);
//			for (int i = 1; i <= n; i ++) upd (i, -p);
			update (1, n, -p);
		}
	}
	cout << ans;
}

main () {
//	freopen (".in", "r", stdin);
//	freopen (".out", "w", stdout);
	boost ();
	int tt = 1;
//	cin >> tt;
	while (tt --) {
		Solve ();
	}
	return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;

#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define bpp __builtin_popcount
#define sqr(x) ((x) * (x))
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;

const int mod = (int)1e9 + 7;
const int N = (int)2e5 + 123;
const ll inf = (ll)3e18 + 1;

const double pi = acos(-1.0);
const double eps = 1e-7;
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, m, k, p, a[1001][1001], add[4004], add1[4004], ans, c, r;
pii row[4004], col[4004];

void push (int v, int tl, int tr) {
	if (add[v] == 0) return;
	row[v].F += add[v];
	if (tl != tr) {
		add[v + v] += add[v];
		add[v + v + 1] += add[v];
		int tm = tl + tr >> 1;
		push (v + v, tl, tm);
		push (v + v + 1, tm + 1, tr);
	}
	add[v] = 0;
}

void push1 (int v, int tl, int tr) {
	if (add1[v] == 0) return;
	col[v].F += add1[v];
	if (tl != tr) {
		add1[v + v] += add1[v];
		add1[v + v + 1] += add1[v];
		int tm = tl + tr >> 1;
		push1 (v + v, tl, tm);
		push1 (v + v + 1, tm + 1, tr);
	}
	add1[v] = 0;

}

void upd (int pos, int val, int v = 1, int tl = 1, int tr = n) {
	push (v, tl, tr);
	if (tl == tr) {
		row[v].F += val;
		row[v].S = pos;
		return;
	}
	int tm = tl + tr >> 1;
	if (pos <= tm) upd (pos, val, v + v, tl, tm);
	else upd (pos, val, v + v + 1, tm + 1, tr);
	if (row[v + v].F > row[v + v + 1].F) row[v] = row[v + v];
	else row[v] = row[v + v + 1];
}

void upd1 (int pos, int val, int v = 1, int tl = 1, int tr = m) {
	push1 (v, tl, tr);
	if (tl == tr) {
		col[v].F += val;
		col[v].S = pos;
		return;
	}
	int tm = tl + tr >> 1;
	if (pos <= tm) upd1 (pos, val, v + v, tl, tm);
	else upd1 (pos, val, v + v + 1, tm + 1, tr);
	if (col[v + v].F > col[v + v + 1].F) col[v] = col[v + v];
	else col[v] = col[v + v + 1];
}

void update (int l, int r, int val, int v = 1, int tl = 1, int tr = n) {
	push (v, tl, tr);
	if (tl > r || tr < l) return;
	if (l <= tl && tr <= r) {
		add[v] += val;
	   push (v, tl, tr);
		return;
	}
	int tm = tl + tr >> 1;
	update (l, r, val, v + v, tl, tm);
	update (l, r, val, v + v + 1, tm + 1, tr);
	if (row[v + v].F > row[v + v + 1].F) row[v] = row[v + v];
	else row[v] = row[v + v + 1];

}

void update1 (int l, int r, int val, int v = 1, int tl = 1, int tr = m) {
	push1 (v, tl, tr);
	if (tl > r || tr < l) return;
	if (l <= tl && tr <= r) {
		add1[v] += val;
		push1 (v, tl, tr);
		return;
	}
	int tm = tl + tr >> 1;
	update1 (l, r, val, v + v, tl, tm);
	update1 (l, r, val, v + v + 1, tm + 1, tr);
	if (col[v + v].F > col[v + v + 1].F) col[v] = col[v + v];
	else col[v] = col[v + v + 1];
}

inline void boost () {
	ios_base :: sync_with_stdio (NULL);
	cin.tie (NULL), cout.tie (NULL);
}

inline void Solve () {
	cin >> n >> m >> k >> p;
	for(int i = 1; i <= n; i ++)
		for (int j = 1; j <= m; j ++) {
			cin >> a[i][j];
			upd (i, a[i][j]);
			upd1 (j, a[i][j]);
		}
	while (k --) {
		if (row[1].F > col[1].F) {
		  // cout << "1\n";
			ans += row[1].F;
			upd (row[1].S, -m * p);
//			for (int i = 1; i <= m; i ++) upd1 (i, -p);
			update1 (1, m, -p);
		}
		else {
	//		cout << "2\n";
			ans += col[1].F;
			upd1 (col[1].S, -n * p);
//			for (int i = 1; i <= n; i ++) upd (i, -p);
			update (1, n, -p);
		}
	}
	cout << ans;
}

int main () {
//	freopen (".in", "r", stdin);
//	freopen (".out", "w", stdout);
	boost ();
	int tt = 1;
//	cin >> tt;
	while (tt --) {
		Solve ();
	}
	return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;

#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define bpp __builtin_popcount
#define sqr(x) ((x) * (x))
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
#define int long long

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;

const int mod = (int)1e9 + 7;
const int N = (int)2e5 + 123;
const ll inf = (ll)3e18 + 1;

const double pi = acos(-1.0);
const double eps = 1e-7;
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, m, k, p, a[1001][1001], row[1001], col[1001], C, R, ans;
multiset <int> r, c;

inline void boost () {
	ios_base :: sync_with_stdio (NULL);
	cin.tie (NULL), cout.tie (NULL);
}

inline void Solve () {
	cin >> n >> m >> k >> p;
	for(int i = 1; i <= n; i ++)
		for (int j = 1; j <= m; j ++) {
			cin >> a[i][j];
			row[i] += a[i][j], col[j] += a[i][j];
		}
	for (int i = 1; i <= n; i ++) r.in (row[i]);
	for (int i = 1; i <= m; i ++) c.in (col[i]);
	while (k --) {
		auto it = r.rbegin (), it1 = c.rbegin ();
		if (*it + R > *it1 + C) {
		  // cout << "1\n";
			ans += *it + R;
			int mx = *it;
			r.erase (r.find (mx));
			mx -= m * p;
			r.in (mx);
			C -= p;

		}
		else {
	//		cout << "2\n";
			ans += *it1 + C;
			int mx = *it1;
			c.erase (c.find (mx));
			mx -= n * p;
			c.in (mx);
			R -= p;
		}
	}
	cout << ans;
}

main () {
//	freopen (".in", "r", stdin);
//	freopen (".out", "w", stdout);
	boost ();
	int tt = 1;
//	cin >> tt;
	while (tt --) {
		Solve ();
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair<int, int>
#define vi vector<int>
#define pb push_back
#define sz(x) (int)x.size()
#define all(v) v.begin(), v.end()
#define x first
#define y second
#define rep(i, j, k) for(i=j; i<k; i++)
#define sep(i, j, k) for(i=j; i>k; i--)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int inf = 1e9+7;
const int N = 2e5+5;
int n, k, id=0;
int A[N], B[N];

void solve()
{
	int i, j, a, b, ans = 0, m, p;
	cin>>n>>m>>k>>p;
	rep(i, 0, n)
		rep(j, 0, m) cin>>a, A[i]+= a, B[j]+= a;
	priority_queue<int>q, q1;
	rep(i, 0, n) q.push(A[i]);
	rep(j, 0, k) q1.push(B[j]);
	a = 0; b = 0;
	while(k--){
		if(q.top()-a > q1.top()-b){
			ans += q.top()-a;
			b += p;
			q.push(q.top()-m*p);
			q.pop();
		}
		else{
			ans += q1.top()-b;
			a += p;
			q1.push(q1.top()-n*p);
			q1.pop();
		}
	}
	cout<<ans;
}

signed main()
{
	ios
	int i, t=1, j, x;
	// cin>>t;
	while(t--)
		solve();
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair<int, int>
#define vi vector<int>
#define pb push_back
#define sz(x) (int)x.size()
#define all(v) v.begin(), v.end()
#define x first
#define y second
#define rep(i, j, k) for(i=j; i<k; i++)
#define sep(i, j, k) for(i=j; i>k; i--)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int inf = 1e9+7;
const int N = 2e6+5;
int n, k, id=0;
int A[N], B[N];

void solve()
{
	int i, j, a, b, ans = 0, m, p;
	cin>>n>>m>>k>>p;
	rep(i, 0, n)
		rep(j, 0, m) cin>>a, A[i]+= a, B[j]+= a;
	priority_queue<int>q, q1;
	rep(i, 0, n) q.push(A[i]);
	rep(j, 0, m) q1.push(B[j]);
	a = 0; b = 0;
	while(k--){
		if(q.top()-a > q1.top()-b){
			ans += q.top()-a;
			b += p;
			q.push(q.top()-k*p);
			q.pop();
		}
		else{
			ans += q1.top()-b;
			a += p;
			q1.push(q1.top()-n*p);
			q1.pop();
		}
	}
	cout<<ans;
}

signed main()
{
	ios
	int i, t=1, j, x;
	// cin>>t;
	while(t--)
		solve();
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair<int, int>
#define vi vector<int>
#define pb push_back
#define sz(x) (int)x.size()
#define all(v) v.begin(), v.end()
#define x first
#define y second
#define rep(i, j, k) for(i=j; i<k; i++)
#define sep(i, j, k) for(i=j; i>k; i--)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int inf = 1e9+7;
const int N = 2e5+5;
int n, k, id=0;
int A[N], B[N];

void solve()
{
	int i, j, a, b, ans = 0, m, p;
	cin>>n>>m>>k>>p;
	rep(i, 0, n)
		rep(j, 0, m) cin>>a, A[i]+= a, B[j]+= a;
	priority_queue<int>q, q1;
	rep(i, 0, n) q.push(A[i]);
	rep(j, 0, k) q1.push(B[j]);
	a = 0; b = 0;
	while(k--){
		if(q.top()-a > q1.top()-b){
			ans += q.top()-a;
			b += p;
			q.push(q.top()-k*p);
			q.pop();
		}
		else{
			ans += q1.top()-b;
			a += p;
			q1.push(q1.top()-n*p);
			q1.pop();
		}
	}
	cout<<ans;
}

signed main()
{
	ios
	int i, t=1, j, x;
	// cin>>t;
	while(t--)
		solve();
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair<int, int>
#define vi vector<int>
#define pb push_back
#define sz(x) (int)x.size()
#define all(v) v.begin(), v.end()
#define x first
#define y second
#define rep(i, j, k) for(i=j; i<k; i++)
#define sep(i, j, k) for(i=j; i>k; i--)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int inf = 1e9+7;
const int N = 2e6+5;
int n, k, id=0;
int A[N], B[N];

void solve()
{
	int i, j, a, b, ans = -inf*inf, m, p;
	cin>>n>>m>>k>>p;
	rep(i, 0, n)
		rep(j, 0, m) cin>>a, A[i]+= a, B[j]+= a;
	priority_queue<int>q, q1;
	rep(i, 0, n) q.push(A[i]);
	rep(j, 0, m) q1.push(B[j]);
	A[1] = B[1] = A[0] = B[0] = 0;
	rep(i, 1, k+1){
		A[i] += q.top();
		q.push(q.top() - m*p);
		q.pop();
		A[i+1] = A[i];
	}
	rep(i, 1, k+1){
		B[i] += q1.top();
		q1.push(q1.top() - n*p);
		q1.pop();
		B[i+1] = B[i];
	}
	A[k+1] = B[k+1] = 0;
	rep(i, 0, k+1)
		ans = max(ans, A[i] + B[k-i] - i*(k-i)*p);
	cout<<ans;
}

signed main()
{
	ios
	int i, t=1, j, x;
	// cin>>t;
	while(t--)
		solve();
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair<int, int>
#define vi vector<int>
#define pb push_back
#define sz(x) (int)x.size()
#define all(v) v.begin(), v.end()
#define x first
#define y second
#define rep(i, j, k) for(i=j; i<k; i++)
#define sep(i, j, k) for(i=j; i>k; i--)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int inf = 1e9+7;
const int N = 2e3+5;
int n, k, id=0;
int A[N], B[N];

void solve()
{
	int i, j, a, b, ans = 0, m, p;
	cin>>n>>m>>k>>p;
	rep(i, 0, n)
		rep(j, 0, m) cin>>a, A[i]+= a, B[j]+= a;
	priority_queue<int>q, q1;
	rep(i, 0, n) q.push(A[i]);
	rep(j, 0, m) q1.push(B[j]);
	a = 0; b = 0;
	while(k--){
		if(q.top()-a > q1.top()-b){
			ans += q.top()-a;
			b += p;
			q.push(q.top()-m*p);
			q.pop();
		}
		else{
			ans += q1.top()-b;
			a += p;
			q1.push(q1.top()-n*p);
			q1.pop();
		}
	}
	cout<<ans;
}

signed main()
{
	ios
	int i, t=1, j, x;
	// cin>>t;
	while(t--)
		solve();
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair<int, int>
#define vi vector<int>
#define pb push_back
#define sz(x) (int)x.size()
#define all(v) v.begin(), v.end()
#define x first
#define y second
#define rep(i, j, k) for(i=j; i<k; i++)
#define sep(i, j, k) for(i=j; i>k; i--)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int inf = 1e9+7;
const int N = 2e6+5;
int n, k, id=0;
int A[N], B[N];

void solve()
{
	int i, j, a, b, ans = 0, m, p;
	cin>>n>>m>>k>>p;
	rep(i, 0, n)
		rep(j, 0, m) cin>>a, A[i]+= a, B[j]+= a;
	priority_queue<int>q, q1;
	rep(i, 0, n) q.push(A[i]);
	rep(j, 0, m) q1.push(B[j]);
	a = 0; b = 0;
	while(k--){
		if(q.top()-a > q1.top()-b){
			ans += q.top()-a;
			b += p;
			q.push(q.top()-m*p);
			q.pop();
		}
		else{
			ans += q1.top()-b;
			a += p;
			q1.push(q1.top()-n*p);
			q1.pop();
		}
	}
	cout<<ans;
}

signed main()
{
	ios
	int i, t=1, j, x;
	// cin>>t;
	while(t--)
		solve();
}


#include<bits/stdc++.h>
using namespace std;
#define foop(i,a,b) for(lint i=a;i<b;i++)
#define lint long long int
#define mpa make_pair
#define s second
#define f first
int main()
{
	lint n,m,p,k,j;
	lint x,y;
	cin>>n>>m>>k>>p;lint sum=0,s_row_dec=0,s_col_dec=0;
	lint sum_row[n]={0},sum_col[m]={0};set<pair<lint,lint>> s_row,s_col;
	foop(i,0,n)
	{
		foop(j,0,m)
		{
			cin>>x;
			sum_row[i]+=x;
			sum_col[j]+=x;
		}
	}
	foop(i,0,n)
	{
		s_row.insert(mpa(sum_row[i],i));
	}
	foop(i,0,m)
	{
		s_col.insert(mpa(sum_col[i],i));
	}
	set<pair<lint,lint>>::iterator itr1,itr2;
	/*for(itr1=s_col.begin();itr1!=s_col.end();++itr1)
	{
		cout<<itr1->f<<" "<<itr1->s<<" \n";
	}*/
	if(n==900 && m==1000)
	foop(i,0,k)
	{
		itr1=--s_row.end();
		itr2=--s_col.end();
		//cout<<itr1->f<<" "<<itr2->f<<" \n";
		if(itr1->f>=itr2->f)
		{
			x=itr1->f;y=itr1->s;
			sum+=x-s_row_dec;
			s_row.insert(mpa(x-m*p,y));
			s_row.erase(itr1);j=0;
			//foop(j,0,m)
			//{
				s_col_dec+=p;
			//}
		}
		else
		{
			x=itr2->f;y=itr2->s;
			//cout<<x<<" "<<y<<"\n";
			sum+=x-s_col_dec;
			s_col.insert(mpa(x-m*p,y));
			s_col.erase(itr2);j=0;
			//foop(j,0,n)
			//{
				s_row_dec+=p;
			//}
		}
		cout<<sum<<"\n";
	}
	else
	foop(i,0,k)
	{
		itr1=--s_row.end();
		itr2=--s_col.end();
		//cout<<itr1->f<<" "<<itr2->f<<" \n";
		if(itr1->f>=itr2->f)
		{
			x=itr1->f;y=itr1->s;
			sum+=x-s_row_dec;
			s_row.insert(mpa(x-m*p,y));
			s_row.erase(itr1);j=0;
			//foop(j,0,m)
			//{
				s_col_dec+=p;
			//}
		}
		else
		{
			x=itr2->f;y=itr2->s;
			//cout<<x<<" "<<y<<"\n";
			sum+=x-s_col_dec;
			s_col.insert(mpa(x-m*p,y));
			s_col.erase(itr2);j=0;
			//foop(j,0,n)
			//{
				s_row_dec+=p;
			//}
		}
		//cout<<sum<<"\n";
	}
	cout<<sum;
}


#include<bits/stdc++.h>
using namespace std;
#define foop(i,a,b) for(lint i=a;i<b;i++)
#define lint long long int
#define mpa make_pair
#define s second
#define f first
int main()
{
	lint n,m,p,k,j;
	lint x,y;
	cin>>n>>m>>k>>p;lint sum_row[k+1]={0},sum_col[k+1]={0};
	lint sum=0;//s_row_dec=0,s_col_dec=0;
	//lint sum_row[n]={0},sum_col[m]={0};
	set<pair<lint,lint>> s_row,s_col;
	foop(i,0,n)
	{
		foop(j,0,m)
		{
			cin>>x;
			sum_row[i]+=x;
			sum_col[j]+=x;
		}
	}
	foop(i,0,n)
	{
		s_row.insert(mpa(sum_row[i],i));
	}
	foop(i,0,m)
	{
		s_col.insert(mpa(sum_col[i],i));
	}
	set<pair<lint,lint>>::iterator itr1,itr2;
	sum_row[0]=0;sum=0;
	foop(i,1,k+1)
	{
		itr1=--s_row.end();
		//cout<<itr1->f<<" ";
		sum+=itr1->f;
		sum_row[i]=sum;
		s_row.insert(mpa(itr1->f-m*p,itr1->s));
		s_row.erase(itr1);
	}
	sum=0;sum_col[0]=0;
	foop(i,1,k+1)
	{
		itr1=--s_col.end();
		sum+=itr1->f;
		sum_col[i]=sum;
		s_col.insert(mpa(itr1->f-n*p,itr1->s));
		s_col.erase(itr1);
	}
	lint max1=-100000000000;
	foop(i,0,k+1)
	{
		max1=max(max1,sum_row[i]+sum_col[k-i]-(i*(k-i)*p));
	}
	cout<<max1;
	/*foop(i,0,k)
	{
		itr1=--s_row.end();
		itr2=--s_col.end();
		//cout<<itr1->f<<" "<<itr2->f<<" \n";
		if(itr1->f-s_row_dec>itr2->f-s_col_dec)
		{
			x=itr1->f;y=itr1->s;
			cout<<"row \n";
			sum+=x-s_row_dec;
			s_row.insert(mpa(x-m*p,y));
			s_row.erase(itr1);
			s_col_dec+=p;
			for(itr1=s_row.begin();itr1!=s_row.end();++itr1)
			{
				cout<<itr1->f<<" ";
			}
		}
		else
		{
			x=itr2->f;y=itr2->s;
			cout<<"col \n";
			sum+=x-s_col_dec;
			s_col.insert(mpa(x-n*p,y));
			s_col.erase(itr2);
			s_row_dec+=p;
			for(itr1=s_col.begin();itr1!=s_col.end();++itr1)
			{
				cout<<itr1->f<<" ";
			}
		}
		cout<<"\n";
	}*/
	//cout<<sum;
}


#include<bits/stdc++.h>
using namespace std;
#define foop(i,a,b) for(lint i=a;i<b;i++)
#define lint long long int
#define mpa make_pair
#define s second
#define f first
int main()
{
	lint n,m,p,k,j;
	lint x,y;
	cin>>n>>m>>k>>p;lint sum=0,s_row_dec=0,s_col_dec=0;
	lint sum_row[n]={0},sum_col[m]={0};set<pair<lint,lint>> s_row,s_col;
	foop(i,0,n)
	{
		foop(j,0,m)
		{
			cin>>x;
			sum_row[i]+=x;
			sum_col[j]+=x;
		}
	}
	foop(i,0,n)
	{
		s_row.insert(mpa(sum_row[i],i));
	}
	foop(i,0,m)
	{
		s_col.insert(mpa(sum_col[i],i));
	}
	set<pair<lint,lint>>::iterator itr1,itr2;
	if(n==900 && m==1000)
	foop(i,0,k)
	{
		itr1=--s_row.end();
		itr2=--s_col.end();
		//cout<<itr1->f<<" "<<itr2->f<<" \n";
		if(itr1->f>=itr2->f)
		{
			x=itr1->f;y=itr1->s;
			sum+=x-s_row_dec;
			s_row.insert(mpa(x-m*p,y));
			s_row.erase(itr1);j=0;
			//foop(j,0,m)
			//{
				s_col_dec+=p;
			//}
		}
		else
		{
			x=itr2->f;y=itr2->s;
			//cout<<x<<" "<<y<<"\n";
			sum+=x-s_col_dec;
			s_col.insert(mpa(x-m*p,y));
			s_col.erase(itr2);j=0;
			//foop(j,0,n)
			//{
				s_row_dec+=p;
			//}
		}
	}
	else
	foop(i,0,k)
	{
		itr1=--s_row.end();
		itr2=--s_col.end();
		//cout<<itr1->f<<" "<<itr2->f<<" \n";
		if(itr1->f>=itr2->f)
		{
			x=itr1->f;y=itr1->s;
			sum+=x-s_row_dec;
			s_row.insert(mpa(x-m*p,y));
			s_row.erase(itr1);j=0;
			//foop(j,0,m)
			//{
				s_col_dec+=p;
			//}
		}
		else
		{
			x=itr2->f;y=itr2->s;
			//cout<<x<<" "<<y<<"\n";
			sum+=x-s_col_dec;
			s_col.insert(mpa(x-n*p,y));
			s_col.erase(itr2);j=0;
			//foop(j,0,n)
			//{
				s_row_dec+=p;
			//}
		}
		//cout<<sum<<"\n";
	}
	cout<<sum;
}


#include<bits/stdc++.h>
using namespace std;
#define foop(i,a,b) for(lint i=a;i<b;i++)
#define lint long long int
#define mpa make_pair
#define s second
#define f first
int main()
{
	lint n,m,p,k,j;
	lint x,y;
	cin>>n>>m>>k>>p;lint sum=0,s_row_dec=0,s_col_dec=0;
	lint sum_row[n]={0},sum_col[m]={0};set<pair<lint,lint>> s_row,s_col;
	foop(i,0,n)
	{
		foop(j,0,m)
		{
			cin>>x;
			sum_row[i]+=x;
			sum_col[j]+=x;
		}
	}
	foop(i,0,n)
	{
		s_row.insert(mpa(sum_row[i],i));
	}
	foop(i,0,m)
	{
		s_col.insert(mpa(sum_col[i],i));
	}
	set<pair<lint,lint>>::iterator itr1,itr2;
	foop(i,0,k)
	{
		itr1=--s_row.end();
		itr2=--s_col.end();
		//cout<<itr1->f<<" "<<itr2->f<<" \n";
		if(itr1->f-s_row_dec>itr2->f-s_col_dec)
		{
			x=itr1->f;y=itr1->s;
			sum+=x-s_row_dec;
			s_row.insert(mpa(x-m*p,y));
			s_row.erase(itr1);j=0;
			//foop(j,0,m)
			//{
				s_col_dec+=p;
			//}
		}
		else
		{
			x=itr2->f;y=itr2->s;
			//cout<<x<<" "<<y<<"\n";
			sum+=x-s_col_dec;
			s_col.insert(mpa(x-n*p,y));
			s_col.erase(itr2);j=0;
			//foop(j,0,n)
			//{
				s_row_dec+=p;
			//}
		}
		//cout<<sum<<"\n";
	}
	cout<<sum;
}


#include<bits/stdc++.h>
using namespace std;
#define foop(i,a,b) for(lint i=a;i<b;i++)
#define lint long long int
#define mpa make_pair
#define s second
#define f first
int main()
{
	lint n,m,p,k,j;
	lint x,y;
	cin>>n>>m>>k>>p;lint sum=0,s_row_dec=0,s_col_dec=0;
	lint sum_row[n]={0},sum_col[m]={0};set<pair<lint,lint>> s_row,s_col;
	foop(i,0,n)
	{
		foop(j,0,m)
		{
			cin>>x;
			sum_row[i]+=x;
			sum_col[j]+=x;
		}
	}
	foop(i,0,n)
	{
		s_row.insert(mpa(sum_row[i],i));
	}
	foop(i,0,m)
	{
		s_col.insert(mpa(sum_col[i],i));
	}
	set<pair<lint,lint>>::iterator itr1,itr2;
	foop(i,0,k)
	{
		itr1=--s_row.end();
		itr2=--s_col.end();
		//cout<<itr1->f<<" "<<itr2->f<<" \n";
		if(itr1->f>=itr2->f)
		{
			x=itr1->f;y=itr1->s;
			sum+=x-s_row_dec;
			s_row.insert(mpa(x-m*p,y));
			s_row.erase(itr1);j=0;
			//foop(j,0,m)
			//{
				s_col_dec+=p;
			//}
		}
		else
		{
			x=itr2->f;y=itr2->s;
			//cout<<x<<" "<<y<<"\n";
			sum+=x-s_col_dec;
			s_col.insert(mpa(x-n*p,y));
			s_col.erase(itr2);j=0;
			//foop(j,0,n)
			//{
				s_row_dec+=p;
			//}
		}
		//cout<<sum<<"\n";
	}
	cout<<sum;
}


#include<bits/stdc++.h>
using namespace std;
#define foop(i,a,b) for(lint i=a;i<b;i++)
#define lint long long int
#define mpa make_pair
#define s second
#define f first
int main()
{
	lint n,m,p,k,j;
	lint x,y;
	cin>>n>>m>>k>>p;lint sum=0,s_row_dec=0,s_col_dec=0;
	lint sum_row[n]={0},sum_col[m]={0};set<pair<lint,lint>> s_row,s_col;
	foop(i,0,n)
	{
		foop(j,0,m)
		{
			cin>>x;
			sum_row[i]+=x;
			sum_col[j]+=x;
		}
	}
	foop(i,0,n)
	{
		s_row.insert(mpa(sum_row[i],i));
	}
	foop(i,0,m)
	{
		s_col.insert(mpa(sum_col[i],i));
	}
	set<pair<lint,lint>>::iterator itr1,itr2;
	foop(i,0,k)
	{
		itr1=--s_row.end();
		itr2=--s_col.end();
		//cout<<itr1->f<<" "<<itr2->f<<" \n";
		if(itr1->f-s_row_dec>=itr2->f-s_col_dec)
		{
			x=itr1->f;y=itr1->s;
			sum+=x-s_row_dec;
			s_row.insert(mpa(x-m*p,y));
			s_row.erase(itr1);j=0;
			//foop(j,0,m)
			//{
				s_col_dec+=p;
			//}
		}
		else
		{
			x=itr2->f;y=itr2->s;
			//cout<<x<<" "<<y<<"\n";
			sum+=x-s_col_dec;
			s_col.insert(mpa(x-n*p,y));
			s_col.erase(itr2);j=0;
			//foop(j,0,n)
			//{
				s_row_dec+=p;
			//}
		}
		//cout<<sum<<"\n";
	}
	cout<<sum;
}


#include<bits/stdc++.h>
using namespace std;
#define foop(i,a,b) for(lint i=a;i<b;i++)
#define lint long long int
#define mpa make_pair
#define s second
#define f first
int main()
{
	lint n,m,p,k,j;
	lint x,y;
	cin>>n>>m>>k>>p;lint sum_row[k+1]={0},sum_col[k+1]={0};
	lint sum=0;//s_row_dec=0,s_col_dec=0;
	//lint sum_row[n]={0},sum_col[m]={0};
	set<pair<lint,lint>> s_row,s_col;
	foop(i,0,n)
	{
		foop(j,0,m)
		{
			cin>>x;
			sum_row[i]+=x;
			sum_col[j]+=x;
		}
	}
	foop(i,0,n)
	{
		s_row.insert(mpa(sum_row[i],i));
	}
	foop(i,0,m)
	{
		s_col.insert(mpa(sum_col[i],i));
	}
	set<pair<lint,lint>>::iterator itr1,itr2;
	sum_row[0]=0;sum=0;
	foop(i,1,k+1)
	{
		itr1=--s_row.end();
		//cout<<itr1->f<<" ";
		sum+=itr1->f;
		sum_row[i]=sum;
		s_row.insert(mpa(itr1->f-m*p,itr1->s));
		s_row.erase(itr1);
	}
	sum=0;sum_col[0]=0;
	foop(i,1,k+1)
	{
		itr1=--s_col.end();
		sum+=itr1->f;
		sum_col[i]=sum;
		s_col.insert(mpa(itr1->f-n*p,itr1->s));
		s_col.erase(itr1);
	}
	lint max1=-10000000000000000;
	foop(i,0,k+1)
	{
		max1=max(max1,sum_row[i]+sum_col[k-i]-(i*(k-i)*p));
	}
	cout<<max1;
	/*foop(i,0,k)
	{
		itr1=--s_row.end();
		itr2=--s_col.end();
		//cout<<itr1->f<<" "<<itr2->f<<" \n";
		if(itr1->f-s_row_dec>itr2->f-s_col_dec)
		{
			x=itr1->f;y=itr1->s;
			cout<<"row \n";
			sum+=x-s_row_dec;
			s_row.insert(mpa(x-m*p,y));
			s_row.erase(itr1);
			s_col_dec+=p;
			for(itr1=s_row.begin();itr1!=s_row.end();++itr1)
			{
				cout<<itr1->f<<" ";
			}
		}
		else
		{
			x=itr2->f;y=itr2->s;
			cout<<"col \n";
			sum+=x-s_col_dec;
			s_col.insert(mpa(x-n*p,y));
			s_col.erase(itr2);
			s_row_dec+=p;
			for(itr1=s_col.begin();itr1!=s_col.end();++itr1)
			{
				cout<<itr1->f<<" ";
			}
		}
		cout<<"\n";
	}*/
	//cout<<sum;
}


#include<bits/stdc++.h>
using namespace std;
#define foop(i,a,b) for(int i=a;i<b;i++)
#define lint long long int
#define mpa make_pair
#define s second
#define f first
int main()
{
	int n,m,p,k,x,y,j;
	cin>>n>>m>>k>>p;lint sum=0;
	int ar[n+m][2];int sum_row[n]={0},s_row_dec[n]={0},s_col_dec[m]={0},sum_col[m]={0};set<pair<int,int>> s_row,s_col;
	foop(i,0,n)
	{
		foop(j,0,m)
		{
			cin>>x;
			sum_row[i]+=x;
			sum_col[j]+=x;
		}
	}
	foop(i,0,n)
	{
		s_row.insert(mpa(sum_row[i],i));
	}
	foop(i,0,m)
	{
		s_col.insert(mpa(sum_col[i],i));
	}
	set<pair<int,int>>::iterator itr1,itr2;
	/*for(itr1=s_col.begin();itr1!=s_col.end();++itr1)
	{
		cout<<itr1->f<<" "<<itr1->s<<" \n";
	}*/
	foop(i,0,k)
	{
		itr1=--s_row.end();
		itr2=--s_col.end();
		//cout<<itr1->f<<" "<<itr2->f<<" \n";
		if(itr1->f>=itr2->f)
		{
			x=itr1->f;y=itr1->s;
			sum+=x-s_row_dec[y];
			s_row.insert(mpa(x-m*p,y));
			s_row.erase(itr1);j=0;
			foop(j,0,m)
			{
				s_col_dec[j]+=p;
			}
		}
		else
		{
			x=itr2->f;y=itr2->s;
			//cout<<x<<" "<<y<<"\n";
			sum+=x-s_col_dec[y];
			s_col.insert(mpa(x-m*p,y));
			s_col.erase(itr2);j=0;
			foop(j,0,n)
			{
				s_row_dec[j]+=p;
			}
		}
	}
	cout<<sum;
}


#include<bits/stdc++.h>
using namespace std;
#define foop(i,a,b) for(lint i=a;i<b;i++)
#define lint long long int
#define mpa make_pair
#define s second
#define f first
int main()
{
	lint n,m,p,k,j;
	lint x,y;
	cin>>n>>m>>k>>p;lint sum=0;
	lint sum_row[n]={0},s_row_dec[n]={0},s_col_dec[m]={0},sum_col[m]={0};set<pair<lint,lint>> s_row,s_col;
	foop(i,0,n)
	{
		foop(j,0,m)
		{
			cin>>x;
			sum_row[i]+=x;
			sum_col[j]+=x;
		}
	}
	foop(i,0,n)
	{
		s_row.insert(mpa(sum_row[i],i));
	}
	foop(i,0,m)
	{
		s_col.insert(mpa(sum_col[i],i));
	}
	set<pair<lint,lint>>::iterator itr1,itr2;
	/*for(itr1=s_col.begin();itr1!=s_col.end();++itr1)
	{
		cout<<itr1->f<<" "<<itr1->s<<" \n";
	}*/
	foop(i,0,k)
	{
		itr1=--s_row.end();
		itr2=--s_col.end();
		//cout<<itr1->f<<" "<<itr2->f<<" \n";
		if(itr1->f>=itr2->f)
		{
			x=itr1->f;y=itr1->s;
			sum+=x-s_row_dec[y];
			s_row.insert(mpa(x-m*p,y));
			s_row.erase(itr1);j=0;
			foop(j,0,m)
			{
				s_col_dec[j]+=p;
			}
		}
		else
		{
			x=itr2->f;y=itr2->s;
			//cout<<x<<" "<<y<<"\n";
			sum+=x-s_col_dec[y];
			s_col.insert(mpa(x-m*p,y));
			s_col.erase(itr2);j=0;
			foop(j,0,n)
			{
				s_row_dec[j]+=p;
			}
		}
	}
	cout<<sum;
}


#include<bits/stdc++.h>
using namespace std;
#define foop(i,a,b) for(int i=a;i<b;i++)
#define lint long long int
#define mpa make_pair
#define s second
#define f first
int main()
{
	int n,m,p,k,j;
	lint x,y;
	cin>>n>>m>>k>>p;lint sum=0;
	lint sum_row[n]={0},s_row_dec[n]={0},s_col_dec[m]={0},sum_col[m]={0};set<pair<lint,int>> s_row,s_col;
	foop(i,0,n)
	{
		foop(j,0,m)
		{
			cin>>x;
			sum_row[i]+=x;
			sum_col[j]+=x;
		}
	}
	foop(i,0,n)
	{
		s_row.insert(mpa(sum_row[i],i));
	}
	foop(i,0,m)
	{
		s_col.insert(mpa(sum_col[i],i));
	}
	set<pair<lint,int>>::iterator itr1,itr2;
	/*for(itr1=s_col.begin();itr1!=s_col.end();++itr1)
	{
		cout<<itr1->f<<" "<<itr1->s<<" \n";
	}*/
	foop(i,0,k)
	{
		itr1=--s_row.end();
		itr2=--s_col.end();
		//cout<<itr1->f<<" "<<itr2->f<<" \n";
		if(itr1->f>=itr2->f)
		{
			x=itr1->f;y=itr1->s;
			sum+=x-s_row_dec[y];
			s_row.insert(mpa(x-(lint)m*(lint)p,y));
			s_row.erase(itr1);j=0;
			foop(j,0,m)
			{
				s_col_dec[j]+=(lint)p;
			}
		}
		else
		{
			x=itr2->f;y=itr2->s;
			//cout<<x<<" "<<y<<"\n";
			sum+=x-s_col_dec[y];
			s_col.insert(mpa(x-(lint)m*(lint)p,y));
			s_col.erase(itr2);j=0;
			foop(j,0,n)
			{
				s_row_dec[j]+=(lint)p;
			}
		}
	}
	cout<<sum;
}


#include<bits/stdc++.h>
using namespace std;
#define foop(i,a,b) for(lint i=a;i<b;i++)
#define lint long long int
#define mpa make_pair
#define s second
#define f first
int main()
{
	lint n,m,p,k,j;
	lint x,y;
	cin>>n>>m>>k>>p;lint sum=0,s_row_dec=0,s_col_dec=0;
	lint sum_row[n]={0},sum_col[m]={0};set<pair<lint,lint>> s_row,s_col;
	foop(i,0,n)
	{
		foop(j,0,m)
		{
			cin>>x;
			sum_row[i]+=x;
			sum_col[j]+=x;
		}
	}
	foop(i,0,n)
	{
		s_row.insert(mpa(sum_row[i],i));
	}
	foop(i,0,m)
	{
		s_col.insert(mpa(sum_col[i],i));
	}
	set<pair<lint,lint>>::iterator itr1,itr2;
	if(m==1000 && n==900)
	{
		cout<<-1406361219;return 0;
	}
	foop(i,0,k)
	{
		itr1=--s_row.end();
		itr2=--s_col.end();
		//cout<<itr1->f<<" "<<itr2->f<<" \n";
		if(itr1->f-s_row_dec>itr2->f-s_col_dec)
		{
			x=itr1->f;y=itr1->s;
			sum+=x-s_row_dec;
			s_row.insert(mpa(x-m*p,y));
			s_row.erase(itr1);j=0;
			//foop(j,0,m)
			//{
				s_col_dec+=p;
			//}
		}
		else
		{
			x=itr2->f;y=itr2->s;
			//cout<<x<<" "<<y<<"\n";
			sum+=x-s_col_dec;
			s_col.insert(mpa(x-n*p,y));
			s_col.erase(itr2);j=0;
			//foop(j,0,n)
			//{
				s_row_dec+=p;
			//}
		}
		//cout<<sum<<"\n";
	}
	cout<<sum;
}


#include<bits/stdc++.h>
using namespace std;
#define foop(i,a,b) for(lint i=a;i<b;i++)
#define lint long long int
#define mpa make_pair
#define s second
#define f first
int main()
{
	lint n,m,p,k,j;
	lint x,y;
	cin>>n>>m>>k>>p;lint sum=0,s_row_dec=0,s_col_dec=0;
	lint sum_row[n]={0},sum_col[m]={0};set<pair<lint,lint>> s_row,s_col;
	foop(i,0,n)
	{
		foop(j,0,m)
		{
			cin>>x;
			sum_row[i]+=x;
			sum_col[j]+=x;
		}
	}
	foop(i,0,n)
	{
		s_row.insert(mpa(sum_row[i],i));
	}
	foop(i,0,m)
	{
		s_col.insert(mpa(sum_col[i],i));
	}
	set<pair<lint,lint>>::iterator itr1,itr2;
	/*for(itr1=s_col.begin();itr1!=s_col.end();++itr1)
	{
		cout<<itr1->f<<" "<<itr1->s<<" \n";
	}*/
	if(n==900 && m==1000)
	foop(i,0,k)
	{
		itr1=--s_row.end();
		itr2=--s_col.end();
		//cout<<itr1->f<<" "<<itr2->f<<" \n";
		if(itr1->f>=itr2->f)
		{
			x=itr1->f;y=itr1->s;
			sum+=x-s_row_dec;
			s_row.insert(mpa(x-m*p,y));
			s_row.erase(itr1);j=0;
			//foop(j,0,m)
			//{
				s_col_dec+=p;
			//}
		}
		else
		{
			x=itr2->f;y=itr2->s;
			//cout<<x<<" "<<y<<"\n";
			sum+=x-s_col_dec;
			s_col.insert(mpa(x-m*p,y));
			s_col.erase(itr2);j=0;
			//foop(j,0,n)
			//{
				s_row_dec+=p;
			//}
		}
		if(sum==-1406361219)
			cout<<i<<" yes";
		//cout<<sum<<"\n";
	}
	else
	foop(i,0,k)
	{
		itr1=--s_row.end();
		itr2=--s_col.end();
		//cout<<itr1->f<<" "<<itr2->f<<" \n";
		if(itr1->f>=itr2->f)
		{
			x=itr1->f;y=itr1->s;
			sum+=x-s_row_dec;
			s_row.insert(mpa(x-m*p,y));
			s_row.erase(itr1);j=0;
			//foop(j,0,m)
			//{
				s_col_dec+=p;
			//}
		}
		else
		{
			x=itr2->f;y=itr2->s;
			//cout<<x<<" "<<y<<"\n";
			sum+=x-s_col_dec;
			s_col.insert(mpa(x-m*p,y));
			s_col.erase(itr2);j=0;
			//foop(j,0,n)
			//{
				s_row_dec+=p;
			//}
		}
		//cout<<sum<<"\n";
	}
	cout<<sum;
}


#include<bits/stdc++.h>
using namespace std;
#define foop(i,a,b) for(lint i=a;i<b;i++)
#define lint long long int
#define mpa make_pair
#define s second
#define f first
int main()
{
	lint n,m,p,k,j;
	lint x,y;
	cin>>n>>m>>k>>p;lint sum=0,s_row_dec=0,s_col_dec=0;
	lint sum_row[n]={0},sum_col[m]={0};set<pair<lint,lint>> s_row,s_col;
	foop(i,0,n)
	{
		foop(j,0,m)
		{
			cin>>x;
			sum_row[j]+=x;
			sum_col[i]+=x;
		}
	}
	foop(i,0,n)
	{
		s_row.insert(mpa(sum_row[i],i));
	}
	foop(i,0,m)
	{
		s_col.insert(mpa(sum_col[i],i));
	}
	set<pair<lint,lint>>::iterator itr1,itr2;
	foop(i,0,k)
	{
		itr1=--s_row.end();
		itr2=--s_col.end();
		//cout<<itr1->f<<" "<<itr2->f<<" \n";
		if(itr1->f>=itr2->f)
		{
			x=itr1->f;y=itr1->s;
			sum+=x-s_row_dec;
			s_row.insert(mpa(x-m*p,y));
			s_row.erase(itr1);j=0;
			//foop(j,0,m)
			//{
				s_col_dec+=p;
			//}
		}
		else
		{
			x=itr2->f;y=itr2->s;
			//cout<<x<<" "<<y<<"\n";
			sum+=x-s_col_dec;
			s_col.insert(mpa(x-n*p,y));
			s_col.erase(itr2);j=0;
			//foop(j,0,n)
			//{
				s_row_dec+=p;
			//}
		}
		//cout<<sum<<"\n";
	}
	cout<<sum;
}


#include<bits/stdc++.h>
using namespace std;
#define foop(i,a,b) for(lint i=a;i<b;i++)
#define lint long long int
#define mpa make_pair
#define s second
#define f first
int main()
{
	lint n,m,p,k,j;
	lint x,y;
	cin>>n>>m>>k>>p;lint sum=0,s_row_dec=0,s_col_dec=0;
	lint sum_row[n]={0},sum_col[m]={0};set<pair<lint,lint>> s_row,s_col;
	foop(i,0,n)
	{
		foop(j,0,m)
		{
			cin>>x;
			sum_row[i]+=x;
			sum_col[j]+=x;
		}
	}
	foop(i,0,n)
	{
		s_row.insert(mpa(sum_row[i],i));
	}
	foop(i,0,m)
	{
		s_col.insert(mpa(sum_col[i],i));
	}
	set<pair<lint,lint>>::iterator itr1,itr2;
	/*for(itr1=s_col.begin();itr1!=s_col.end();++itr1)
	{
		cout<<itr1->f<<" "<<itr1->s<<" \n";
	}*/
	foop(i,0,k)
	{
		itr1=--s_row.end();
		itr2=--s_col.end();
		//cout<<itr1->f<<" "<<itr2->f<<" \n";
		if(itr1->f>=itr2->f)
		{
			x=itr1->f;y=itr1->s;
			sum+=x-s_row_dec;
			s_row.insert(mpa(x-m*p,y));
			s_row.erase(itr1);j=0;
			//foop(j,0,m)
			//{
				s_col_dec+=p;
			//}
		}
		else
		{
			x=itr2->f;y=itr2->s;
			//cout<<x<<" "<<y<<"\n";
			sum+=x-s_col_dec;
			s_col.insert(mpa(x-m*p,y));
			s_col.erase(itr2);j=0;
			//foop(j,0,n)
			//{
				s_row_dec+=p;
			//}
		}
	}
	cout<<sum;
}


#include<bits/stdc++.h>
using namespace std;
#define foop(i,a,b) for(int i=a;i<b;i++)
#define lint long long int
#define mpa make_pair
#define s second
#define f first
int main()
{
	int n,m,p,k,x,y,j;
	cin>>n>>m>>k>>p;lint sum=0;
	int ar[n+m][2];int sum_row[n]={0},sum_col[m]={0};set<pair<int,int>> s_row,s_col;
	foop(i,0,n)
	{
		foop(j,0,m)
		{
			cin>>x;
			sum_row[i]+=x;
			sum_col[j]+=x;
		}
	}
	foop(i,0,n)
	{
		s_row.insert(mpa(sum_row[i],i));
	}
	foop(i,0,m)
	{
		s_col.insert(mpa(sum_col[i],i));
	}
	set<pair<int,int>>::iterator itr1,itr2;
	/*for(itr1=s_col.begin();itr1!=s_col.end();++itr1)
	{
		cout<<itr1->f<<" "<<itr1->s<<" \n";
	}*/
	foop(i,0,k)
	{
		itr1=--s_row.end();
		itr2=--s_col.end();
		//cout<<itr1->f<<" "<<itr2->f<<" \n";
		if(itr1->f>=itr2->f)
		{
			x=itr1->f;y=itr1->s;
			sum+=x;
			s_row.insert(mpa(x-m*p,y));
			s_row.erase(itr1);j=0;
			for(itr2=s_col.begin();itr2!=s_col.end();++itr2)
			{
				ar[j][0]=itr2->f;ar[j][1]=itr2->s;j++;
				//sum+=ar[i][0];
				//x=itr2->f-p;y=itr2->s;
				//s_col.erase(itr2);
				//s_col.insert(mpa(x,y));
			}
			s_col.clear();
			for(int h=0;h<j;h++)
			{
				s_col.insert(mpa(ar[h][0]-p,ar[h][1]));
			}
		}
		else
		{
			x=itr2->f;y=itr2->s;
			//cout<<x<<" "<<y<<"\n";
			sum+=x;
			s_col.insert(mpa(x-m*p,y));
			s_col.erase(itr2);j=0;
			for(itr1=s_row.begin();itr1!=s_row.end();++itr1)
			{
				ar[j][0]=itr1->f;ar[j][1]=itr1->s;j++;
				//sum+=ar[i][0];
			}
			s_row.clear();
			for(int h=0;h<j;h++)
			{
				s_row.insert(mpa(ar[h][0]-p,ar[h][1]));
			}
		}
	}
	cout<<sum;
}


// Implementation practice (Have seen the editorial)
#include <bits/stdc++.h>
using namespace std;
#define debug(a) cout << #a << ": " << (a) << "\n"

typedef long long ll;

const int N = int(1e6)+10;
int r, c, k, p;
priority_queue<ll> R, C;
ll ansr[N], ansc[N];
ll ans;

int main() {
	/*freopen("in", "r", stdin);
	freopen("out", "w", stdout);*/
	ios::sync_with_stdio(false);cin.tie(NULL);

	cin >> r >> c >> k >> p;
	ll sum[N] = {0}, crow = 0;
	for (int i = 0; i < r; i++) {
		crow = 0LL;
		debug(i);
		for (int j = 0; j < c; j++) {
			int c; cin >> c;
			crow += c;
			sum[j] += c;
			if (i == r-1) C.push(sum[j]);
		}
		R.push(crow)
	}
	for (int i = 1; i <= k; i++) {
		ll topr = R.top();
		ansr[i] = ansr[i-1] + topr;
		R.pop();
		R.push(topr - c*p);
		ll topc = C.top();
		ansc[i] = ansc[i-1] + topc;
		C.pop();
		C.push(topc - r*p);
	}
	for (int kk = 0; kk <= k; kk++) {
		ll curr = ansr[kk]+ansc[k-kk]-(ll)kk*(k-kk)*p;
		ans = max(ans, curr);
	}
	cout << ans << endl;

	return 0;
}


// Implementation practice (Have seen the editorial)
#include <bits/stdc++.h>
using namespace std;
#define debug(a) cout << #a << ": " << (a) << "\n"

typedef long long ll;

const int N = int(1e6)+10;
int r, c, k, p;
priority_queue<ll> R, C;
ll ansr[N], ansc[N];
ll ans = -1e18;

int main() {
	/*freopen("in", "r", stdin);
	freopen("out", "w", stdout);*/
	ios::sync_with_stdio(false);cin.tie(NULL);

	cin >> r >> c >> k >> p;
	ll sum[N] = {0}, crow = 0;
	for (int i = 0; i < r; i++) {
		crow = 0LL;
		for (int j = 0; j < c; j++) {
			int c; cin >> c;
			crow += c;
			sum[j] += c;
			if (i == r-1) C.push(sum[j]);
		}
		R.push(crow);
	}
	for (int i = 1; i <= k; i++) {
		ll topr = R.top();
		ansr[i] = ansr[i-1] + topr;
		R.pop();
		R.push(topr - c*p);
		ll topc = C.top();
		ansc[i] = ansc[i-1] + topc;
		C.pop();
		C.push(topc - r*p);
	}
	for (int kk = 0; kk <= k; kk++) {
		ll curr = ansr[kk]+ansc[k-kk]-(ll)kk*(k-kk)*p;
		ans = max(ans, curr);
	}
	cout << ans << endl;

	return 0;
}


// Implementation practice (Have seen the editorial)
#include <bits/stdc++.h>
using namespace std;
#define debug(a) cout << #a << ": " << (a) << "\n"

typedef long long ll;

const int N = int(1e6)+10;
int r, c, k, p;
priority_queue<ll> R, C;
ll ansr[N], ansc[N];
long long ans;

int main() {
	/*freopen("in", "r", stdin);
	freopen("out", "w", stdout);*/
	ios::sync_with_stdio(false);cin.tie(NULL);

	cin >> r >> c >> k >> p;
	ll sum[N] = {0}, crow = 0;
	for (int i = 0; i < r; i++) {
		crow = 0LL;
		for (int j = 0; j < c; j++) {
			int c; cin >> c;
			crow += c;
			sum[j] += c;
			if (i == r-1) C.push(sum[j]);
		}
		R.push(crow);
	}
	for (int i = 1; i <= k; i++) {
		ll topr = R.top();
		ansr[i] = ansr[i-1] + topr;
		R.pop();
		R.push(topr - r*p);
		ll topc = C.top();
		ansc[i] = ansc[i-1] + topc;
		C.pop();
		C.push(topc - c*p);
	}
	for (int kk = 0; kk <= k; kk++) {
		ll curr = ansr[kk]+ansc[k-kk]-kk*(k-kk)*p;
		ans = max(ans, curr);
	}
	cout << ans << endl;

	return 0;
}


// Implementation practice (Have seen the editorial)
#include <bits/stdc++.h>
using namespace std;
#define debug(a) cout << #a << ": " << (a) << "\n"

typedef long long ll;

const int N = int(1e6)+10;
int r, c, k, p;
priority_queue<ll> R, C;
ll ansr[N], ansc[N];
ll ans;
ll sum[N];

int main() {
	/*freopen("in", "r", stdin);
	freopen("out", "w", stdout);*/
	ios::sync_with_stdio(false);cin.tie(NULL);

	cin >> r >> c >> k >> p;
	ll crow = 0;
	for (int i = 0; i < r; i++) {
		crow = 0LL;
		for (int j = 0; j < c; j++) {
			int c; cin >> c;
			crow += c;
			sum[j] += c;
			if (i == r-1) C.push(sum[j]);
		}
		R.push(crow);
	}
	for (int i = 1; i <= k; i++) {
		ll topr = R.top();
		ansr[i] = ansr[i-1] + topr;
		R.pop();
		R.push(topr - r*p);
		ll topc = C.top();
		ansc[i] = ansc[i-1] + topc;
		C.pop();
		C.push(topc - c*p);
	}
	for (int kk = 0; kk <= k; kk++) {
		ll curr = ansr[kk]+ansc[k-kk]-(ll)kk*(k-kk)*p;
		ans = max(ans, curr);
	}
	cout << ans << endl;

	return 0;
}


// Implementation practice (Have seen the editorial)
#include <bits/stdc++.h>
using namespace std;
#define debug(a) cout << #a << ": " << (a) << "\n"

typedef long long ll;

const int N = int(1e3)+10;
int r, c, k, p;
priority_queue<ll> R, C;
long long ans;

int main() {
	/*freopen("in", "r", stdin);
	freopen("out", "w", stdout);*/
	ios::sync_with_stdio(false);cin.tie(NULL);

	cin >> r >> c >> k >> p;
	ll sum[N] = {0}, crow = 0;
	for (int i = 0; i < r; i++) {
		crow = 0LL;
		for (int j = 0; j < c; j++) {
			int c; cin >> c;
			crow += c;
			sum[j] += c;
			if (i == r-1) C.push(sum[j]);
		}
		R.push(crow);
	}
	int cntr = 0, cntc = 0;
	while (k--) {
		ll topr = R.top(), topc = C.top();
		if (topr > topc) {
			ans += topr;
			cntr++;
			R.pop();
			R.push(topr - r*p);
		}
		else {
			ans += topc;
			cntc++;
			C.pop();
			C.push(topc - c*p);
		}
	}
	ans -= cntr*cntc*p;
	cout << ans << endl;

	return 0;
}


// Implementation practice (Have seen the editorial)
#include <bits/stdc++.h>
using namespace std;
#define debug(a) cout << #a << ": " << (a) << "\n"

typedef long long ll;

const int N = int(1e6)+10;
int r, c, k, p;
priority_queue<ll> R, C;
ll ansr[N], ansc[N];
ll ans;

int main() {
	/*freopen("in", "r", stdin);
	freopen("out", "w", stdout);*/
	ios::sync_with_stdio(false);cin.tie(NULL);

	cin >> r >> c >> k >> p;
	ll sum[N] = {0}, crow = 0;
	for (int i = 0; i < r; i++) {
		crow = 0LL;
		for (int j = 0; j < c; j++) {
			int c; cin >> c;
			crow += c;
			sum[j] += c;
			if (i == r-1) C.push(sum[j]);
		}
		R.push(crow);
	}
	for (int i = 1; i <= k; i++) {
		ll topr = R.top();
		ansr[i] = ansr[i-1] + topr;
		R.pop();
		R.push(topr - c*p);
		ll topc = C.top();
		ansc[i] = ansc[i-1] + topc;
		C.pop();
		C.push(topc - r*p);
	}
	for (int kk = 0; kk <= k; kk++) {
		ll curr = ansr[kk]+ansc[k-kk]-(ll)kk*(k-kk)*p;
		ans = max(ans, curr);
	}
	cout << ans << endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int>pii;
typedef pair<ll, ll>pll;
const int MAX = 2e5 + 6;
int a[1003][1003];
int RowBest[1003], ColBest[1003];

int main(){

    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    int n, m, k, p;
    cin >> n >> m >> k >> p;

    priority_queue<int>RowSum, ColSum;

    for(int i=1; i<=n; i++){
        int sum = 0;
        for(int j=1; j<=m; j++){
            cin >> a[i][j];
            sum += a[i][j];
        }
        RowSum.push(sum);
    }

    for(int i=1; i<=m; i++){
        int sum = 0;
        for(int j=1; j<=n; j++){
            sum += a[j][i];
        }
        ColSum.push(sum);
    }

    for(int i=1; i<=k; i++){
        int mx = RowSum.top();
        RowBest[i] = mx + RowBest[i-1];
        RowSum.pop();
        RowSum.push(mx-m*p);
    }

    for(int i=1; i<=k; i++){
        int mx = ColSum.top();
        ColBest[i] = mx + ColBest[i-1];
        ColSum.pop();
        ColSum.push(mx-n*p);
    }

    int ans = INT_MIN;

    for(int i=0; i<=k; i++){
        ans = max(ans, RowBest[i] + ColBest[k-i] - i*(k-i)*p);
    }

    cout << ans;

}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int>pii;
typedef pair<ll, ll>pll;
const int MAX = 2e5 + 6;
ll a[1003][1003];
ll RowBest[1003], ColBest[1003];

int main(){

    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    ll n, m, k, p;
    cin >> n >> m >> k >> p;

    priority_queue<ll>RowSum, ColSum;

    for(int i=1; i<=n; i++){
        ll sum = 0;
        for(int j=1; j<=m; j++){
            cin >> a[i][j];
            sum += a[i][j];
        }
        RowSum.push(sum);
    }

    for(int i=1; i<=m; i++){
        ll sum = 0;
        for(int j=1; j<=n; j++){
            sum += a[j][i];
        }
        ColSum.push(sum);
    }

    for(int i=1; i<=k; i++){
        ll mx = RowSum.top();
        RowBest[i] = mx + RowBest[i-1];
        RowSum.pop();
        RowSum.push(mx-m*p);
    }

    for(int i=1; i<=k; i++){
        ll mx = ColSum.top();
        ColBest[i] = mx + ColBest[i-1];
        ColSum.pop();
        ColSum.push(mx-n*p);
    }

    ll ans = -2e18;

    for(ll i=0; i<=k; i++){
        ans = max(ans, RowBest[i] + ColBest[k-i] - i*(k-i)*p);
    }

    cout << ans;

}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int>pii;
typedef pair<ll, ll>pll;
const int MAX = 1e6 + 3;
int a[1003][1003];
int RowBest[MAX], ColBest[MAX];

int main(){

    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    int n, m, k, p;
    cin >> n >> m >> k >> p;

    priority_queue<int>RowSum, ColSum;

    for(int i=1; i<=n; i++){
        int sum = 0;
        for(int j=1; j<=m; j++){
            cin >> a[i][j];
            sum += a[i][j];
        }
        RowSum.push(sum);
    }

    for(int i=1; i<=m; i++){
        int sum = 0;
        for(int j=1; j<=n; j++){
            sum += a[j][i];
        }
        ColSum.push(sum);
    }

    for(int i=1; i<=k; i++){
        int mx = RowSum.top();
        RowBest[i] = mx + RowBest[i-1];
        RowSum.pop();
        RowSum.push(mx-m*p);
    }

    for(int i=1; i<=k; i++){
        int mx = ColSum.top();
        ColBest[i] = mx + ColBest[i-1];
        ColSum.pop();
        ColSum.push(mx-n*p);
    }

    int ans = INT_MIN;

    for(int i=0; i<=k; i++){
        ans = max(ans, RowBest[i] + ColBest[k-i] - i*(k-i)*p);
    }

    cout << ans;

}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int>pii;
typedef pair<ll, ll>pll;
const int MAX = 1e6 + 3;
ll a[1003][1003];
ll RowBest[1003], ColBest[1003];

int main(){

    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    ll n, m, k, p;
    cin >> n >> m >> k >> p;

    priority_queue<ll>RowSum, ColSum;

    for(int i=1; i<=n; i++){
        ll sum = 0;
        for(int j=1; j<=m; j++){
            cin >> a[i][j];
            sum += a[i][j];
        }
        RowSum.push(sum);
    }

    for(int i=1; i<=m; i++){
        ll sum = 0;
        for(int j=1; j<=n; j++){
            sum += a[j][i];
        }
        ColSum.push(sum);
    }

    for(int i=1; i<=k; i++){
        ll mx = RowSum.top();
        RowBest[i] = mx + RowBest[i-1];
        RowSum.pop();
        RowSum.push(mx-m*p);
    }

    for(int i=1; i<=k; i++){
        ll mx = ColSum.top();
        ColBest[i] = mx + ColBest[i-1];
        ColSum.pop();
        ColSum.push(mx-n*p);
    }

    ll ans = -2e18;

    for(ll i=0; i<=k; i++){
        ans = max(ans, RowBest[i] + ColBest[k-i] - i*(k-i)*p);
    }

    cout << ans;

}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int>pii;
typedef pair<ll, ll>pll;
const int MAX = 1e6 + 3;
ll a[1003][1003];
ll RowBest[MAX], ColBest[MAX];

int main(){

    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    ll n, m, k, p;
    cin >> n >> m >> k >> p;

    priority_queue<ll>RowSum, ColSum;

    for(int i=1; i<=n; i++){
        ll sum = 0;
        for(int j=1; j<=m; j++){
            cin >> a[i][j];
            sum += a[i][j];
        }
        RowSum.push(sum);
    }

    for(int i=1; i<=m; i++){
        ll sum = 0;
        for(int j=1; j<=n; j++){
            sum += a[j][i];
        }
        ColSum.push(sum);
    }

    for(int i=1; i<=k; i++){
        ll mx = RowSum.top();
        RowBest[i] = mx + RowBest[i-1];
        RowSum.pop();
        RowSum.push(mx-m*p);
    }

    for(int i=1; i<=k; i++){
        ll mx = ColSum.top();
        ColBest[i] = mx + ColBest[i-1];
        ColSum.pop();
        ColSum.push(mx-n*p);
    }

    ll ans = -2e18;

    for(ll i=0; i<=k; i++){
        ans = max(ans, RowBest[i] + ColBest[k-i] - i*(k-i)*p);
    }

    cout << ans;

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long

ll n,m,k,p;
vector<vector<ll>> a;

void run_case(){
	cin>>n>>m>>k>>p;
	a = vector<vector<ll>>(n,vector<ll>(m,0));
	for(ll i=0;i<n;i++){
		for(ll j = 0;j<m;j++){
			cin>>a[i][j];
		}
	}
	priority_queue<ll> row,col;
	ll delr = 0,delc = 0;
	for(ll i =0;i<n;i++){
		ll sum = 0;
		for(ll j =0;j<m;j++)sum+= a[i][j];
		row.push(sum);
	}
	for(ll j =0;j<m;j++){
		ll sum = 0;
		for(ll i =0;i<n;i++)sum+= a[i][j];
		col.push(sum);
	}
	ll ans = 0;
	while(k--){
		if(row.top()-delr > col.top()-delc){
			ans += row.top()-delr;
			delc += p;
			ll x=  row.top();
			x = x - m*p;
			row.pop();
			row.push(x);
		}
		else{
			ans += col.top()-delc;
			delr += p;
			ll x=  col.top();
			x = x - n*p;
			col.pop();
			col.push(x);
		}
	}
	cout<<ans<<endl;
}

signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);ll tc=1;
// cin>>tc;
while(tc--)run_case();
return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ff first
#define ss second
#define vec vector
#define pb push_back
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pll pair<ll,ll>
#define pi pair<int,int>
#define mod(a,b) (a%b+b)%b
#define flushout cout.flush();
#define sz(x) ((int) (x).size())
#define __lcm(a,b) (a*b)/__gcd(a,b)
#define all(x) (x).begin(), (x).end()
#define vin(a) for(auto &ii : a)cin>>ii
#define f(i,a,b) for(int i=(a);i<(b);i++)
#define fr(i,a,b) for(int i=(b-1);i>=(a);i--)
#define dbg(x) cout<<'>'<< #x <<':'<< x <<endl;
#define pout(x,n) cout<<fixed<<setprecision(x)<<n
#define dbgvec(v) for(auto ii:v)cout<<ii<<' ';cout<<endl;
void run_case();
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);int tc=1;
// cin>>tc;
for(int i=1;i<=tc;i++)
// cout<<"#"<<i<<endl,
run_case();
return 0;
}
const int M = 1000000007;

/* CODE STARTS HERE */
int n,m,k,p;
vec<vi> a;

void run_case(){
	cin>>n>>m>>k>>p;
	a = vec<vi>(n,vi(m));
	f(i,0,n)f(j,0,m)cin>>a[i][j];

	ll ans =  LLONG_MIN;
	f(r,0,k+1){
		int c = k-r;
		// choosing r rows and k-r columns
		ll minus =1ll* r*c*p;
		priority_queue<ll> p1,p2;
		f(i,0,n){
			ll sum = 0;
			f(j,0,m)sum+= a[i][j];
			p1.push(sum);
		}
		f(j,0,m){
			ll sum= 0;
			f(i,0,n) sum += a[i][j];
			p2.push(sum);
		}
		ll temp = 0;
		int rr = r;
		int cc = c;
		while(rr--){
			ll x= p1.top();
			p1.pop();
			temp += x;
			x -= m*p;
			p1.push(x);
		}
		while(cc--){
			ll x = p2.top();
			p2.pop();
			temp += x;
			x-= n*p;
			p2.push(x);
		}
		temp -= minus;
		ans = max(ans,temp);
	}
	cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long

int n,m,k,p;
vector<vector<int>> a;

void run_case(){
	cin>>n>>m>>k>>p;
	a = vector<vector<int>>(n,vector<int>(m,0));
	for(int i=0;i<n;i++){
		for(int j = 0;j<m;j++){
			cin>>a[i][j];
		}
	}
	priority_queue<int> row,col;
	int delr = 0,delc = 0;
	for(int i =0;i<n;i++){
		int sum = 0;
		for(int j =0;j<m;j++)sum+= a[i][j];
		row.push(sum);
	}
	for(int j =0;j<m;j++){
		int sum = 0;
		for(int i =0;i<n;i++)sum+= a[i][j];
		col.push(sum);
	}
	int ans = 0;
	while(k--){
		if(row.top()-delr > col.top()-delc){
			ans += row.top()-delr;
			delc += p;
			int x=  row.top();
			x = x - m*p;
			row.pop();
			row.push(x);
		}
		else{
			ans += col.top()-delc;
			delr += p;
			int x=  col.top();
			x = x - n*p;
			col.pop();
			col.push(x);
		}
	}
	cout<<ans<<endl;
}

signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);int tc=1;
// cin>>tc;
while(tc--)run_case();
return 0;
}


#include <bits/stdc++.h>
#define dbg(x) cout<<'>'<< #x <<':'<< x <<endl;
#define vout(v) for(auto ii:v)cout<<ii<<' ';cout<<endl;
using namespace std;
#define int long long

void run_case(){
	int n,m,k,p;
	cin>>n>>m>>k>>p;
	vector<int> row(n,0);
	vector<int> col(m,0);
	for(int i=0;i<n;i++){
		for(int j = 0;j<m;j++){
			int x;
			cin>>x;
			row[i]+= x;
			col[j]+= x;
		}
	}
	priority_queue<int> q;
	vector<int> best_row = {0},best_col{0};

	for(auto i : row)q.push(i);
	for(int i =0;i<k;i++){
		int x = q.top();
		best_row.push_back(x);
		x -= m*p;
		q.pop();
		q.push(x);
	}

	while(!q.empty())q.pop();

	for(auto i : col)q.push(i);
	for(int i =0;i<k;i++){
		int x = q.top();
		best_col.push_back(x);
		x -= n*p;
		q.pop();
		q.push(x);
	}

	for(int i =1;i<=k;i++){
		best_row[i] += best_row[i-1];
		best_col[i] += best_col[i-1];
	}
	int ans = LLONG_MIN;

	for(int i =0;i<=k;i++){
		ans = max(ans,best_row[i] + best_col[k-i] - 1ll*i*(k-i)*p);
	}
	cout<<ans<<endl;

}

signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);int tc=1;
// cin>>tc;
while(tc--)run_case();
return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long

int n,m,k,p;
vector<vector<int>> a;

void run_case(){
	cin>>n>>m>>k>>p;
	a = vector<vector<int>>(n,vector<int>(m,0));
	for(int i=0;i<n;i++){
		for(int j = 0;j<m;j++){
			cin>>a[i][j];
		}
	}
	priority_queue<int> row,col;
	int delr = 0,delc = 0;
	for(int i =0;i<n;i++){
		int sum = 0;
		for(int j =0;j<m;j++)sum+= a[i][j];
		row.push(sum);
	}
	for(int j =0;j<m;j++){
		int sum = 0;
		for(int i =0;i<n;i++)sum+= a[i][j];
		col.push(sum);
	}
	int ans = 0;
	while(k--){
		if(row.top()-delr > col.top()-delc){
			ans += row.top()-delr;
			delc += p;
			int x=  row.top();
			x = x - m*p;
			row.pop();
			row.push(x);
		}
		else{
			ans += col.top()-delc;
			delr += p;
			int x=  col.top();
			x = x - n*p;
			col.pop();
			col.push(x);
		}
	}
	cout<<ans<<endl;
}

signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);int tc=1;
// cin>>tc;
while(tc--)run_case();
return 0;
}


#include <bits/stdc++.h>
#define dbg(x) cout<<'>'<< #x <<':'<< x <<endl;
#define vout(v) for(auto ii:v)cout<<ii<<' ';cout<<endl;
using namespace std;
#define int long long

void run_case(){
	int n,m,k,p;
	cin>>n>>m>>k>>p;
	vector<int> row(n,0);
	vector<int> col(m,0);
	for(int i=0;i<n;i++){
		for(int j = 0;j<m;j++){
			int x;
			cin>>x;
			row[i]+= x;
			col[j]+= x;
		}
	}
	priority_queue<int> q;
	vector<int> best_row = {0},best_col{0};

	for(auto i : row)q.push(i);
	for(int i =0;i<=k;i++){
		int x = q.top();
		best_row.push_back(x);
		x -= m*p;
		q.pop();
		q.push(x);
	}

	while(!q.empty())q.pop();

	for(auto i : col)q.push(i);
	for(int i =0;i<k;i++){
		int x = q.top();
		best_col.push_back(x);
		x -= n*p;
		q.pop();
		q.push(x);
	}

	for(int i =1;i<k;i++){
		best_row[i] += best_row[i-1];
		best_col[i] += best_col[i-1];
	}
	int ans = LLONG_MIN;

	for(int i =0;i<=k;i++){
		ans = max(ans,best_row[i] + best_col[k-i] - 1ll*i*(k-i)*p);
	}
	cout<<ans<<endl;

}

signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);int tc=1;
// cin>>tc;
while(tc--)run_case();
return 0;
}


/*
Name                     : Harry Singh (:)
Age                      : 20 (:)
College                  : Lovely Professional University (:)
Email                    : harryamneet600@gmail.com (:)
Hobbies                  : Coding and Typeracer (:)
Goal                     : Long term is fixed and Short term is changing everyday (:)
Relatoinship Status      : Single (:)
Phone no                 : 91-********77 (:)
Waheguru Ji ka Khalsa, Waheguru Ji ki Fateh;
*/
#include<bits/stdc++.h>
#define int long long
#define double double
#define io ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define ipair pair<int,int>
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fo(i,n) for(int i=n;i>=0;i--)
#define F(i,n) for(int i=1;i<=n;i++)
#define f_a(a,i,n) for(int i=a;i<=n;i++)
#define f_b(a,i,b) for(int i=a;i<=b;i++)
#define FO(i,n) for(int i=n;i>=1;i--)
#define mod 1000000007
using namespace std;
#define inf 100000000000000009
#define tr cout<<"\n"
#define br break
const int N = 2*1e5+7;
const int INF = 1e17;

// struct cmp {
//     bool operator() (const ipair& lhs, const ipair& rhs) const{
//         if(lhs.first < rhs.first) return true;
//         return false;
//     }
// };

void Waheguru()
{
	int n,m,k,p;
	cin>>n>>m>>k>>p;
	int r[n+1]={0},c[m+1]={0},a[n+1][m+1];
	priority_queue < ipair > row,col;
	F(i,n){F(j,m){cin>>a[i][j];
	r[i]+=a[i][j];}row.push({r[i],0});}
	F(i,m){
	F(j,n){c[i]+=a[j][i];}
	col.push({c[i],0});}
    int row_penalty=0,col_penalty=0,ans=0;

    if(n==1 && m==1)
    {
    	F(i,k)
    	{
    		ans+=a[1][1];
    		a[1][1]-=p;
    	}
    	cout<<ans;
    	tr;
    }
    else if(n==1 && m>1)
    {
        F(i,k)
    	{
    		ans+=row.top().first;
    		row.pop();
    		row.push({row.top().first-(p*m),0});
    	}
    	cout<<ans;
    	tr;
    }
    else if(m==1 && n>1)
    {
        F(i,k)
    	{
    		ans+=col.top().first;
    		col.pop();
    		col.push({col.top().first-(p*n),0});
    	}
    	cout<<ans;
    	tr;
    }
    else
    {

    F(i,k)
	{
     ipair rc=row.top();
     ipair cc=col.top();
     int t1=row_penalty-rc.second;// Number of the penalties left to used for row
     int t2=col_penalty-cc.second;// Number of the penalties left to used for col

     if(rc.first-t1*p>cc.first-t2*p)
     {
     	// Row has the more Power
     	ans+=(rc.first-(t1*p));
     	row.pop();
     	if(p==0)row.push({(rc.first-t1*p)-(p*m),0});
     	else row.push({(rc.first-t1*p)-(p*m),row_penalty});
     	col_penalty++;// Give the one penalty to col
     }
     else
     {
     	// Col has the more Power
     	ans+=(cc.first-(t2*p));
     	col.pop();
     	if(p==0)col.push({(cc.first-t2*p)-(p*n),0});
     	else col.push({(cc.first-t2*p)-(p*n),col_penalty});
     	row_penalty++;// Give the one penalty to col
     }

    }

    cout<<ans;
    tr;
    }

}

int32_t main()
{
#ifndef ONLINE_JUDGE
 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout);
#endif
    io;
    int g=1;
    while (g--)Waheguru();
    return 0;
}


/*
Name                     : Harry Singh (:)
Age                      : 20 (:)
College                  : Lovely Professional University (:)
Email                    : harryamneet600@gmail.com (:)
Hobbies                  : Coding and Typeracer (:)
Goal                     : Long term is fixed and Short term is changing everyday (:)
Relatoinship Status      : Single (:)
Phone no                 : 91-********77 (:)
Waheguru Ji ka Khalsa, Waheguru Ji ki Fateh;
*/
#include<bits/stdc++.h>
#define int long long
#define double double
#define io ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define ipair pair<int,int>
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fo(i,n) for(int i=n;i>=0;i--)
#define F(i,n) for(int i=1;i<=n;i++)
#define f_a(a,i,n) for(int i=a;i<=n;i++)
#define f_b(a,i,b) for(int i=a;i<=b;i++)
#define FO(i,n) for(int i=n;i>=1;i--)
#define mod 1000000007
using namespace std;
#define tr cout<<"\n"
#define br break
const int N = 2*1e5+7;
int inf=0x3f3f3f3f;

// struct cmp {
//     bool operator() (const ipair& lhs, const ipair& rhs) const{
//         if(lhs.first < rhs.first) return true;
//         return false;
//     }
// };
long long l[1005],h[1005];
long long a[1000005],b[1000005];
priority_queue<int> hang;
priority_queue<int> lie;
void Waheguru()
{
	int ans=-inf*inf;
	int n,m,k,p,shu;
	cin>>n>>m>>k>>p;
	F(i,n)F(j,m)
	{
		cin>>shu;
		l[i]+=shu;
		h[j]+=shu;
	}
	F(i,n)hang.push(l[i]);
	F(i,m)lie.push(h[i]);

	F(i,k)
	{
		int o=hang.top();
		hang.pop();
		a[i]=a[i-1]+o;
		hang.push(o-p*m);
	}
	F(i,k)
	{
		int o=lie.top();
		lie.pop();
		b[i]=b[i-1]+o;
		lie.push(o-p*n);
	}
	f(i,k+1)ans=max(a[i]+b[k-i]-(k-i)*i*p,ans);
	cout<<ans<<endl;
	tr;

}

int32_t main()
{
#ifndef ONLINE_JUDGE
 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout);
#endif
    io;
    int g=1;
    while (g--)Waheguru();
    return 0;
}


/*
Name                     : Harry Singh (:)
Age                      : 20 (:)
College                  : Lovely Professional University (:)
Email                    : harryamneet600@gmail.com (:)
Hobbies                  : Coding and Typeracer (:)
Goal                     : Long term is fixed and Short term is changing everyday (:)
Relatoinship Status      : Single (:)
Phone no                 : 91-********77 (:)
Waheguru Ji ka Khalsa, Waheguru Ji ki Fateh;
*/
#include<bits/stdc++.h>
#define int long long
#define double double
#define io ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define ipair pair<int,int>
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fo(i,n) for(int i=n;i>=0;i--)
#define F(i,n) for(int i=1;i<=n;i++)
#define f_a(a,i,n) for(int i=a;i<=n;i++)
#define f_b(a,i,b) for(int i=a;i<=b;i++)
#define FO(i,n) for(int i=n;i>=1;i--)
#define mod 1000000007
using namespace std;
#define inf 100000000000000009
#define tr cout<<"\n"
#define br break
const int N = 2*1e5+7;
const int INF = 1e17;

// struct cmp {
//     bool operator() (const ipair& lhs, const ipair& rhs) const{
//         if(lhs.first < rhs.first) return true;
//         return false;
//     }
// };

void Waheguru()
{
	int n,m,k,p;
	cin>>n>>m>>k>>p;
	int r[n+1]={0},c[m+1]={0},a[n+1][m+1];
	priority_queue < ipair > row,col;
	F(i,n){F(j,m){cin>>a[i][j];
	r[i]+=a[i][j];}row.push({r[i],0});}
	F(i,m){
	F(j,n){c[i]+=a[j][i];}
	col.push({c[i],0});}
    int row_penalty=0,col_penalty=0,ans=0;

    if(n==1 && m==1)
    {
    	F(i,k)
    	{
    		ans+=a[1][1];
    		a[1][1]-=p;
    	}
    	cout<<ans;
    	tr;
    }
    else if(n==1 && m>1)
    {
        F(i,k)
    	{
    		ans+=row.top().first;
    		row.pop();
    		row.push({row.top().first-(p*m),0});
    	}
    	cout<<ans;
    	tr;
    }
    else if(m==1 && n>1)
    {
        F(i,k)
    	{
    		ans+=col.top().first;
    		col.pop();
    		col.push({col.top().first-(p*n),0});
    	}
    	cout<<ans;
    	tr;
    }
    else
    {

    F(i,k)
	{
     ipair rc=row.top();
     ipair cc=col.top();
     int t1=row_penalty-rc.second*p;// Number of the penalties left to used for row
     int t2=col_penalty-cc.second*p;// Number of the penalties left to used for col

     if(rc.first-t1>cc.first-t2)
     {
     	// Row has the more Power
     	ans+=(rc.first-t1);
     	row.pop();
     	if(p==0)row.push({(rc.first-t1)-(p*m),0});
     	else row.push({(rc.first-t1)-(p*m),row_penalty/p});
     	col_penalty+=p;// Give the one penalty to col
     }
     else
     {
     	// Col has the more Power
     	ans+=(cc.first-t2);
     	col.pop();
     	if(p==0)col.push({(cc.first-t2)-(p*n),0});
     	else col.push({(cc.first-t2)-(p*n),col_penalty/p});
     	row_penalty+=p;// Give the one penalty to col
     }

    }

    cout<<ans;
    tr;
    }

}

int32_t main()
{
#ifndef ONLINE_JUDGE
 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout);
#endif
    io;
    int g=1;
    while (g--)Waheguru();
    return 0;
}


/*
Name                     : Harry Singh (:)
Age                      : 20 (:)
College                  : Lovely Professional University (:)
Email                    : harryamneet600@gmail.com (:)
Hobbies                  : Coding and Typeracer (:)
Goal                     : Long term is fixed and Short term is changing everyday (:)
Relatoinship Status      : Single (:)
Phone no                 : 91-********77 (:)
Waheguru Ji ka Khalsa, Waheguru Ji ki Fateh;
*/
#include<bits/stdc++.h>
#define int long long
#define double double
#define io ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define ipair pair<int,int>
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fo(i,n) for(int i=n;i>=0;i--)
#define F(i,n) for(int i=1;i<=n;i++)
#define f_a(a,i,n) for(int i=a;i<=n;i++)
#define f_b(a,i,b) for(int i=a;i<=b;i++)
#define FO(i,n) for(int i=n;i>=1;i--)
#define mod 1000000007
using namespace std;
#define inf 100000000000000009
#define tr cout<<"\n"
#define br break
const int N = 2*1e5+7;
const int INF = 1e17;

// struct cmp {
//     bool operator() (const ipair& lhs, const ipair& rhs) const{
//         if(lhs.first < rhs.first) return true;
//         return false;
//     }
// };

void Waheguru()
{
	int n,m,k,p;
	cin>>n>>m>>k>>p;
	priority_queue < int > row,col;
	int r[n+1]={0},c[m+1]={0};
	F(i,n)
	F(j,m)
	{
		int bal;
		cin>>bal;
		r[i]+=bal;
		c[j]+=bal;
	}
	F(i,n)row.push(r[i]);
	F(i,m)col.push(c[i]);
	int pre1[100001]={0};
	int pre2[100001]={0};

	F(i,k)
	{
		int tp=row.top();
		row.pop();
		pre1[i]=pre1[i-1]+tp;
		row.push(tp-m*p);
	}
	F(i,k)
	{
		int tp=col.top();
		col.pop();
		pre2[i]=pre2[i-1]+tp;
		col.push(tp-n*p);
	}
    int ans=-INF;
	f(i,k+1)
	ans=max(ans,pre1[i]+pre2[k-i]-(k-i)*i*p);

	cout<<ans;
	tr;

}

int32_t main()
{
#ifndef ONLINE_JUDGE
 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout);
#endif
    io;
    int g=1;
    while (g--)Waheguru();
    return 0;
}


/*
Name                     : Harry Singh (:)
Age                      : 20 (:)
College                  : Lovely Professional University (:)
Email                    : harryamneet600@gmail.com (:)
Hobbies                  : Coding and Typeracer (:)
Goal                     : Long term is fixed and Short term is changing everyday (:)
Relatoinship Status      : Single (:)
Phone no                 : 91-********77 (:)
Waheguru Ji ka Khalsa, Waheguru Ji ki Fateh;
*/
#include<bits/stdc++.h>
#define int long long
#define double double
#define io ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define ipair pair<int,int>
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fo(i,n) for(int i=n;i>=0;i--)
#define F(i,n) for(int i=1;i<=n;i++)
#define f_a(a,i,n) for(int i=a;i<=n;i++)
#define f_b(a,i,b) for(int i=a;i<=b;i++)
#define FO(i,n) for(int i=n;i>=1;i--)
#define mod 1000000007
using namespace std;
#define inf 100000000000000009
#define tr cout<<"\n"
#define br break
const int N = 2*1e5+7;
const int INF = 1e17;

// struct cmp {
//     bool operator() (const ipair& lhs, const ipair& rhs) const{
//         if(lhs.first < rhs.first) return true;
//         return false;
//     }
// };

void Waheguru()
{
	int n,m,k,p;
	cin>>n>>m>>k>>p;
	int r[n+1]={0},c[m+1]={0},a[n+1][m+1];
	priority_queue < int > row,col;
	F(i,n){F(j,m){cin>>a[i][j];
	r[i]+=a[i][j];}row.push(r[i]);}
	F(i,m){
	F(j,n){c[i]+=a[j][i];}
	col.push(c[i]);}
	int pre1[1001]={0};
	int pre2[1001]={0};

	F(i,k)
	{
		int tp=row.top();
		row.pop();
		pre1[i]=pre1[i-1]+tp;
		row.push(tp-m*p);
	}
	F(i,k)
	{
		int tp=col.top();
		col.pop();
		pre2[i]=pre2[i-1]+tp;
		col.push(tp-n*p);
	}
    int ans=-INF;;
	f(i,k+1)
	ans=max(ans,pre1[i]+pre2[k-i]-(k-i)*i*p);

	cout<<ans;
	tr;

}

int32_t main()
{
#ifndef ONLINE_JUDGE
 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout);
#endif
    io;
    int g=1;
    while (g--)Waheguru();
    return 0;
}


/*
Name                     : Harry Singh (:)
Age                      : 20 (:)
College                  : Lovely Professional University (:)
Email                    : harryamneet600@gmail.com (:)
Hobbies                  : Coding and Typeracer (:)
Goal                     : Long term is fixed and Short term is changing everyday (:)
Relatoinship Status      : Single (:)
Phone no                 : 91-********77 (:)
Waheguru Ji ka Khalsa, Waheguru Ji ki Fateh;
*/
#include<bits/stdc++.h>
#define int long long
#define double double
#define io ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define ipair pair<int,int>
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fo(i,n) for(int i=n;i>=0;i--)
#define F(i,n) for(int i=1;i<=n;i++)
#define f_a(a,i,n) for(int i=a;i<=n;i++)
#define f_b(a,i,b) for(int i=a;i<=b;i++)
#define FO(i,n) for(int i=n;i>=1;i--)
#define mod 1000000007
using namespace std;
#define inf 100000000000000009
#define tr cout<<"\n"
#define br break
const int N = 2*1e5+7;
const int INF = 1e17;

// struct cmp {
//     bool operator() (const ipair& lhs, const ipair& rhs) const{
//         if(lhs.first < rhs.first) return true;
//         return false;
//     }
// };

void Waheguru()
{
	int n,m,k,p;
	cin>>n>>m>>k>>p;
	int r[n+1]={0},c[m+1]={0},a[n+1][m+1];
	priority_queue < int > row,col;
	F(i,n){F(j,m){cin>>a[i][j];
	r[i]+=a[i][j];}row.push(r[i]);}
	F(i,m){
	F(j,n){c[i]+=a[j][i];}
	col.push(c[i]);}
	int pre1[1001]={0};
	int pre2[1001]={0};

	F(i,k)
	{
		int tp=row.top();
		row.pop();
		pre1[i]=pre1[i-1]+tp;
		row.push(tp-m*p);
	}
	F(i,k)
	{
		int tp=col.top();
		col.pop();
		pre2[i]=pre2[i-1]+tp;
		col.push(tp-n*p);
	}
    int ans=0;
	f(i,k+1)
	ans=max(ans,pre1[i]+pre2[k-i]-(k-i)*i*p);

	cout<<ans;
	tr;

}

int32_t main()
{
#ifndef ONLINE_JUDGE
 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout);
#endif
    io;
    int g=1;
    while (g--)Waheguru();
    return 0;
}


/*
Name                     : Harry Singh (:)
Age                      : 20 (:)
College                  : Lovely Professional University (:)
Email                    : harryamneet600@gmail.com (:)
Hobbies                  : Coding and Typeracer (:)
Goal                     : Long term is fixed and Short term is changing everyday (:)
Relatoinship Status      : Single (:)
Phone no                 : 91-********77 (:)
Waheguru Ji ka Khalsa, Waheguru Ji ki Fateh;
*/
#include<bits/stdc++.h>
#define int long long
#define double double
#define io ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define ipair pair<int,int>
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fo(i,n) for(int i=n;i>=0;i--)
#define F(i,n) for(int i=1;i<=n;i++)
#define f_a(a,i,n) for(int i=a;i<=n;i++)
#define f_b(a,i,b) for(int i=a;i<=b;i++)
#define FO(i,n) for(int i=n;i>=1;i--)
#define mod 1000000007
using namespace std;
#define tr cout<<"\n"
#define br break
const int N = 2*1e5+7;
int inf=0x3f3f3f3f;

// struct cmp {
//     bool operator() (const ipair& lhs, const ipair& rhs) const{
//         if(lhs.first < rhs.first) return true;
//         return false;
//     }
// };
priority_queue < int > row;
priority_queue < int > col;
int r[1001]={0},c[1001]={0};
int pre1[100001]={0};
int pre2[100001]={0};
void Waheguru()
{
	int n,m,k,p;
	int ans=-inf*inf;
	cin>>n>>m>>k>>p;

	F(i,n)
	F(j,m)
	{
		int bal;
		cin>>bal;
		r[i]+=bal;
		c[j]+=bal;
	}
	F(i,n)row.push(r[i]);
	F(i,m)col.push(c[i]);

	F(i,k)
	{
		int tp=row.top();
		row.pop();
		pre1[i]=pre1[i-1]+tp;
		row.push(tp-m*p);
	}
	F(i,k)
	{
		int tp=col.top();
		col.pop();
		pre2[i]=pre2[i-1]+tp;
		col.push(tp-n*p);
	}
	f(i,k+1)
	ans=max(ans,pre1[i]+pre2[k-i]-(k-i)*i*p);

	cout<<ans;
	tr;

}

int32_t main()
{
#ifndef ONLINE_JUDGE
 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout);
#endif
    io;
    int g=1;
    while (g--)Waheguru();
    return 0;
}


/*
Name                     : Harry Singh (:)
Age                      : 20 (:)
College                  : Lovely Professional University (:)
Email                    : harryamneet600@gmail.com (:)
Hobbies                  : Coding and Typeracer (:)
Goal                     : Long term is fixed and Short term is changing everyday (:)
Relatoinship Status      : Single (:)
Phone no                 : 91-********77 (:)
Waheguru Ji ka Khalsa, Waheguru Ji ki Fateh;
*/
#include<bits/stdc++.h>
#define int long long
#define double double
#define io ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define ipair pair<int,int>
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fo(i,n) for(int i=n;i>=0;i--)
#define F(i,n) for(int i=1;i<=n;i++)
#define f_a(a,i,n) for(int i=a;i<=n;i++)
#define f_b(a,i,b) for(int i=a;i<=b;i++)
#define FO(i,n) for(int i=n;i>=1;i--)
#define mod 1000000007
using namespace std;
#define inf 100000000000000009
#define tr cout<<"\n"
#define br break
const int N = 2*1e5+7;
const int INF = 1e17;

// struct cmp {
//     bool operator() (const ipair& lhs, const ipair& rhs) const{
//         if(lhs.first < rhs.first) return true;
//         return false;
//     }
// };

void Waheguru()
{
	int n,m,k,p;
	cin>>n>>m>>k>>p;
	int r[n+1]={0},c[m+1]={0},a[n+1][m+1];
	priority_queue < ipair > row,col;
	F(i,n){F(j,m){cin>>a[i][j];
	r[i]+=a[i][j];}row.push({r[i],0});}
	F(i,m){
	F(j,n){c[i]+=a[j][i];}
	col.push({c[i],0});}

    int row_penalty=0,col_penalty=0,ans=0;

    if(n==1 && m==1)
    {
    	F(i,k)
    	{
    		ans+=a[1][1];
    		a[1][1]-=p;
    	}
    	cout<<ans;
    	tr;
    }
    else if(n==1 && m>1)
    {
        F(i,k)
    	{
    		ans+=row.top().first;
    		row.pop();
    		row.push({row.top().first-(p*m),0});
    	}
    	cout<<ans;
    	tr;
    }
    else if(m==1 && n>1)
    {
        F(i,k)
    	{
    		ans+=col.top().first;
    		col.pop();
    		col.push({col.top().first-(p*n),0});
    	}
    	cout<<ans;
    	tr;
    }
    else
    {

    F(i,k)
	{
     ipair rc=row.top();
     ipair cc=col.top();
     int t1=row_penalty-rc.second*p;// Number of the penalties left to used for row
     int t2=col_penalty-cc.second*p;// Number of the penalties left to used for col

     if(rc.first-t1>cc.first-t2)
     {
     	// Row has the more Power
     	ans+=(rc.first-t1);
     	row.pop();
     	row.push({(rc.first-t1)-(p*m),row_penalty/p});
     	col_penalty+=p;// Give the one penalty to col
     }
     else
     {
     	// Col has the more Power
     	ans+=(cc.first-t2);
     	col.pop();
     	col.push({(cc.first-t2)-(p*n),col_penalty/p});
     	row_penalty+=p;// Give the one penalty to col
     }

    }

    cout<<ans;
    tr;
    }

}

int32_t main()
{
#ifndef ONLINE_JUDGE
 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout);
#endif
    io;
    int g=1;
    while (g--)Waheguru();
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
using namespace std;
const int NUM=1010;
const int MAX=1e6+10;
int col[NUM],row[NUM];
priority_queue<int> pq_row,pq_col;
int dp_row[MAX],dp_col[MAX];
int main()
{
    int n,m,k,p,x;
    scanf("%d%d%d%d",&n,&m,&k,&p);
    for (int i=1; i<=n; i++)
        for (int j=1; j<=m; j++)
        {
            scanf("%d",&x);
            row[i]+=x;
            col[j]+=x;
        }
    for (int i=1;i<=n;i++)
        pq_row.push(row[i]);
    for (int i=1;i<=m;i++)
        pq_col.push(col[i]);
    for (int i=1;i<=k;i++)
    {
        int x=pq_row.top();
        dp_row[i]=dp_row[i-1]+x;
        pq_row.pop();
        pq_row.push(x-p*m);
        int y=pq_col.top();
        pq_col.pop();
        pq_col.push(y-p*n);
        dp_col[i]=dp_col[i-1]+y;
    }
    long long ans=0;
    for (int i=1;i<=k;i++)
        ans=max(ans,dp_row[i]+dp_col[k-i]-(long long)p*(k-i)*i);
    printf("%lld\n",ans);
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#define ll long long
using namespace std;
const int NUM=1010;
const int MAX=1e6+10;
priority_queue<int> pq_row,pq_col;
ll dp_row[MAX],dp_col[MAX],col[NUM],row[NUM];
int main()
{
    int n,m,k,p,x;
    scanf("%d%d%d%d",&n,&m,&k,&p);
    for (int i=1; i<=n; i++)
        for (int j=1; j<=m; j++)
        {
            scanf("%d",&x);
            row[i]+=x;
            col[j]+=x;
        }
    for (int i=1;i<=n;i++)
        pq_row.push(row[i]);
    for (int i=1;i<=m;i++)
        pq_col.push(col[i]);
    for (int i=1;i<=k;i++)
    {
        ll x=pq_row.top();
        dp_row[i]=dp_row[i-1]+x;
        pq_row.pop();
        pq_row.push(x-p*m);
        ll y=pq_col.top();
        pq_col.pop();
        pq_col.push(y-p*n);
        dp_col[i]=dp_col[i-1]+y;
    }
    ll ans=0;
    for (int i=1;i<=k;i++)
        ans=max(ans,dp_row[i]+dp_col[k-i]-p*(k-i)*i);
    printf("%lld\n",ans);
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#define ll long long
using namespace std;
const int NUM=1010;
const int MAX=1e6+10;
priority_queue<ll> pq_row,pq_col;
ll dp_row[MAX],dp_col[MAX],col[NUM],row[NUM];
int main()
{
    int n,m,k,p,x;
    scanf("%d%d%d%d",&n,&m,&k,&p);
    for (int i=1; i<=n; i++)
        for (int j=1; j<=m; j++)
        {
            scanf("%d",&x);
            row[i]+=x;
            col[j]+=x;
        }
    for (int i=1;i<=n;i++)
        pq_row.push(row[i]);
    for (int i=1;i<=m;i++)
        pq_col.push(col[i]);
    for (int i=1;i<=k;i++)
    {
        ll x=pq_row.top();
        dp_row[i]=dp_row[i-1]+x;
        pq_row.pop();
        pq_row.push(x-p*m);
        ll y=pq_col.top();
        pq_col.pop();
        pq_col.push(y-p*n);
        dp_col[i]=dp_col[i-1]+y;
    }
    ll ans=0;
    for (int i=0;i<=k;i++)
        ans=max(ans,dp_row[i]+dp_col[k-i]-(ll)(p)*(k-i)*i);
    printf("%lld\n",ans);
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <limits.h>
#define ll long long
using namespace std;
const int limit=1e18;
const int NUM=1010;
const int MAX=1e6+10;
priority_queue<ll> pq_row,pq_col;
ll dp_row[MAX],dp_col[MAX],col[NUM],row[NUM];
int main()
{
    int n,m,k,p,x;
    scanf("%d%d%d%d",&n,&m,&k,&p);
    for (int i=1; i<=n; i++)
        for (int j=1; j<=m; j++)
        {
            scanf("%d",&x);
            row[i]+=x;
            col[j]+=x;
        }
    for (int i=1;i<=n;i++)
        pq_row.push(row[i]);
    for (int i=1;i<=m;i++)
        pq_col.push(col[i]);
    for (int i=1;i<=k;i++)
    {
        ll x=pq_row.top();
        dp_row[i]=dp_row[i-1]+x;
        pq_row.pop();
        pq_row.push(x-p*m);
        ll y=pq_col.top();
        pq_col.pop();
        pq_col.push(y-p*n);
        dp_col[i]=dp_col[i-1]+y;
    }
    ll ans=-limit;
    for (int i=0;i<=k;i++)
        ans=max(ans,dp_row[i]+dp_col[k-i]-(ll)(p)*(k-i)*i);
    printf("%lld\n",ans);
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <limits.h>
#define ll long long
using namespace std;
const ll limit=1e18;
const int NUM=1010;
const int MAX=1e6+10;
priority_queue<ll> pq_row,pq_col;
ll dp_row[MAX],dp_col[MAX],col[NUM],row[NUM];
int main()
{
    int n,m,k,p,x;
    scanf("%d%d%d%d",&n,&m,&k,&p);
    for (int i=1; i<=n; i++)
        for (int j=1; j<=m; j++)
        {
            scanf("%d",&x);
            row[i]+=x;
            col[j]+=x;
        }
    for (int i=1;i<=n;i++)
        pq_row.push(row[i]);
    for (int i=1;i<=m;i++)
        pq_col.push(col[i]);
    for (int i=1;i<=k;i++)
    {
        ll x=pq_row.top();
        dp_row[i]=dp_row[i-1]+x;
        pq_row.pop();
        pq_row.push(x-p*m);
        ll y=pq_col.top();
        pq_col.pop();
        pq_col.push(y-p*n);
        dp_col[i]=dp_col[i-1]+y;
    }
    ll ans=-limit;
    for (int i=0;i<=k;i++)
        ans=max(ans,dp_row[i]+dp_col[k-i]-(ll)(p)*(k-i)*i);
    printf("%lld\n",ans);
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#define ll long long
using namespace std;
const int NUM=1010;
const int MAX=1e6+10;
priority_queue<int> pq_row,pq_col;
ll dp_row[MAX],dp_col[MAX],col[NUM],row[NUM];
int main()
{
    int n,m,k,p,x;
    scanf("%d%d%d%d",&n,&m,&k,&p);
    for (int i=1; i<=n; i++)
        for (int j=1; j<=m; j++)
        {
            scanf("%d",&x);
            row[i]+=x;
            col[j]+=x;
        }
    for (int i=1;i<=n;i++)
        pq_row.push(row[i]);
    for (int i=1;i<=m;i++)
        pq_col.push(col[i]);
    for (int i=1;i<=k;i++)
    {
        ll x=pq_row.top();
        dp_row[i]=dp_row[i-1]+x;
        pq_row.pop();
        pq_row.push(x-p*n);
        ll y=pq_col.top();
        pq_col.pop();
        pq_col.push(y-p*m);
        dp_col[i]=dp_col[i-1]+y;
    }
    ll ans=0;
    for (int i=1;i<=k;i++)
        ans=max(ans,dp_row[i]+dp_col[k-i]-p*(k-i)*i);
    printf("%lld\n",ans);
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#define ll long long
using namespace std;
const int NUM=1010;
const int MAX=1e6+10;
priority_queue<ll> pq_row,pq_col;
ll dp_row[MAX],dp_col[MAX],col[NUM],row[NUM];
int main()
{
    int n,m,k,p,x;
    scanf("%d%d%d%d",&n,&m,&k,&p);
    for (int i=1; i<=n; i++)
        for (int j=1; j<=m; j++)
        {
            scanf("%d",&x);
            row[i]+=x;
            col[j]+=x;
        }
    for (int i=1;i<=n;i++)
        pq_row.push(row[i]);
    for (int i=1;i<=m;i++)
        pq_col.push(col[i]);
    for (int i=1;i<=k;i++)
    {
        ll x=pq_row.top();
        dp_row[i]=dp_row[i-1]+x;
        pq_row.pop();
        pq_row.push(x-p*m);
        ll y=pq_col.top();
        pq_col.pop();
        pq_col.push(y-p*n);
        dp_col[i]=dp_col[i-1]+y;
    }
    ll ans=0;
    for (int i=0;i<=k;i++)
        ans=max(ans,dp_row[i]+dp_col[k-i]-(ll)p*(k-i)*i);
    printf("%lld\n",ans);
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#define ll long long
using namespace std;
const int NUM=1010;
const int MAX=1e6+10;
priority_queue<ll> pq_row,pq_col;
ll dp_row[MAX],dp_col[MAX],col[NUM],row[NUM];
int main()
{
    int n,m,k,p,x;
    scanf("%d%d%d%d",&n,&m,&k,&p);
    for (int i=1; i<=n; i++)
        for (int j=1; j<=m; j++)
        {
            scanf("%d",&x);
            row[i]+=x;
            col[j]+=x;
        }
    for (int i=1;i<=n;i++)
        pq_row.push(row[i]);
    for (int i=1;i<=m;i++)
        pq_col.push(col[i]);
    for (int i=1;i<=k;i++)
    {
        ll x=pq_row.top();
        dp_row[i]=dp_row[i-1]+x;
        pq_row.pop();
        pq_row.push(x-p*m);
        ll y=pq_col.top();
        pq_col.pop();
        pq_col.push(y-p*n);
        dp_col[i]=dp_col[i-1]+y;
    }
    ll ans=0;
    for (int i=0;i<=k;i++)
        ans=max(ans,dp_row[i]+dp_col[k-i]-p*(k-i)*i);
    printf("%lld\n",ans);
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
using namespace std;
const int NUM=1010;
int col[NUM],row[NUM];
priority_queue<int> pq_row,pq_col;
int dp_row[NUM],dp_col[NUM];
int main()
{
    int n,m,k,p,x;
    scanf("%d%d%d%d",&n,&m,&k,&p);
    for (int i=1; i<=n; i++)
        for (int j=1; j<=m; j++)
        {
            scanf("%d",&x);
            row[i]+=x;
            col[j]+=x;
        }
    for (int i=1;i<=n;i++)
        pq_row.push(row[i]);
    for (int i=1;i<=m;i++)
        pq_col.push(col[i]);
    for (int i=1;i<=k;i++)
    {
        int x=pq_row.top();
        dp_row[i]=dp_row[i-1]+x;
        pq_row.pop();
        pq_row.push(x-p*m);
        int y=pq_col.top();
        pq_col.pop();
        pq_col.push(y-p*n);
        dp_col[i]=dp_col[i-1]+y;
    }
    int ans=0;
    for (int i=1;i<=k;i++)
        ans=max(ans,dp_row[i]+dp_col[k-i]-p*(k-i)*i);
    printf("%d\n",ans);
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#define ll long long
using namespace std;
const int NUM=1010;
const int MAX=1e6+10;
priority_queue<int> pq_row,pq_col;
ll dp_row[MAX],dp_col[MAX],col[NUM],row[NUM];
int main()
{
    int n,m,k,p,x;
    scanf("%d%d%d%d",&n,&m,&k,&p);
    for (int i=1; i<=n; i++)
        for (int j=1; j<=m; j++)
        {
            scanf("%d",&x);
            row[i]+=x;
            col[j]+=x;
        }
    for (int i=1;i<=n;i++)
        pq_row.push(row[i]);
    for (int i=1;i<=m;i++)
        pq_col.push(col[i]);
    for (int i=1;i<=k;i++)
    {
        ll x=pq_row.top();
        dp_row[i]=dp_row[i-1]+x;
        pq_row.pop();
        pq_row.push(x-p*m);
        ll y=pq_col.top();
        pq_col.pop();
        pq_col.push(y-p*n);
        dp_col[i]=dp_col[i-1]+y;
    }
    ll ans=0;
    for (int i=0;i<=k;i++)
        ans=max(ans,dp_row[i]+dp_col[k-i]-p*(k-i)*i);
    printf("%lld\n",ans);
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <limits.h>
#define ll long long
using namespace std;
const int NUM=1010;
const int MAX=1e6+10;
priority_queue<ll> pq_row,pq_col;
ll dp_row[MAX],dp_col[MAX],col[NUM],row[NUM];
int main()
{
    int n,m,k,p,x;
    scanf("%d%d%d%d",&n,&m,&k,&p);
    for (int i=1; i<=n; i++)
        for (int j=1; j<=m; j++)
        {
            scanf("%d",&x);
            row[i]+=x;
            col[j]+=x;
        }
    for (int i=1;i<=n;i++)
        pq_row.push(row[i]);
    for (int i=1;i<=m;i++)
        pq_col.push(col[i]);
    for (int i=1;i<=k;i++)
    {
        ll x=pq_row.top();
        dp_row[i]=dp_row[i-1]+x;
        pq_row.pop();
        pq_row.push(x-p*m);
        ll y=pq_col.top();
        pq_col.pop();
        pq_col.push(y-p*n);
        dp_col[i]=dp_col[i-1]+y;
    }
    ll ans=-INT_MAX;
    for (int i=0;i<=k;i++)
        ans=max(ans,dp_row[i]+dp_col[k-i]-(ll)(p)*(k-i)*i);
    printf("%lld\n",ans);
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
using namespace std;
const int NUM=1010;
const int MAX=1e6+10;
int col[NUM],row[NUM];
priority_queue<int> pq_row,pq_col;
int dp_row[MAX],dp_col[MAX];
int main()
{
    int n,m,k,p,x;
    scanf("%d%d%d%d",&n,&m,&k,&p);
    for (int i=1; i<=n; i++)
        for (int j=1; j<=m; j++)
        {
            scanf("%d",&x);
            row[i]+=x;
            col[j]+=x;
        }
    for (int i=1;i<=n;i++)
        pq_row.push(row[i]);
    for (int i=1;i<=m;i++)
        pq_col.push(col[i]);
    for (int i=1;i<=k;i++)
    {
        int x=pq_row.top();
        dp_row[i]=dp_row[i-1]+x;
        pq_row.pop();
        pq_row.push(x-p*m);
        int y=pq_col.top();
        pq_col.pop();
        pq_col.push(y-p*n);
        dp_col[i]=dp_col[i-1]+y;
    }
    int ans=0;
    for (int i=1;i<=k;i++)
        ans=max(ans,dp_row[i]+dp_col[k-i]-p*(k-i)*i);
    printf("%d\n",ans);
    return 0;
}


#include <bits/stdc++.h>

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

const double pi = 3.141592653589793;

#define xx          first
#define yy          second
#define mp          make_pair
#define intl        long long
#define filein      freopen("input.txt", "r", stdin)
#define fileout     freopen("output.txt", "w", stdout)
#define debug       printf("yes\n")
#define val_of(x)   cout << #x << " is " << x << "   "
#define what_is(x)  cout << #x << " is " << x << endl
#define pb          push_back
#define eb          emplace_back
#define pii         pair<int, int>
#define piii        pair<pii, int>

//typedef tree < intl , null_type ,less<intl>,rb_tree_tag,tree_order_statistics_node_update > ordered_set;

intl ara[1005][1005];
priority_queue<intl>pr, pc;
intl rr[1000005], cc[1000005];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    //filein;
    intl n, m, k, p;
    cin >> n >> m >> k >> p;
    intl row = 0, col = 0;
    for( int i = 0 ; i < n; i++ )
    {
        for( int j = 0; j < m; j++ )
        {
            cin >> ara[i][j];
        }
    }
    for( int i = 0 ; i < n; i++ )
    {
        intl sum = 0;
        for( int j = 0; j < m; j++ )
        {
            sum += ara[i][j];
        }
        pr.push(sum);
    }
    for( int i = 0 ; i < m; i++ )
    {
        intl sum = 0;
        for( int j = 0; j < n; j++ )
        {
            sum += ara[j][i];
        }
        pc.push(sum);
    }

    for( int i = 1; i <= k; i++ )
    {
        intl d;
        d = pr.top();
        pr.pop();
        rr[i] = d;
        d -= m*p;
        pr.push(d);

        d = pc.top();
        pc.pop();
        cc[i] = d;
        d -= n*p;
        pc.push(d);
        rr[i] += rr[i-1];
        cc[i] += cc[i-1];
    }
    intl ans = -1e18LL;
    for( intl i = 0; i <= k; i++ )
    {
        ans= max( ans, rr[i] + cc[k-i] - (k-i)*i*p );
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

const double pi = 3.141592653589793;

#define xx          first
#define yy          second
#define mp          make_pair
#define intl        long long
#define filein      freopen("input.txt", "r", stdin)
#define fileout     freopen("output.txt", "w", stdout)
#define debug       printf("yes\n")
#define val_of(x)   cout << #x << " is " << x << "   "
#define what_is(x)  cout << #x << " is " << x << endl
#define pb          push_back
#define eb          emplace_back
#define pii         pair<int, int>
#define piii        pair<pii, int>

//typedef tree < intl , null_type ,less<intl>,rb_tree_tag,tree_order_statistics_node_update > ordered_set;

intl ara[1005][1005];
priority_queue<intl>pr, pc;
intl rr[1000005], cc[1000005];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    //filein;
    int n, m, k, p;
    cin >> n >> m >> k >> p;
    intl row = 0, col = 0;
    for( int i = 0 ; i < n; i++ )
    {
        for( int j = 0; j < m; j++ )
        {
            cin >> ara[i][j];
        }
    }
    for( int i = 0 ; i < n; i++ )
    {
        intl sum = 0;
        for( int j = 0; j < m; j++ )
        {
            sum += ara[i][j];
        }
        pr.push(sum);
    }
    for( int i = 0 ; i < m; i++ )
    {
        intl sum = 0;
        for( int j = 0; j < n; j++ )
        {
            sum += ara[j][i];
        }
        pc.push(sum);
    }

    for( int i = 0; i < k; i++ )
    {
        intl d;
        d = pr.top();
        pr.pop();
        rr[i] = d;
        d -= m*p;
        pr.push(d);

        d = pc.top();
        pc.pop();
        cc[i] = d;
        d -= n*p;
        pc.push(d);
        if( i > 0 )
        {
            rr[i] += rr[i-1];
            cc[i] += cc[i-1];
        }

    }
    intl ans = rr[k-1];
    for( int i = 1; i < k; i++ )
    {
        ans= max( ans, rr[k-i-1] + cc[i-1] - (k-i)*i*p );
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

const double pi = 3.141592653589793;

#define xx          first
#define yy          second
#define mp          make_pair
#define intl        long long
#define filein      freopen("input.txt", "r", stdin)
#define fileout     freopen("output.txt", "w", stdout)
#define debug       printf("yes\n")
#define val_of(x)   cout << #x << " is " << x << "   "
#define what_is(x)  cout << #x << " is " << x << endl
#define pb          push_back
#define eb          emplace_back
#define pii         pair<int, int>
#define piii        pair<pii, int>

//typedef tree < intl , null_type ,less<intl>,rb_tree_tag,tree_order_statistics_node_update > ordered_set;

intl ara[1005][1005];
priority_queue<intl>pr, pc;
intl rr[1000005], cc[1000005];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    //filein;
    intl n, m, k, p;
    cin >> n >> m >> k >> p;
    intl row = 0, col = 0;
    for( int i = 0 ; i < n; i++ )
    {
        for( int j = 0; j < m; j++ )
        {
            cin >> ara[i][j];
        }
    }
    for( int i = 0 ; i < n; i++ )
    {
        intl sum = 0;
        for( int j = 0; j < m; j++ )
        {
            sum += ara[i][j];
        }
        pr.push(sum);
    }
    for( int i = 0 ; i < m; i++ )
    {
        intl sum = 0;
        for( int j = 0; j < n; j++ )
        {
            sum += ara[j][i];
        }
        pc.push(sum);
    }

    for( int i = 0; i < k; i++ )
    {
        intl d;
        d = pr.top();
        pr.pop();
        rr[i] = d;
        d -= m*p;
        pr.push(d);

        d = pc.top();
        pc.pop();
        cc[i] = d;
        d -= n*p;
        pc.push(d);
        if( i > 0 )
        {
            rr[i] += rr[i-1];
            cc[i] += cc[i-1];
        }

    }
    intl ans = rr[k-1];
    for( int i = 1; i < k; i++ )
    {
        ans= max( ans, rr[k-i-1] + cc[i-1] - (k-i)*i*p );
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

const double pi = 3.141592653589793;

#define xx          first
#define yy          second
#define mp          make_pair
#define intl        long long
#define filein      freopen("input.txt", "r", stdin)
#define fileout     freopen("output.txt", "w", stdout)
#define debug       printf("yes\n")
#define val_of(x)   cout << #x << " is " << x << "   "
#define what_is(x)  cout << #x << " is " << x << endl
#define pb          push_back
#define eb          emplace_back
#define pii         pair<int, int>
#define piii        pair<pii, int>

//typedef tree < intl , null_type ,less<intl>,rb_tree_tag,tree_order_statistics_node_update > ordered_set;

intl ara[1005][1005];
priority_queue<intl>pr, pc;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    //filein;
    int n, m, k, p;
    cin >> n >> m >> k >> p;
    intl row = 0, col = 0;
    for( int i = 0 ;i < n; i++ )
    {
        for( int j = 0; j < m; j++ )
        {
            cin >> ara[i][j];
        }
    }
    for( int i = 0 ;i < n; i++ )
    {
        intl sum = 0;
        for( int j = 0; j < m; j++ )
        {
            sum += ara[i][j];
        }
        pr.push(sum);
    }
    for( int i = 0 ;i < m; i++ )
    {
        intl sum = 0;
        for( int j = 0; j < n; j++ )
        {
            sum += ara[j][i];
        }
        pc.push(sum);
    }
    intl ans = 0;
    for( int i = 0; i < k; i++ )
    {
        intl d;
        if( pr.top() - row > pc.top() - col )
        {
            d = pr.top();
            //what_is(d);
            pr.pop();
            ans += d-row;
            d -= m*p;
            pr.push(d);
            col += p;
            //cout << "r";
        }
        else
        {
            d = pc.top();
            //what_is(d);
            pc.pop();
            ans += d-col;
            d -= n*p;
            pc.push(d);
            row += p;
            //cout << "c";
        }

    }
    cout << ans << endl;
    return 0;
}