Задачі
K-equivalence
K-equivalence
Consider a set \textit{K }of positive integers.
Let \textit{p }and \textit{q }be two non-zero decimal digits. Call them \textit{K}-equivalent if the following condition applies:
For every \textit{n 2 K}, if you replace one digit \textit{p }with \textit{q }or one digit \textit{q }with \textit{p }in the decimal notation of \textit{n }then the resulting number will be an element of \textit{K}.
For example, when \textit{K }is the set of integers divisible by 3, the digits 1, 4, and 7 are \textit{K}-equivalent. Indeed, replacing a 1 with a 4 in the decimal notation of a number never changes its divisibility by 3.
It can be seen that \textit{K}-equivalence is an equivalence relation (it is reflexive, symmetric and transitive).
You are given a finite set \textit{K }in form of a union of disjoint finite intervals of positive integers.
Your task is to find the equivalence classes of digits 1 to 9.
\InputFile
The first line contains \textit{n}, the number of intervals composing the set \textit{K }(1 ≤\textit{ n }≤\textit{ }10 000). Each of the next \textit{n }lines contains two positive integers \textit{a_i }and \textit{b_i }that describe the interval \[\textit{a_i, b_i}\] (i. e. the set of positive integers between \textit{a_i }and \textit{b_i}, inclusive), where 1 ≤\textit{ a_i }≤\textit{ b_i }≤\textit{ }10^18. Also, for \textit{i }\[2..\textit{n}\]: \textit{a_i ¸ b_\{i--\}}_1 + 2.
\OutputFile
Represent each equivalence class as a concatenation of its elements, in ascending order.
Output all the equivalence classes of digits 1 to 9, one at a line, sorted lexicographically.
Вхідні дані #1
1 1 566
Вихідні дані #1
1234 5 6 789