@matrix = Array.new(@n = $<.gets.to_i) {$<.gets.split.map(&:to_i)}
@max = -Float::INFINITY
@memo = {}

def try(x, y, w, h)
  return 0 if x >= @n or y >= @n or w <= 0 or h <= 0
  key = "#{x},#{y},#{w},#{h}"
  return @memo[key] if @memo[key]
  
  if h == 1 and w == 1
    num = @matrix[y][x]
  else
    try(x, y + 1, w, h - 1)
    try(x, y    , w, h - 1)
    try(x + 1, y, w - 1, h)
    try(x    , y, w - 1, h)
    num = try(x, y, 1, 1) + try(x + 1, y, w - 1, 1) +
          try(x, y + 1, 1, h - 1) + try(x + 1, y + 1, w - 1, h - 1)
  end
  @max = num if num > @max
  @memo[key] = num
end

try(0, 0, @n, @n)
puts @max
