AlgoUniversity
  • Go Back
Discussion
Earn Max Money :

Author

Manas

Difficulty Level : Medium

Submissions : 226

Asked In : Cisco

Marks :10

: 9 | : 0

You are given 'n' piggy banks, indexed from 0 to n - 1. Each piggy bank contains some amount of money in it which is represented by an array 'nums': You are asked to break all the piggy banks in any order. If you break the ith piggy bank, you will get the amount equivalent to (nums[i-1]* nums[i] * nums[i+1] dollars. If i-1 or i+1 goes out of bounds of the array, then treat it as if there is a piggy bank with 1 US Dollar in it. The goal is to return the maximum amount of dollars.

Constraints: 1 < 1<= 300 0 <= nums(i] <= 100 where i is [0, n-1]

Input

First line contains n, the number of piggy banks. Second line contains an array nums representing the amount of money in each piggy bank.

Output

An integer representing maximum amount of money

Example

Input
4
3 1 5 8
Output
167

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.