#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int a[n][n];
    int maxEl = -2000;
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            cin >> a[i][j];
            maxEl = max(maxEl, a[i][j]);
        }
    }

    int row[n+1][n+1];
    int col[n+1][n+1];

    for(int i = 0; i< n+1;i++){
        row[0][i] = 0;
    }
    for(int i = 1; i < n + 1; i++){
        row[i][0] = 0;
        for(int j = 0; j < n; j++){
            row[i][j+1] = row[i][j] + a[i-1][j];
        }
    }

    for(int i = 0; i< n+1;i++){
        col[i][0] = 0;
    }
    for(int j = 1; j < n + 1; j++){
        col[0][j] = 0;
        for(int i = 0; i< n; i++){
            col[i+1][j] = col[i][j] + a[i][j-1];
        }
    }
 /*for(int i = 0; i <= n; i++){
        for(int j = 0; j <= n; j++){
                cout << row[i][j] << " ";
        }
        cout << endl;
     }

      for(int i = 0; i <= n; i++){
        for(int j = 0; j <= n; j++){
                cout << col[i][j] << " ";
        }
        cout << endl;
     }*/

    int maxSum = -1000000000;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            for(int len = n + 1 - max(i,j); len > 1; len--){
                int srcX = j;
                int srcY = i;

                int secEndX = j + len - 1;
                int secEndY = i;

                int thirdEndX = j;
                int thirdEndY = i  + len - 1;

                int fourthEndX = j + len -1;
                int fourthEndY = i + len - 1;
                //cout <<"X "<< srcX << " " << secEndX << " " << thirdEndX << " " << fourthEndX << endl;
                //cout <<"Y "<< srcY << " " << secEndY << " " << thirdEndY << " " << fourthEndY << endl;
                int sum = 0;
                //src i third end edna kolona
                int leftCol = col[thirdEndY][thirdEndX] - col[srcY-1][srcX];
                //src i secEnd edin red
                int upperRow = row[secEndY][secEndX] - row[srcY][srcX - 1];
                //secEnd i fourthEnd edna kolona
                int rightCol =  col[fourthEndY][fourthEndX] - col[secEndY - 1][secEndX];
                //thirdEnd i fourthEnd edin red
                int downRow = row[fourthEndY][fourthEndX] - row[thirdEndY][thirdEndX - 1];
               // cout << leftCol << " " << upperRow << " " << rightCol << " " << downRow << endl;
                sum = leftCol + rightCol + upperRow + downRow;
                sum -= a[srcY-1][srcX-1];
                sum -= a[secEndY-1][secEndX-1];
                sum -= a[thirdEndY-1][thirdEndX-1];
                sum -= a[fourthEndY-1][fourthEndX-1];
                maxSum = max(maxSum, sum);
               // cout << sum << endl;
            }
        }
    }


    cout << max(maxSum,maxEl) << endl;
    return 0;
}