#D3176. LISum

    ID: 2643 Type: Default 1000ms 268MiB

LISum

LISum

problem

Given the sequence A A of length N N . Find the maximum value of  sumBi \ sum B_i , where B B is one of the longest increasing subsequences of the sequence A A .

The longest increasing subsequence of the sequence A A is the longest subsequence that satisfies Ai<Aj A_i <A_j with all i<j i <j .

output

Output the maximum value of  sumBi \ sum B_i , where B B is one of the longest increasing subsequences of the sequence A A . Also, output a line break at the end.

Example

Input

4 6 4 7 8

Output

21

inputFormat

outputFormat

output

Output the maximum value of  sumBi \ sum B_i , where B B is one of the longest increasing subsequences of the sequence A A . Also, output a line break at the end.

Example

Input

4 6 4 7 8

Output

21

样例

4
6 4 7 8
21