2 {$MINSTACKSIZE 4000000}
6 a
,b
,c
:array [0..100] of string;
7 pre
,plan
:array [0..5000000] of string;
9 function getstr
:string;
16 while (ch
<>#10) and (ch
<>#13) and (ch
<>' ') do
23 procedure trans(var a
,b
:string);
28 b
:=copy(a
,1,length(a
)-length(b
))+b
;
30 while length(a
)<12 do a
:=a
+'0';
31 for i
:=length(a
) downto 1 do
32 if a
[i
]='0' then a
[i
]:='9' else
38 while length(b
)<12 do b
:=b
+'9';
39 for i
:=length(b
) downto 1 do
40 if b
[i
]='9' then b
[i
]:='0' else
47 function cal(s
:string):string;
55 if (copy(a
[i
],1,length(s
))=s
) and (length(s
)<12) then exit
;
56 if (copy(b
[i
],1,length(s
))=s
) and (length(s
)<12) then exit
;
57 if (a
[i
]<s
) and (s
<b
[i
]) then exit(c
[i
]);
62 function build(prefix
:string):string;
64 child
:array ['0'..'9'] of string;
68 fillchar(child
,sizeof(child
),0);
69 if length(prefix
)>1 then
72 if build
<>'@' then exit
;
77 child
[i
]:=build(prefix
+i
);
78 if build
='' then build
:=child
[i
] else if build
<>child
[i
] then build
:='@';
80 if (build
='@') or (length(prefix
)=1) then
83 if (child
[i
]<>'@') and (child
[i
]<>'invalid') then
92 procedure swap(var x
,y
:string); inline;
102 procedure sort(l
,r
:longint);
112 while pre
[i
]<m
do inc(i
);
113 while pre
[j
]>m
do dec(j
);
117 swap(plan
[i
],plan
[j
]);
122 if l
<j
then sort(l
,j
);
123 if r
>i
then sort(i
,r
);
142 if ans
>1 then sort(1,ans
);
143 for i
:=1 to ans
do writeln(copy(pre
[i
],2,1000),' ',plan
[i
]);