AlgoUniversity
  • Go Back
Discussion
Chocolates :

Author

Ujjwal Srivastava

Difficulty Level : Medium

Submissions : 173

Asked In : Apollo

Marks :30

: 4 | : 1

Bob has $$$N$$$ chocolates in his refrigerator to which he gives special value. He performs some operations on the chocolates. In each operation, he takes one or more chocolates that are lying in a continuous manner. He then finds and notes down the minimum special value of a chocolate in that group of chocolates. He performs this operation for all groups of chocolates he could find.

The task is to find the sum of all the numbers he had written.

Input

The first line contains an integer $$$N$$$. The second line contains an array $$$A_{i}$$$ representing the special value of chocolates.$$$(1 \le N,A_{i} \le 10^5).$$$

Output

The desired sum.

Examples

Input
2
3 4
Output
10
Input
5
1 1 1 1 1
Output
15

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.