program task_d; {$APPTYPE CONSOLE} uses SysUtils; var n,m,i,j,ans,max:integer; a:array[0..1001,0..1001] of longint; p:array[1..1000] of integer; b:boolean; f:text; function fmax(a,b:longint):longint; begin if (a>=b) then fmax:=a else fmax:=b; end; procedure swap(var a,b:longint); var c:longint; begin c:=a; a:=b; b:=c; end; begin assign(f,'legacy.in'); reset(f); readln(f,n,m); for i:=1 to n do begin for j:=1 to n do read(f,a[i,j]); readln(f); end; close(f); max:=0; ans:=0; for i:=1 to n do begin ans:=ans+a[i,i]; p[i]:=i; end; while (1=1) do begin b:=true; for i:=1 to n-1 do for j:=i+1 to n do begin if ((a[i,p[j]]+a[j,p[i]])>(a[i,p[i]]+a[j,p[j]])) then begin ans:=ans-(a[i,p[i]]+a[j,p[j]])+(a[i,p[j]]+a[j,p[i]]); swap(p[i],p[j]); end; end; if (b) then break; end; assign(f,'legacy.out'); rewrite(f); writeln(f,ans); close(f); { TODO -oUser -cConsole Main : Insert code here } end.