=================================================================
prim:增加源点。
================
var
n:longint;
v:array[0..301]of longint;
cost:array[0..301,0..301]of longint;
l_cost:array[0..301]of longint;
f_bo:array[0..301]of boolean;
procedure init;
begin
assign(input,'newstart.in');
assign(output,'newstart.out');
reset(input); rewrite(output);
end;
procedure terminate;
begin
close(input); close(output);
halt;
end;
procedure main;
var
i,j,i1:longint;
n_cost:longint;
min,k:longint;
ans:longint;
begin
readln(n);
for i:=1 to n do read(v[i]);
for i:=1 to n do
for j:=1 to n do
read(cost[i,j]);
for i:=1 to n do
begin
cost[0,i]:=v[i];
cost[i,0]:=v[i];
end;
ans:=maxlongint;
for i:=1 to n do
begin
fillchar(l_cost,sizeof(l_cost),$7);
for j:=1 to n do
if i<>j then l_cost[j]:=cost[i,j]; {到i所在集合的距离}
for j:=1 to n do
if l_cost[j]>v[j] then l_cost[j]:=v[j]; {维护出j号单独修电机的费用}
fillchar(f_bo,sizeof(f_bo),true);
f_bo[i]:=false;
n_cost:=cost[0,i];
{==========================chushihua}
for j:=1 to n-1 do {加入n-1条边,就可以连完所有点}
begin
min:=maxlongint;
for i1:=1 to n do
if (f_bo[i1])and(min>l_cost[i1]) then
begin
min:=l_cost[i1];
k:=i1;
end;
n_cost:=n_cost+min;
f_bo[k]:=false;
for i1:=1 to n do
if l_cost[i1]>cost[k,i1] then
l_cost[i1]:=cost[k,i1];
end;
if ans>n_cost then ans:=n_cost;
end;
writeln(ans);
end;
begin
init;
main;
terminate;
end.