Subtask 1
We try all possible
values (starting from smallest -
). With each
, we check if it is the answer using brute force - checking if all sequence numbers contain the required digits.
Time complexity: 
- correct answer.
Since
and
in the first subtask, this solution is enough for it.
Subtask 2
If the full solution is programmed inefficiently, it is possible to acquire an
solution.
Time complexity: 
Subtask 3
We are assuming that all elements of the given sequence are equal. Let's denote this digit as
.
If
, then our answer is
.
If
, then
(some number of digits 8
and one digit 9
at the end).
If
, then
.
The length of
depends on
. For example, if
and our sequence is 3 3 3 3 3
, then
and
. If
and
, then
.
Time complexity: 
Subtask 4
We'll solve our task by solving a more complex task first: for each
sequence element we'll declare sequence
.
is the sequence of digits which
sequence element has to have. For our initial task,
, where
- ... (DMOJ editor note: did the author get lazy here?)
Let's denote
, where
is the last digit and
. Now we have to try all possible
values
. After we have locked
with one of the possible values, our sequence looks like this:

After removing last digit, we get sequence 
What digits does
have to have?
has
, so
must have
.
has
, so
must have
and so on.
By merging these requirements, we can get a new sequence of sets
.
declares the required digits for
,
- for
, and so on. We repeat the same steps with our new sequence. What happens when we repeat these steps? We started with sequence length
, so after the first step, our new sequence length will be not bigger than
. So after
steps our sequence will be of length
or
- at this step, we can produce the answer.
Time complexity: 
Comments