Save Energy
There are N towns in a line, numbered from 0 to N - 1. Starting from town 0, we want to reach town N - 1. From town i, we can jump to any town j > i with an energy cost of (j-i)*A[i] + (j2 - i2)*A[i]2, where A[i] for all i are given in input. Find the minimum total energy cost to reach town N - 1 from town 0.
Input
The first line contains a single integer, N. The next line contains N space separated integers, ith integer denoting the value of A[i] , 0 ≤ i ≤ N - 1.
Output
Output the minimum cost to reach town N.
Constraints
1 ≤ N ≤ 10^5
-10^3 ≤ A[i] ≤ 10^3
Example 1
Example 2
PreviousMinimum Number of Platforms Required for a Railway/Bus StationNextDifficult Economic Situation
Last updated