Var a: array [1..100, 1..100] of real; sum: real; i, j, n: integer;
begin
read(n);
sum := 0;
for i := 1 to n do
for j := 1 to n do
begin
read(a[i, j]);
if i = j then sum := sum + a[i, j];
end;
for i := 1 to n do
begin
for j := 1 to n do
write(a[i, j], ' ');
writeln;
end;
writeln(sum);
end.