fun main(args:Array<String>):Unit {
    val n = readLine()!!.trim().toInt()
    val state = Array(n + 1){Array(n + 1){0}}
    for (i in 1 .. n) {
        readLine()!!.trim().split(' ').map(String::toInt).forEachIndexed { j, num -> state[i][j + 1] = num }
    }
    for (y in 1 .. n) for (x in 1 .. n) state[y][x] += state[y - 1][x]
    var max = Int.MIN_VALUE
    for (upper in 0 until n - 1){
        for (bottom in upper + 2 .. n){//上がupper + 1、下がbottomである枠の最大値
            var current = 0
            for (x in 1 .. n){
                if (max < state[bottom][x] - state[upper][x]) max = state[bottom][x] - state[upper][x]
                current += state[bottom][x] - state[upper][x] - state[bottom - 1][x - 1] + state[upper + 1][x - 1]
                if (current < state[bottom][x] - state[upper][x] + state[bottom][x - 1] - state[upper][x - 1])
                    current = state[bottom][x] - state[upper][x] + state[bottom][x-  1] - state[upper][x - 1]
                if (max < current) {
                    max = current
                }
            }
        }
    }
    for (y in (1 .. n).reversed()) for (x in 1 .. n) state[y][x] -= state[y - 1][x]
    for (y in 1 .. n) for (x in 1 .. n) state[y][x] += state[y][x - 1]
    for (y in 1 .. n){
        var minLeft = state[y][1]
        var maxRight = state[y][1]
        for (x in 1 .. n){
            if (minLeft < state[y][x]) minLeft = state[y][x]
            if (maxRight > state[y][x]) maxRight = state[y][x]
            if (max < maxRight - minLeft) {
                max = maxRight - minLeft
            }
        }
    }
    println(max)
}
