/*
TASK: tre
LANG: C++
*/
#include<stdio.h>
#include<algorithm>
using namespace std;
    int vh[10008][128],maxx,tn,n,k,l,d;
    int dp[10008],dp2[10008];
typedef struct data
{
    int etaj,pyt,st;
};
    data tre[1024];
bool cmp(data p1,data p2)
{
     return p1.pyt<p2.pyt;
}
int main()
{
    int i,j,a;
    data tmp;
    scanf("%d%d%d%d",&n,&k,&l,&d);
    for(i=1;i<=d;i++)
    for(j=1;j<=l;j++)
    {
      vh[i][j]=vh[i][j-1]+a;
      scanf("%d",&a);
      if(vh[i][j] && a)
      {
        tmp.etaj=j;
        tmp.pyt=i;
        tmp.st=vh[i][j];
        tre[tn++]=tmp;
      }
    }
    for(i=1;i<=k;i++)dp[k]=10000000;
    sort(tre,tre+tn,cmp);
    for(i=0;i<tn;i++)
    {
      for(j=0;j<=k;j++)
      if(j+tre[i].pyt<=k && dp[j+tre[i].pyt]<dp[j]+tre[i].st && dp2[j]!=tre[i].etaj)
      {
       dp[j+tre[i].pyt]=dp[j]+tre[i].st;
       dp2[j+tre[i].pyt]=tre[i].etaj;
       if(dp[j+tre[i].pyt]>maxx)maxx=dp[j+tre[i].pyt];
      }
      else
       if(j+tre[i].pyt<=k && dp[j+tre[i].pyt]==dp[j]+tre[i].st && dp2[j]!=tre[i].etaj)dp2[j+tre[i].pyt]=-1;
    }
    printf("%d\n",maxx);
return 0;
}

