Rokomari has decided to give you some books for free and you will also be given an opportunity to make some profit. Books will be placed in a line and you can pick one book at a time. Let’s say Price of ith book is defined with price (i)
. Upon picking ith book, you will gain profit of price (i) * price (i - 1) * price (i + 1)
. In words, prices of adjacent books will be multiplied with current picked book and will be contributed to profit. But if any adjacent book is not available (e.g: Books at the ends), you don’t need to consider that. Also note that, after picking i-th
book, (i-1)-th
book and (i + 1)-th
book will become adjacent. Now, you’re wondering, what is the maximum profit that you can make?
- Subtask1: Solve with input
n = 10
. - Subtask2: Solve with input
n = 100
.
For each case, print the case number and a number denoting maximum profit.
1
3
4 5 6
Case 1: 150
Explanation of sample input: Picking 5
first will result in (4 * 5 * 6)
. Then, picking 4 will result in (4 * 6)
. Then picking 6 will result in (6)
. Profit: (4 * 5 * 6) + (4 * 6) + 6
= 150