Open Olympiad in Design

시간 제한1초메모리 제한1024 MB

요약
각 단어의 길이가 주어질 때, 그 길이를 가진 서로 다른 단어 n개를 사전순으로 나열하는 데 필요한 최소 문자 종류 수를 구한다.
난이도

보통10점 중 6점

유형
그리디, 문자열, 구현, 수학
정답자
아직 제출이 없습니다

문제

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 l_il\_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 (1≤n≤100,0001 \leq n \leq 100\\,000) --- the number of problems.

The second line contains nn integers l_1,l_2,…,l_nl\_1, l\_2, \ldots, l\_n (1≤l_i≤1091 \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 x_1x_2…x_ax\_1 x\_2 \ldots x\_a of length aa is called lexicographically smaller than string y_1y_2…y_by\_1 y\_2 \ldots y\_b of length bb, if one of the two following statements holds:

  • In the first position ii such that x_i≠y_ix\_i \neq y\_i the first string has the smaller symbol than the second string, i.e. x_1=y_1x\_1 = y\_1, x_2=y_2x\_2 = y\_2, …\ldots, x_i−1=y_i−1x\_{i-1} = y\_{i-1}, x_i<y_ix\_i < y\_i;
  • the first string is a strict prefix of a second string, i.e. a<ba < b and x_1=y_1x\_1 = y\_1, x_2=y_2x\_2 = y\_2, …\ldots, x_a=y_ax\_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".

예제2

  1. 예제 1

    입력
    5
    2 2 2 2 2
    
    예상 출력
    3
    
  2. 예제 2

    입력
    4
    3 1 2 2
    
    예상 출력
    2