Program cgt;
var a:array[1..100,1..100]of integer;
max,min,s,i,j,n,x1,y1,x2,y2:integer;
begin
read(N);
for i:=1 to n do
for j:=1 to n do
read(a[i,j]);
max:=a[1,1];
min:=a[1,1];
for i:=1 to n do
begin
for j:=1 to n do
begin
if(i=j)and(a[i,j]>=max)then begin
max:=a[i,j];
x1:=i;
y1:=j;
end;
if(i=j)and(a[i,j]<=min)then begin<br>min:=a[i,j];
x2:=i;
y2:=j;
end;
end;
end;
s:=x1+x2+y1+y2;
writeln(s);
end.