Under construction

Still being built. Things may change

How Many Tests

Interview

Time limit1sMemory limit512 MB

Summary
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 11 to nn.

It is convenient if the files with tests are shown in their correct order, from 11 to nn. 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 1010 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 kk, the number of files (1≤k≤10001 \le k \le 1000). The following kk lines contain file names. All these lines are non-empty, have equal length that doesn't exceed 99. 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.

Examples1

  1. Example 1

    Input
    3
    05
    10
    08
    
    Expected output
    10
    99