/*
TASK: tre
LANG: C++
*/
#include <iostream>
using namespace std;
struct pole{int x,y,time,del;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=cena1;
	     poleta[pol].koef=cena1/(long double)i;
	     poleta[pol].del=0;
		}
	}	
  }
pol++;
cena=0;
 
while(1)
{int get=-1;
 long double maxx=0;
/*  for(i=0;i<pol;i++)cout<<"x="<<poleta[i].x<<" y="<<poleta[i].y<<" time="<<
       poleta[i].time<<" cena="<<poleta[i].cena<<" koef="<<poleta[i].koef<<endl;
 cout<<"ost vreme "<<k<<endl; */
  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].del=1;
     if (poleta[i].y>poleta[get].y) 
	   {cena1=0;
		for (j=poleta[get].y+1;j<=poleta[i].y;j++) cena1+=matrix[poleta[get].x][j];
		  poleta[i].time=poleta[i].y-poleta[get].y;
		  poleta[i].cena-=poleta[get].cena;
	      poleta[i].koef=cena1/(long double)(poleta[i].y-poleta[get].y);
	
	    }
	    
	} 
poleta[get].del=1;	
 for(i=0;i<pol;i++) if (poleta[i].del==1) poleta[i]=poleta[--pol];
/* 
 for(i=0;i<pol;i++)cout<<"x="<<poleta[i].x<<" y="<<poleta[i].y<<" time="<<
       poleta[i].time<<" cena="<<poleta[i].cena<<" koef="<<poleta[i].koef<<endl;
 cout<<"ost vreme "<<k<<endl;     */ 
}

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