program xqz; const maxn=1005; maxm=maxn*maxn+2*maxn; oo=1 shl 30; var i,j,k,m,n,e,rr,ss,tt,de,b,p:longint; edge,a,d,ne,shift,pre:array[0..maxn] of longint; point,next,c:array[-maxm..maxm] of longint; ans:int64; ok:boolean; procedure add(ss,tt,k,k2:longint); begin inc(e); point[e]:=tt; next[e]:=edge[ss]; edge[ss]:=e; c[e]:=k; point[-e]:=ss; next[-e]:=edge[tt]; edge[tt]:=-e; c[-e]:=k2; end; function bfs:boolean; begin fillchar(d[1],tt*4,$ff); fillchar(ne[1],tt*4,0); d[ss]:=0; rr:=ss; i:=ss; while i<>0 do begin b:=edge[i]; while b<>0 do begin p:=point[b]; if (c[b]>0)and(d[p]=-1) then begin d[p]:=d[i]+1; ne[rr]:=p; rr:=p; if p=tt then exit(true); end; b:=next[b]; end; j:=ne[i]; ne[i]:=0; i:=j; end; bfs:=false; end; procedure improve; var i,de:longint; begin i:=pre[tt]; de:=oo; while i<>0 do begin if c[shift[i]]<=de then begin de:=c[shift[i]]; k:=i; end; i:=pre[i]; end; i:=pre[tt]; dec(ans,de); while i<>0 do begin dec(c[shift[i]],de); inc(c[-shift[i]],de); i:=pre[i]; end; end; procedure dfs; begin for i:=1 to tt do shift[i]:=edge[i]; pre[ss]:=0; i:=ss; while i<>0 do begin b:=shift[i]; ok:=false; while b<>0 do begin p:=point[b]; if (d[p]=d[i]+1)and(c[b]>0) then begin shift[i]:=b; pre[p]:=i; ok:=true; i:=p; if p=tt then begin improve; i:=k; end; break; end; b:=next[b]; end; if not ok then begin d[i]:=-1; i:=pre[i]; end; end; end; begin assign(input,'employ.in'); reset(input); assign(output,'employ.out'); rewrite(output); read(n); ss:=n+1; tt:=ss+1; for i:=1 to n do begin read(k); add(i,tt,k,0); end; for i:=1 to n do begin for j:=1 to i do read(k); for j:=i+1 to n do begin read(k); ans:=ans+2*k; inc(a[i],k); inc(a[j],k); if k>0 then add(i,j,2*k,2*k); end; end; for i:=1 to n do add(ss,i,a[i],0); while bfs do dfs; writeln(ans); close(input); close(output); end.