Bobo has a sequence a1,a2,…,an.
Let f(x) be the length of longest *strictly* increasing subsequence after replacing all
the occurrence of 0 with x.
He would like to find ∑ni=1i⋅f(i).
Note that the length of longest strictly increasing subsequence of sequence s1,s2,…,sm
isthe largest k
such that there exists 1≤i1<i2<⋯<ik≤m satisfying si1<si2<⋯<sik.
【Input】
The input consists of several test cases and is terminated by end-of-file.
The first line of each test case contains an integer n.
The second line contains n integers a1,a2,…,an.
【Output】
For each test case, print an integer which denotes the result.
Constraint
*1≤n≤105*0≤ai≤n
* The sum of n does not exceed 250,000.
2018-ACM-CCPC-湘潭邀请赛-I-Longest Increasing Subsequence-思维-最长上升子序列变形【Description】Bobo has a sequence a1,a2,…,an. Let f(x) be the length of longest *strictly* increasing subsequence after replacing all...