Company: Tesco_15nov
Difficulty: medium
Maximum BLOCKSUM Problem Description N blocks stand in a row and the i -th of them carries the number P_i . The only allowed rearrangement takes the first block and puts it at the end; every other block slides one position to the left. The move may be repeated any number of times, so the reachable arrangements are exactly the cyclic left rotations of the row. For an arrangement, the BLOCKSUM is BLOCKSUM = 1 * P_1 + 2 * P_2 + ... + N * P_N where the index i is 1-based. Report the largest BLOCKSUM that any reachable arrangement produces. Input Format The first line contains N . The second line contains N space-separated integers, the values on the blocks in their initial order. Output Format Print a single integer: the maximum BLOCKSUM. Constraints 1 <= N <= 2000 (the source paper states 10^5 ; the bound is reduced here so that every graded case fits the platform's input limit) 0 <= P_i <= 100000 Examples Example 1 Input: 3 30 20 10 Output: 130 Explanation: the three reachabl