/**
 * CPSC490: Challenge 3 solution.
 *
 * Suppose the input contains n, followed by
 * n rows of n integers - the input matrix.
 * For example,
 * 4
 *  1  2 -2  4
 * -1  4 -2 -1
 *  5 -1  1  2
 * -2 -3 -4  1
 *
 * First, we will read this into data[][].
 * Then, we will "integrate" each row - run
 * the algorithm from Challenge 1. This will
 * convert rows into running sums so that
 * the sum of the elements between indices
 * L (inclusive) and R (exclusive) is
 * data[row][R] - data[row][L].
 *
 * Finally, we will try all choices for the
 * left and right boundaries of the maximum
 * submatrix and run the algorithm from
 * Challenge 2 to find a range with the
 * maximal sum.
 *
 * The algorithm will print 12 for the
 * example above.
 **/
#include <iostream>
#include <algorithm>
using namespace std;

#define N 1024

int data[N][N];

int main()
{
    int n;
    cin >> n;
        
    // read data
    for( int i = 0; i < n; i++ ) 
    { 
        data[i][0] = 0; 
        for( int j = 0; j < n; j++ ) 
            cin >> data[i][j + 1]; 
    }

    // "integrate" each row
    for( int i = 0; i < n; i++ ) 
    for( int j = 0; j < n; j++ ) 
        data[i][j + 1] += data[i][j];

    // this will keep the best sum found so far
    int best = INT_MIN;

    // pick the left and right boundaries
    for( int l = 0;     l < n;  l++ ) 
    for( int r = l + 1; r <= n; r++ )
    {
        // solve the one-dimensional problem
        int sum = INT_MIN;
        for( int i = 0; i < n; i++ )
        {
            sum = max( sum, 0 );
            sum += data[i][r] - data[i][l];
            best = max( best, sum );
        }
    }

    // print the answer
    cout << best << endl;
    
    return 0;
}
