#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,j,k) for (int i=j;i<=k;i++)
#define dep(i,j,k) for (int i=j;i>=k;i--)
#define M(a,b) memset(a,b,sizeof(a))
using namespace std;
int n,m,p,ans,minn,zuixiao[70][70][70][70];
int sum[70][70],num[70][70],tot;
int main(){
//freopen("puzzle.in","r",stdin);
// freopen("puzzle.out","w",stdout);
ans=-2e9;
scanf("%d%d%d",&n,&m,&p);
rep(i,1,n)
rep(j,1,m) scanf("%d",&num[i][j]);
rep(i,1,n)
rep(j,1,m) sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+num[i][j];
rep(i,1,n)
rep(j,1,m)
rep(k,i,n)
rep(l,j,m){
tot=sum[k][l]-sum[i-1][l]-sum[k][j-1]+sum[i-1][j-1];
minn=2e9;
rep(a,i,k)
rep(b,j,l) minn=min(minn,num[a][b]);
if(minn<p) tot=tot-minn+p;
ans=max(ans,tot);
}
printf("%d",ans);
return 0;
}