program D; var f:text; i,j,n,m:longint; mas:array[1..1000,1..1000] of int64; sum:int64; flag:array[1..1000] of 0..1; a:array[1..1000] of integer; procedure Lich(pos:longint); var ii:longint; begin if pos>n then begin sum:=0; for ii:=1 to n do sum:=sum+mas[a[ii],ii]; writeln(sum); end else begin for ii:=1 to n do if (flag[ii]=0) then begin a[pos]:=ii; flag[ii]:=1; Lich(pos+1); flag[ii]:=0; end; end; end; {_________________________________} begin assign(f,'legacy.in'); reset(f); readln(f,n,m); for i:=1 to n do for j:=1 to n do read(f,mas[i,j]); close(f); assign(f,'legacy.out'); Lich(1); rewrite(f); close(f); end.