In Homeric Epics there are
different words numbered from
to
.
The
-th word appears
times in the text.
Allison wants to substitute the
-th word with a
-ary string
, satisfying the following constraint: for any
,
,
is not the prefix of
.
Allison wants to know how to choose
so that the resulting text has minimum length.
Under the assumption that the total length of the text is minimal, Allison wants to know what is the shortest possible length of the longest
.
A string is called a
-ary string if and only if its characters are in
.
A string
is said to be a prefix of
if and only if there exists
such that
where
is the length of
and
represents the substring of
formed by the first
characters.
Input Specification
The first line of the input file contains two integers
separated by one space, denoting there are
words in total and we need to substitute the words with a
-ary string.
In the following
lines, the
-th line has a nonnegative integer
denoting the number of times the
-th word has occurred.
Output Specification
The output consists of two lines.
The first line is an integer denoting the minimum length of the Homeric Epics after substitution. The second line is an integer denoting the minimum length of the longest string
given the total length is minimum.
Sample Input 1
Copy
4 2
1
1
2
2
Sample Output 1
Copy
12
2
Sample Input 2
Copy
6 3
1
1
3
3
9
9
Sample Output 2
Copy
36
3
Constraints
Test Case |  |  | Additional Constraints |  |
1 |  |  | |  |
2 |  |  | |
3 |  |  | All are equal. |
4 |  |  | The are generated uniformly at random. |
5 |  |  | |
6 |  |  | |
7 |  |  | All are equal. |
8 |  |  | |
9 |  |  | |
10 |  |  | All are equal. |
11 |  |  | All are equal. |
12 |  |  | All are equal. |
13 |  |  | |
14 |  |  | |
15 |  |  | |
16 |  |  | The are generated uniformly at random. |
17 |  |  | |
18 |  |  | The are generated uniformly at random. |
19 |  |  | |
20 |  |  | |
Scoring
For each test case:
- If only the first line is correct,
of points will be awarded;
- If both lines are correct,
of points will be awarded.
Comments