Var
A:Array[1..100] of Word;
N,Max_S,i,I_max:Byte;
Function Sum_of_figures(p:Word):Byte;
var
d:Word;
S,j:Byte;
begin
d:=10000;
S:=0;
For j:=1 to 5 do
begin
S:=S+(p div d);
p:=p mod d;
d:=d div 10;
end;
Sum_of_figures:=S;
end;
Begin
Randomize;
Write('N= ');
Readln(N);
Writeln;
Writeln('Initial array:');
For i:=1 to N do
begin
A[i]:=Random(65535);
Write(A[i]:8);
end;
Writeln;
Writeln;
Writeln('Sums of figures:');
Max_S:=0;
For i:=1 to N do
begin
Write(Sum_of_figures(A[i]):8);
If Sum_of_figures(A[i])>Max_S then
begin
Max_S:=Sum_of_figures(A[i]);
I_max:=i;
end;
end;
Writeln;
Writeln;
Writeln('Maximal sum of figures (',Max_S,') has the element N',I_max,' equal to ',A[I_max]);
Readln;
End.