Open Olympiad in Design | 프로그래밍의 벗 PivotOJ
PivotOJ

Open Olympiad in Design

시간 제한: 1000ms메모리 제한: 1024MB출처: MOOI 2016-17 finalBOJ 30759

문제

Nowadays, many of the people who prepare programming competitions are the former participants. This is good because former competitors not only know many competition details, but are also able to prepare the statements, admin the judgement system and do a lot of other interesting (or not so interesting) stuff. How would the things look like if the competition will be prepared by designers?

In one imaginary world the Open Olympiad in Design takes place. There are nn problem, which are prepared by nn statements designers (one for each problem), one designer of problem names and one font designer. Each of the nn designers who prepare statements has already finished his job and left some fixed space for the problem name. In particular, the lengths of the name of the ii-th problem should be equal to exactly lil_i characters.

According to competition rules problem names should be made of Unicode characters, be distinct and be located in lexicographical order (check the notes section). Font designer asked the problem names designer to pick such names that all conditions are satisfied and least possible number of distinct letters is used, so the amount of job he has to do is minimized.

Find out the minimum possible amount of distinct letters, required to obtain nn words of given lengths such that they are distinct and go in lexicographical order. Please, not that you are not allowed to change the order of the problems.

입력

The first line of the input contains a single integer nn (1n1000001 \leq n \leq 100\,000) --- the number of problems.

The second line contains nn integers l1,l2,,lnl_1, l_2, \ldots, l_n (1li1091 \leq l_i \leq 10^9) --- lengths of the problem names.

출력

Print one integer --- the minimum possible amount of distinct letters font designer has to paint in order to make it possible for names designer to achieve his goal.

힌트

String x1x2xax_1 x_2 \ldots x_a of length aa is called lexicographically smaller than string y1y2yby_1 y_2 \ldots y_b of length bb, if one of the two following statements holds:

  • In the first position ii such that xiyix_i \neq y_i the first string has the smaller symbol than the second string, i.e. x1=y1x_1 = y_1, x2=y2x_2 = y_2, \ldots, xi1=yi1x_{i-1} = y_{i-1}, xi<yix_i < y_i;
  • the first string is a strict prefix of a second string, i.e. a<ba < b and x1=y1x_1 = y_1, x2=y2x_2 = y_2, \ldots, xa=yax_a = y_a.

The sequence of distinct words is said to be sorted in lexicographical order if each word (except the last one) is lexicographically smaller than the next word.

In the first sample, it's enough to use characters 'a' << 'o' << 'x' and names "aa", "ao", "ax", "ox", "xx".

In the second sample, only two distinct letters are required, for example 'l' << 'o' and names "lol", "o", "ol" and "oo".

예제

예제 1

입력
5
2 2 2 2 2
출력
3

예제 2

입력
4
3 1 2 2
출력
2
코드를 제출하려면 로그인하세요.