#579
Unrated
262144 Revisited
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Bessie likes downloading games to play on her cell phone, even though she does find the small touch screen rather cumbersome to use with her large hooves.

She is particularly intrigued by the current game she is playing. The game starts with a sequence of NN positive integers a1,a2,,aNa_1,a_2,\ldots,a_N (2N262,1442\le N\le 262,144), each in the range 11061\ldots 10^6. In one move, Bessie can take two adjacent numbers and replace them with a single number equal to one greater than the maximum of the two (e.g., she might replace an adjacent pair (5,7)(5,7) with an 88). The game ends after N1N-1 moves, at which point only a single number remains. The goal is to minimize this final number.

Bessie knows that this game is too easy for you. So your job is not just to play the game optimally on aa, but for every contiguous subsequence of aa.

Output the sum of the minimum possible final numbers over all N(N+1)2\frac{N(N+1)}{2} contiguous subsequences of aa.

입력

First line contains NN.

The next line contains NN space-separated integers denoting the input sequence.

출력

A single line containing the sum.

예제 입력 1

6
1 3 1 2 1 10

예제 출력 1

115

점수

Test cases 2-3 satisfy N300N\le 300.Test cases 4-5 satisfy N3000N\le 3000.In test cases 6-8, all values are at most 4040.In test cases 9-11, the input sequence is non-decreasing.Test cases 12-23 satisfy no additional constraints.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.