Jailbreak

Partition L cells into at most G consecutive blocks, minimizing the sum over each cell of its escape power times its block length.

Hard8Dynamic programmingDivide and conquerPrefix sumNo attempts yetTime limit2sMemory limit512 MB

Problem

A prison has LL cells in a row. The cells are numbered 1 through LL, and cell ii holds one prisoner. The escape power of the prisoner in cell ii is CiC_i, a number that measures how well that prisoner can break out.

The ideal way to watch the prison is to put one guard on every cell, so that each guard watches a single prisoner. Because of the budget, this prison can hire at most GG guards. You want to hire and place the guards so that the escape risk is as small as possible.

Each guard watches cells with consecutive numbers, and every cell is watched by exactly one guard. The escape risk RiR_i of cell ii is the escape power CiC_i multiplied by the number of prisoners watched by the guard in charge of cell ii. The escape risk of the prison is the sum of RiR_i over all cells.

Given LL, GG, and the escape power CiC_i of the prisoner in each cell, write a program that finds the minimum escape risk.

Input

The first line contains the size of the prison LL and the number of guards GG, separated by a space. (1L80001 \le L \le 8000, 1G8001 \le G \le 800)

The second line contains C1,C2,,CLC_1, C_2, \dots, C_L separated by spaces. (1Ci1091 \le C_i \le 10^9)

Output

Print the minimum escape risk on the first line.

Hint

In the first example the escape risk is smallest when one guard watches cells 1, 2, 3, another guard watches cells 4, 5, and the remaining guard watches cell 6.

The guard in charge of cells 1, 2, 3 watches three prisoners, so the escape risk of each of those cells is 11×3=3311 \times 3 = 33.

The guard in charge of cells 4, 5 watches two prisoners, so cell 4 gives 24×2=4824 \times 2 = 48 and cell 5 gives 26×2=5226 \times 2 = 52.

The guard in charge of cell 6 watches one prisoner, so cell 6 gives 100×1=100100 \times 1 = 100. The total is 33×3+48+52+100=29933 \times 3 + 48 + 52 + 100 = 299.