const n = 5;
m = 8;
var a:array [1..n,1..8] of char;
b:array [1..5] of char;
i,j,k,l,s,c,cnt:integer;
tmp:char;
begin
randomize;
for i:=1 to n do
begin
for j:=1 to m do
begin
a[i,j]:=chr(random(9)+65);
k:=random(2);
if (k=1) then a[i,j]:=chr(ord(a[i,j])-16);
write (a[i,j]:3);
end;
writeln;
end;
cnt:=0;
for i:=1 to m do
begin
l:=0;
s:=0;
inc(cnt);
for c:=1 to m do
if (ord(a[cnt,c])>=49) and (ord(a[cnt,c])<=57) then s:=s+(ord(a[cnt,c])-48);</em>
for j:=1 to n do
begin
if (ord(a[j,i])>=65) and (ord(a[j,i])<=73) then</em>
begin
inc(l);
b[l]:=a[j,i];
end;
end;
for c:=1 to l-1 do
if b[c+1]>b[c] then
begin
tmp:=b[c];
b[c]:=b[c+1];
b[c+1]:=tmp;
end;
for c:=1 to l do write (b[c],' ');
writeln ('SUMMA: ',s);
end;
end.