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

int matrix[10010][110];
qu q[10010];
void clear()
{
	pol=0;
}

void gen(int k)
{
int i,j,cena1,get;
	
if (q[k].from==0) {pol=pol_;
 			for(i=0;i<pol;i++)
 			 {poleta[i].x=poleta_[i].x;
	     	  poleta[i].y=poleta_[i].y;
     	      poleta[i].time=poleta_[i].time;
	          poleta[i].cena=poleta_[i].cena;
	          poleta[i].del=poleta_[i].del;
		      }
		    return;  
    		}
gen(q[k].from);
for(i=0;i<pol;i++) if (q[k].x==poleta[i].x&&q[k].y==poleta[i].y){get=i;break;};

//cout<<k<<" from "<<i<<"get "<<get<<endl;
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[get].del=1;	
for(i=0;i<pol;i++) if (poleta[i].del==1) poleta[i]=poleta[--pol];
return;
    		
}
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_].del=0;
		}
	}	
  }
pol_++;
 
q[0].cena=0;
q[0].from=0; 
q[0].x=-1;
q[0].y=-1;
for (i=1;i<=k;i++)
	{q[i].cena=0;
	 q[i].from=-1;
	 q[i].x=-1;
	 q[i].y=-1;
	}
for (i=1;i<=k;i++)
 for (j=0;j<i;j++)
  { clear();
	gen(j);
	int i1;
/*	for(i1=0;i1<pol;i1++)cout<<"x="<<poleta[i1].x<<" y="<<poleta[i1].y<<" time="<<
       poleta[i1].time<<" cena="<<poleta[i1].cena<<endl;
    cout<<i<<" "<<j<<endl;   */
	long long maxx=0,get=-1;
	for(i1=0;i1<pol;i1++) if (poleta[i1].time==(i-j)) if (poleta[i1].cena>maxx) {maxx=poleta[i1].cena;get=i1;}
//	cout<<"get "<<get<<endl;
	if (get>-1){
		if (q[i].from=-1) 
		  {
			q[i].cena=poleta[get].cena;
			q[i].x=poleta[get].x;
			q[i].y=poleta[get].y;
			q[i].from=j;
		} 
		else 
	if (q[i].cena<(q[q[i].from].cena+poleta[get].cena))
	  {
			q[i].cena=q[q[i].from].cena+poleta[get].cena;
			q[i].x=poleta[get].x;
			q[i].y=poleta[get].y;
			q[i].from=j;			
	  }
	}	
//	cout<<"["<<i<<"] cena="<<q[i].cena<<" from="<<q[i].from<<" x="<<q[i].x<<" y="<<q[i].y<<endl;
  }	
  long long maxx1=0;
  for (i=0;i<=k;i++) if (q[i].cena>maxx1) maxx1=q[i].cena;
  cout<<maxx1<<endl;
 return 0;
}
