AT_abc436_f [ABC436F] Starry Landscape Photo

Description

In the night sky seen from planet AtCoder, there are $ N $ stars, and these $ N $ stars are arranged in a line from east to west. The $ i $ -th star from the east $ (1\le i\le N) $ is the $ B _ i $ -th brightest among these stars. Takahashi decided to take a picture of the night sky using the following procedure: 1. Choose a pair of integers $ (l,r) $ satisfying $ 1\le l\le r\le N $ , and set up the camera so that the $ l $ -th, $ (l+1) $ -th, $ \ldots $ , $ r $ -th stars from the east all fit in the frame, and no other stars enter the frame. 2. Choose an integer $ b $ satisfying $ 1\le b\le N $ , and open the shutter so that all stars among the $ N $ stars whose brightness ranks from $ 1 $ st through $ b $ -th (and that fit in the frame) are captured, and no other stars are captured. However, he may not take a picture with no stars captured. Find the number of different sets of stars that can be captured in pictures taken in this way.

Input Format

The input is given from Standard Input in the following format: > $ N $ $ B _ 1 $ $ B _ 2 $ $ \ldots $ $ B _ N $

Output Format

Print the answer.

Explanation/Hint

### Sample Explanation 1 For example, with $ (l,r)=(2,4),b=3 $ , you can take a picture with two stars: the $ 2 $ nd star from the east and the $ 4 $ th star from the east. Including this, you can take pictures with the following $ 12 $ different sets of stars. In each picture, stars further east are arranged further left, and the $ i $ -th brightest star is labeled with integer $ i $ . ![](https://cdn.luogu.com.cn/upload/vjudge_pic/AT_abc436_f/06834b0953931367a3fa63927d97cb405d0bbec8627c975eebe41aa2c0eb98e1.png) No other sets can be captured, so print `12`. ### Constraints - $ 1\le N\le5\times10 ^ 5 $ - $ 1\le B _ i\le N\ (1\le i\le N) $ - $ B _ i\ne B _ j\ (1\le i\lt j\le N) $ - All input values are integers.