#include<bits/stdc++.h>
const int maxn=600;
inline const void read(int &a)
{
a=0;int b=1;
char c=getchar();
while(c<'0'||c>'9'){if(c=='-')b=-1;c=getchar();}
while(c>='0'&&c<='9')
{
a=(a<<1)+(a<<3)+c-'0';
c=getchar();
}
a*=b;
}
inline const void write(int a)
{
if(a<0){putchar('-');a=-a;}
if(a>9)write(a/10);
putchar(a%10+'0');
}
inline const int max(int a,int b)
{
if(a>b)return a;
else return b;
}
int n,m,p,s[maxn][maxn],a[maxn][maxn],ans=0;
inline const int get(int xa,int ya,int xb,int yb)
{
return s[xa][ya]-s[xa][yb]-s[xb][ya]+s[xb][yb];
}
int main()
{
read(n);read(m);read(p);
memset(a,0,sizeof(a));
memset(s,0,sizeof(s));
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)read(a[i][j]);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
if(p-a[i][j]>0)
{
int k=a[i][j];
a[i][j]=p;
memset(s,0,sizeof(s));
for(int k=1;k<=n;k++)
for(int l=1;l<=m;l++)s[k][l]=s[k-1][l]+s[k][l-1]-s[k-1][l-1]+a[k][l];
for(int k=0;k<=n;k++)
for(int l=0;l<=m;l++)
for(int r=k;r<=n;r++)
for(int q=l;q<=m;q++)ans=max(ans,get(r,q,k,l));
a[i][j]=k;
}
}
write(ans);
return 0;
}