var a,b:array[0..100,0..100] of longint;
n,m,i,j:longint;f:text;
procedure xuly;
var i,j,n1,m1,max:longint;
begin
for j:= 1 to m do
b[1,j]:=b[1 ,j-1]+a[1,j];
for i:= 2 to n do
b[i,1]:=a[i,1]+b[i-1,1];
for i:= 1 to m do
for j:= 1 to n do
if (i<>m) and (b[i,j-1]>=b[i-1,j]) then
b[i,j]:=a[i,j]+b[i,j-1]
else b[i,j]:=a[i,j]+b[i-1,j];
max:=b[m,1];
for i:= 2 to n do
if b[m,i]>max then
begin
max:=b[m,i];
n1:=m; m1:=i;
end;
writeln(max);
writeln(n1,'-------',m1);
{-----------------}
[B][COLOR="Red"]while (n1<>1) or (m1<>1) do
begin
write('(',n1,',',m1,')-->');
If b[n1,m1]=b[n1-1,m1]+A[n1,m1] then dec(n1)
Else
dec(m1);
end;[/COLOR][/B]
write('(1,1)');
writeln;
end;
begin
assign(f,'C:\kien.txt');
reset(f);
read(f,m,n);
for i:= 1 to m do
begin
for j:= 1 to n do
read(f,a[i,j]);
readln(f);
end;
fillchar(b,sizeof(b),0);
xuly;
for i:= 1 to m do
begin
for j:= 1 to n do
write(a[i,j]:4);
writeln;
end;
writeln;writeln;
for i:= 1 to m do
begin
for j:= 1 to n do
write(b[i,j]:4);
writeln;
end;
readln;
end.