How Many Tests
InterviewTime limit1sMemory limit512 MB
Given some surviving file names (equal length, digits only), find the minimum and maximum possible original test count n consistent with the zero-padding naming rule.
- Level
Medium5 of 10
- Topics
- Implementation, Math, Brute force, String
- Solved
- No attempts yet
Problem
When judges prepare tests for a programming contest problem, they number the tests from to .
It is convenient if the files with tests are shown in their correct order, from to . But file managers sort files by their names as strings, so if the name of the test file is equal to its number, the file order is not correct, for example <<10>> goes before <<2>>.
To avoid this problem, file names are prepended with leading zeroes. Judges use the minimal possible number of leading zeroes to make the names of all files have the same length. For example, if the problem has tests, the names of the files with tests are <<01>>, <<02>>, <<03>>, <<04>>, <<05>>, <<06>>, <<07>>, <<08>>, <<09>> and <<10>>.
Andrew is an experienced judge, so he always uses the described way to name the files with tests. Recently he has found some files with tests of some ancient problem on his old hard drive. Unfortunately, the drive is damaged, so some tests are missing. Help Andrew find out how many tests could have been in the problem. He wants to know the minimal and the maximal possible number of tests.
Input
The first line of input contains an integer , the number of files (). The following lines contain file names. All these lines are non-empty, have equal length that doesn't exceed . File names are distinct, they only contain digits. No file name contains only zeroes.
Output
Output two integers: the minimal and the maximal number of tests that the problem could have.