#include using namespace std; using ll = long long; const ll linf = 1e18; bool chmin(auto &a, auto b){ return a > b ? a = b, 1 : 0; } bool chmax(auto &a, auto b){ return a < b ? a = b, 1 : 0; } int main(){ cin.tie(0)->sync_with_stdio(0); int n, m, c, x; cin >> n >> m >> c >> x; vector a(n,vector(m)); for (int i = 0; i < n; i++){ for (int j = 0; j < m; j++){ cin >> a[i][j]; } } vector dp(m,vector(x+1,vector(2,-linf))); for (int j = 0; j < m; j++){ dp[j][0][0] = a[0][j]; dp[j][1][1] = a[0][j] - c; } for (int i = 1; i < n; i++){ vector ndp(m,vector(x+1,vector(2,-linf))); for (int j = 0; j < m; j++){ for (int t = 0; t <= x; t++){ for (int k = 0; k < m; k++){ if (j != k){ // 0 -> 0 chmax(ndp[k][t][0],min(dp[j][t][0],a[i][k])); // 0 -> 1 chmax(ndp[k][min(t+1,x)][1],min(dp[j][t][0],a[i][k]-c)); } else { // 1 -> 0 chmax(ndp[k][min(t+1,x)][0],min(dp[j][t][1],a[i][k]-c)); // 1 -> 1 chmax(ndp[k][min(t+1,x)][1],min(dp[j][t][1],a[i][k]-c)); } } } } swap(dp,ndp); } ll ans = -linf; for (int j = 0; j < m; j++){ chmax(ans,dp[j][x][0]); } cout << ans << '\n'; }