program shuta;
var
a:array[1..80,1..80] of integer;
b,c:array[1..80] of integer;
i,j,n:integer;
s,z:longint;
procedure init;
begin
s:=0;
z:=0;
for i:=1 to n do
for j:=1 to i do read(a[i,j]);
end;
procedure search(cc,dd:integer);
var
k:integer;
begin
k:=dd-1;
while k<dd+1 do
begin
inc(k);
b[cc]:=a[cc,k];
s:=s+a[cc,k];
if cc=n then
begin
if s>z then
begin
z:=s;
for i:=1 to n do c[i]:=b[i];
end;
end
else
search(cc+1,k);
s:=s-a[cc,k];
end;
end;
begin
assign(input,'shuta.in');
reset(input);
assign(output,'shuta.out');
rewrite(output);
readln(n);
init;
search(1,1);
writeln;
writeln(z);
for i:=1 to n do write(c[i],' ');
close(input);
close(output);
end.