Baltic Olympiad in Informatics: 2014 Day 1, Problem 3
Adam wrote down a sequence of
consecutive positive integers starting with
on a blackboard. When he left, Billy came in and erased all but one digit from each number, thus creating a sequence of
digits.
Given the final sequence left on the blackboard, find the smallest value of
with which the initial sequence might have started.
Constraints
Subtask 1 [9%]

The correct answer does not exceed
.
Subtask 2 [33%]

Subtask 3 [25%]


All elements of the given sequence are equal.
Subtask 4 [33%]

Input Specification
The first line of the input contains a single integer
— the length of the sequence. The
second line contains
space-separated integers
— Billy's sequence
, in the order in which it is written on the blackboard.
Output Specification
The output should consist of a single line with the smallest value of
with which the initial sequence might have started.
Sample Input
Copy
6
7 8 9 5 1 2
Sample Output
Copy
47
Explanation for Sample
would correspond to Adam's sequence being
from which
Billy's sequence can indeed be obtained. As no smaller value of
would work, the answer is
.
Comments