1 /**************************************************************
2 Problem: 1177
3 User: Tunix
4 Language: C++
5 Result: Accepted
6 Time:6088 ms
7 Memory:62028 kb
8 ****************************************************************/
9
10 //BZOJ 1177
11 #include<vector>
12 #include<cstdio>
13 #include<cstring>
14 #include<cstdlib>
15 #include<iostream>
16 #include<algorithm>
17 #define rep(i,n) for(int i=0;i<n;++i)
18 #define F(i,j,n) for(int i=j;i<=n;++i)
19 #define D(i,j,n) for(int i=j;i>=n;--i)
20 #define pb push_back
21 using namespace std;
22 inline int getint(){
23 int v=0,sign=1; char ch=getchar();
24 while(ch<‘0‘||ch>‘9‘){ if (ch==‘-‘) sign=-1; ch=getchar();}
25 while(ch>=‘0‘&&ch<=‘9‘){ v=v*10+ch-‘0‘; ch=getchar();}
26 return v*sign;
27 }
28 const int N=1610,INF=~0u>>2;
29 typedef long long LL;
30 /******************tamplate*********************/
31 int n,m,k;
32 typedef int Matrix[N][N];
33 Matrix a,b,c,d,s,t;
34 int ans;
35
36 int main(){
37 #ifndef ONLINE_JUDGE
38 freopen("1177.in","r",stdin);
39 freopen("1177.out","w",stdout);
40 #endif
41 n=getint(); m=getint(); k=getint();
42 int x;
43 F(i,1,n) F(j,1,m){
44 scanf("%d",&x);
45 t[i][j]=t[i-1][j]+t[i][j-1]-t[i-1][j-1]+x;
46 }
47 F(i,k,n) F(j,k,m) s[i][j]=t[i][j]-t[i-k][j]-t[i][j-k]+t[i-k][j-k];
48
49 F(i,k,n) F(j,k,m) a[i][j]=max(s[i][j],max(a[i-1][j],a[i][j-1]));
50 F(i,k,n) D(j,m,k) b[i][j]=max(s[i][j],max(b[i-1][j],b[i][j+1]));
51 D(i,n,k) F(j,k,m) c[i][j]=max(s[i][j],max(c[i+1][j],c[i][j-1]));
52 D(i,n,k) D(j,m,k) d[i][j]=max(s[i][j],max(d[i+1][j],d[i][j+1]));
53
54 F(i,k,n-k) F(j,k,m-k) ans=max(ans,a[i][j]+b[i][j+k]+c[i+k][m]);
55 F(i,k,n-k) F(j,k,m-k) ans=max(ans,a[i][j]+c[i+k][j]+b[n][j+k]);
56 F(i,k,n-k) F(j,k,m-k) ans=max(ans,a[i][m]+c[i+k][j]+d[i+k][j+k]);
57 F(i,k,n-k) F(j,k,m-k) ans=max(ans,a[n][j]+b[i][j+k]+d[i+k][j+k]);
58 F(i,k,n) F(j,k+k,m-k) ans=max(ans,s[i][j]+a[n][j-k]+b[n][j+k]);
59 F(i,k+k,n-k) F(j,k,m) ans=max(ans,s[i][j]+a[i-k][m]+c[i+k][m]);
60 printf("%d\n",ans);
61 return 0;
62 }