/*
1282:最大子矩阵
http://ybt.ssoier.cn:8088/problem_show.php?pid=1282
P2331 [SCOI2005]最大子矩阵
https://www.luogu.org/problemnew/show/P2331
*/
#include <iostream>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
int a[201][201],sum[201][201];
int temp[200+1];
int n;
void solve()
{
int i,j,k,max=-INT_MAX,sumall;
for(i=0;i<=n;i++)
for(j=i+1;j<=n;j++) //从i行到j行
{
for(k=1;k<=n;k++) //该循环求出i到j行第k列的和
{
temp[k]=sum[j][k]-sum[i][k];
cout<<"i1="<<i<<" j="<<j<<" k="<<k<<" temp["<<k<<"]="<<temp[k]<<endl;
}
cout<<endl;
//cout<<"********************************************"<<endl;
sumall=0;
for(k=1;k<=n;k++) //与最大子序列和一样,找到最大值
{
sumall+=temp[k];
if(sumall>max) //记录最大值
max=sumall;
if(sumall<0)
sumall=0;
}
cout<<"i2="<<i<<" max1="<<max<<endl;
cout<<"????????????????????????????????"<<endl<<endl;
}
cout<<max<<endl;
}
void init()
{
int i,j;
cin>>n;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
cin>>a[i][j];
//显示输入的矩阵
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
cout<<a[i][j]<<" ";
cout<<endl;
}
cout<<"------------------------"<<endl;
for(i=1;i<=n;i++) // sum[i,j]表示矩阵第j列前i个元素的和,
for(j=1;j<=n;j++)
sum[i][j]=sum[i-1][j]+a[i][j];//压缩数据
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
cout<<sum[i][j]<<" ";
cout<<endl;
}
}
int main()
{
freopen("Matrix2d.in","r",stdin);
freopen("Matrix2d.out","w",stdout);
init();
solve();
return 0;
}