program Search2Dimensional;
Var
Arry : Array[1..5,1..5] of Integer;
Temp,TempM : Integer;
X,Y,mit,mat : integer;
Begin
Temp := -maxint;
TempM :=maxint;
mit := 0;
mat := 0;
For X:= 1 to 5 do
For Y:= 1 to 5 do
Read(Arry[X,Y]);
For X:= 1 to 5 do
For Y:= 1 to 5 do
Begin
If Arry[X,Y] > Temp then Temp:= Arry[X,Y];
If Arry[X,Y] < TempM then TempM:= Arry[X,Y];
End;
For X:= 1 to 5 do
For Y:= 1 to 5 do
Begin
If Arry[X,Y] = Temp then mat := mat + 1;
If Arry[X,Y] = TempM then mit := mit+1;
End;
Writeln('Maximum is ',Temp,' and occurs ',mat,' times.');
Writeln('Minimum is ',TempM,' and occurs ',mit,' times.');
End.