1. const fi='';
2. nmax=999999;
3. type data=longint;
4. var
5. f:text;
6. kq,S,A,tmp:string;
7. n,sl,i:data;
8. dd:array[1..6] of boolean;
9.
10. procedure sort(l,r: longint);
11. var
12. i,j: longint;
13. y,x:char;
14. begin
15. i:=l;
16. j:=r;
17. x:=s[(l+r) div 2];
18. repeat
19. while s[i]<x do
20. inc(i);
21. while x<s[j] do
22. dec(j);
23. if not(i>j) then
24. begin
25. y:=s[i];
26. s[i]:=s[j];
27. s[j]:=y;
28. inc(i);
29. j:=j-1;
30. end;
31. until i>j;
32. if l<j then
33. sort(l,j);
34. if i<r then
35. sort(i,r);
36. end;
37.
38.
39. procedure try;
40. var i:data;
41. begin
42. if sl=n then
43. begin
44. if kq>a then
45. begin
46. writeln(kq);
47. halt;
48. end;
49.
50. end
51. else
52. for i:=1 to n do
53. if not dd[i] then
54. begin
55. inc(sl);
56. dd[i]:=true;
57. kq[sl]:=s[i];
58. try;
59. dd[i]:=false;
60. dec(sl);
61. end;
62. end;
63.
64. begin
65. assign(f,fi); reset(f);
67. close(f);
68. n:=length(s);
69. a:=s;
70. kq:=s;
71. sort(1,n);
72. for i:=n downto 1 do
73.
74. tmp:=tmp+s[i];
75. if tmp=a then
76. begin
77. writeln(0);
78. halt;
79. end;
80. fillchar(dd,sizeof(dd),false);
81. sl:=0;
82.
83. try;
84. writeln(0);
85. end.
Success #stdin #stdout 0s 4352KB
stdin
156
stdout
165