#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define MAXN 55 #define INF 1000000000 int N; int A[MAXN][MAXN]; int B[MAXN][MAXN]; int calcSum(int a, int b, int c, int d) { int ret = B[c][d]; ret -= B[a - 1][d]; ret -= B[c][b - 1]; ret += B[a - 1][b - 1]; return ret; } int main() { // freopen("date.in", "r", stdin); // freopen("date.out","w", stdout); scanf("%d", &N); for(int i = 1; i <= N; i++) for(int j = 1; j <= N; j++) scanf("%d", &A[i][j]); for(int i = 1; i <= N; i++) for(int j = 1; j <= N; j++) { B[i][j] = A[i][j] + B[i - 1][j] + B[i][j - 1] - B[i - 1][j - 1]; } int ans = -INF; for(int i = 1; i <= N; i++) for(int j = 1; j <= N; j++) for(int i2 = i; i2 <= N; i2++) for(int j2 = j; j2 <= N; j2++) { int sum = calcSum(i, j, i2, j2); if(i2 > i + 1 && j2 > j + 1) sum -= calcSum(i + 1, j + 1, i2 - 1, j2 - 1); ans = max(ans, sum); } printf("%d\n", ans); return 0; }