const n=100; var str: array[1..n] of string; f1, f2: text; i, m: word; function check(strs:array of string; nn: word): boolean; {parbaude, vai visi burti ir vienadi} 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; procedure sort_first(var strf: array of string; mm: word); {sorings pec pirma burta} Var fl: boolean; temp: string; j: word; begin repeat fl:=true; 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; 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 readln(F1, str[i]); inc(i); end; m:=i; if check(str, i) then begin for i:=m downto 1 do writeln(F1, str[i]); end else sort_first(str, m); Close (f1); Close (f2); end.