const n=10; var str: array[1..n] of string; f1, f2: text; i, m: word; function check(const strs:array of string; nn: word): boolean; Var tr: boolean; k: word; begin tr:=true; for k:=1 to nn-1 do if(strs[k][1]<>strs[k-1][1]) then tr:=false; if tr then check:=true else check:=false; end; Function sort_first(var strf: array of string; mm: word):string; Var fl: boolean; temp: string; j: word; begin repeat fl:=false; for j:=0 to mm-2 do if(strf[j][1]>strf[j+1][1]) then begin temp:=strf[j]; strf[j]:=strf[j+1]; strf[j+1]:=temp; fl:=true; end; until not (fl); end; begin Assign (f1, 'pasts.in'); Assign (f2,'pasts.out'); Reset (f1); Rewrite (f2); i:=1; while not(EoF(F1)) do begin read(F1, str[i]); inc(i); end; m:=i; if check(str, i) then begin for i:=m downto 1 do write(F2, str[i]); end else sort_first(str, m); write (f2,str[i]); Close (f1); Close (f2); end.