/*
TASK: tre
LANG: C++
*/
#include <iostream>
using namespace std;
struct pole{int x,y,time;long long cena;long double koef;};
long long i,j,n,k,l,d,pol,cena,cena1;
pole poleta[10010];
int matrix[10010][110];

int main()
{
scanf("%d %d %d %d",&n,&k,&l,&d);	
for (i=1;i<=d;i++)
 for (j=1;j<=l;j++) scanf("%d",&matrix[j][i]);
pol=-1;
for (j=1;j<=l;j++) 
 {cena1=0;
  for (i=1;i<=d;i++)
    {cena1+=matrix[j][i];
     if (matrix[j][i]>0) 
	    {pol++;
	     poleta[pol].x=j;
	     poleta[pol].y=i;
	     poleta[pol].time=i;
	     poleta[pol].cena=matrix[j][i];
	     poleta[pol].koef=cena1/(long double)i;
		}
	}	
  }
cena=0;
while(1)
{int get=-1;
 long double maxx=0;
  for(i=0;i<pol;i++) if (poleta[i].time<=k) if (poleta[i].koef>maxx) {maxx=poleta[i].koef;get=i;}
 if (get==-1) break;
 cena+=poleta[get].cena;
 k-=poleta[get].time;
 if (k<=0) break;
 for(i=0;i<pol;i++) 
   if (poleta[i].x==poleta[get].x)
    {
     if (poleta[i].y<poleta[get].y) {poleta[i]=poleta[pol-1];pol--;}
     if (poleta[i].y>poleta[get].y) 
	   {cena1=0;
		for (j=poleta[get].y+1;j<=d;j++)
		if (matrix[i][j]>0) 
	     {pol++;
	      poleta[pol].time=j-poleta[get].y;
	      poleta[pol].cena=matrix[i][j];
	      poleta[pol].koef=cena1/(long double)j;
	    }
	   } 
	} 
 poleta[get]=poleta[pol-1];pol--;
}

cout<<cena<<endl;
return 0;
}
