Range Editing
시간 제한4초메모리 제한2048 MB
모두 비어 있는 상태에서 시작해 범위 채우기와 범위 지우기만으로 주어진 셀 값 배열을 만드는 최소 연산 횟수를 구한다.
문제
You are editing a list of spreadsheet cells. Initially all cells are empty. You can perform two types of operations:
- Select a consecutive range of cells and change their values to a positive integer of your choice. All these cells get the same value after this operation.
- Select a consecutive range of cells and delete their values. All these cells become empty after this operation.
Given the final cell values that you would like to have in the spreadsheet, calculate the minimum number of editing operations required to obtain those values.
입력
The first line of input contains a single integer (), which is the number of cells you are editing. The cells are number from to .
Each of the next lines contains a single integer between and inclusive. The integer on the line is if cell should be empty after all operations. Otherwise, it is a positive integer that is the final value of cell .
출력
Output a single integer, which the minimum number of editing operations required.