
import std.stdio, std.conv, std.string, std.algorithm, std.array, std.range;

void dump(int[][] arr) {
  for(int i = 0; i < arr.length; i++)
    for(int j = 0; j < arr[i].length; j++)
      writef("%2d%s", arr[i][j], j == arr[i].length - 1 ? "\n" : " ");
}

void main() {
  int n = readln.chomp.to!(int);
  int ans = int.min;
  int[][] arr;
  int[][] dp = new int[][](n + 1, n + 1);
  for(int i = 0; i < n; i++)
    arr ~= (readln.chomp.split(" ").map!(to!(int)).array) ~ [0];
  arr ~= repeat(0).take(n + 1).array;
  for(int i = n - 1; i >= 0; i--) {
    for (int j = n - 1; j >= 0; j--) {
      arr[i][j] +=
        max(arr[i + 1][j], arr[i][j + 1], arr[i + 1][j + 1]);
      if (ans < arr[i][j]) ans = arr[i][j];
    }
  }
  dump(arr);
  writeln(arr);
  writeln(ans);
}