P17699 [HackerEarth] You have recently found an array of N non-negative integers. You like it a lot but unfortunately it is too long. So now you are going to divide in exactly K blocks and each of the blocks
提高
题目描述

You have recently found an array of N non-negative integers. You like it a lot but unfortunately it is too long. So now you are going to divide in exactly K blocks and each of the blocks should consist of several consecutive elements of the array.

There are many ways to divide the array. You wish to minimize the value X calculated in the following way :
Let's suppose that sums of the elements in blocks are S1, S2 ... Sk correspondingly. X = sum (Si - Sj)^2 through all i, j from 1 to K and i ≤ j.

Before dividing the array you are interested in the exact value of X. So the only thing you have to do is to find it.

Input
The first line contains two space-separated integers N and K.
The second line contains N space-separated integers - your array.

Output
Output one integer - answer for the question.

Constraints
N ≤ 500, K ≤ 300, K ≤ N
Each element of the array is an integer from 0 to 10^5
N ≤ 20 in 40% of the test data.

SAMPLE INPUT
7 3
1 7 3 5 1 4 4

SAMPLE OUTPUT
2

Explanation

The best way is to divide the array in such 3 groups : (1, 7), (3, 5), (1, 4, 4) with Si correspondingly 8, 8, 9

输入格式

见题面

输出格式

见题面

样例输入
391 132 49926 50527 88235 44525 27775 34011 67567 87931 63104 84597 34859 60338 68157 54239 49338 78518 57175 79412 37245 37721 64001 65585 42851 55602 79589 43307 47274 35180 51399 32956 44261 55904 35814 70461 62649 41441 54056 46836 38254 52825 37617 46609 44074 48793 69079 51546 60658 35944 26358 87969 57720 40417 48676 77305 60313 37247 47556 74924 20385 55540 41595 91371 51788 38589 29830 49988 63125 37495 68327 58069 34606 22512 18498 38210 71623 54523 57737 43878 39451 68108 44632 43725 41638 41344 41761 39900 71986 33208 22792 58581 37144 44524 18317 25984 52553 68033 70636 51102 46085 54167 39493 47140 46705 59813 38010 64814 61388 44483 66267 40109 65661 72714 47748 34782 59595 59421 48514 65410 59252 46404 16569 42191 40924 48445 33669 27424 35872 63954 23840 56945 65234 42284 74698 62092 47236 42211 53669 20222 54529 46040 68441 19411 37981 24266 60546 70398 50100 42913 48591 39571 84393 58252 30941 27585 39602 42959 48617 60023 71964 55642 40748 37351 74950 45850 26112 22962 24236 22288 46534 47067 25644 48674 45191 62339 34310 39603 65885 48211 48932 66035 61583 80569 28439 61433 25982 68819 40036 64138 31299 25643 49796 50879 34070 47144 61349 38220 47980 82238 46642 31123 53993 78059 13846 36744 17391 23140 49600 50221 70168 16392 25316 66813 48714 47512 82695 59888 50851 42796 48057 44630 55324 58596 70304 35946 71141 29530 42298 53158 72345 35035 67678 45529 38674 65370 57222 87794 13080 54046 61392 64418 37822 42562 45758 43685 43914 31963 60609 36058 14422 75255 35704 43034 37624 66890 53176 41155 46244 45478 67402 21013 38412 7215 55928 86341 52302 46154 28998 44873 67468 48218 29824 36217 22358 49962 44665 55508 55508 63018 20365 49186 45724 16473 39530 47294 33378 59909 31764 42545 41048 44341 54177 30845 56400 62177 60871 21824 39074 77032 63517 40821 59087 32959 61465 61976 68073 46825 53725 24946 66225 74539 35506 38701 67966 31100 29527 40235 39394 50109 54779 60189 29708 60462 50180 68298 14314 69787 81814 59188 65045 70234 64723 39518 37484 71412 48866 19946 78975 28070 70833 33382 65963 68999 31098 53603 60677 73862 40200 65098 59648 53019 22455 59885 42692 49336 36412 48353 36708 66821 35113 56454 55985 22984 66607 32491 26604 33189 31011 61781 48158 73610 60094 26008 84551 51943 45868 55853 59705 86178 39491 61696 72514 54470 46990 51468 35725 51454 25617 44713 58693 60356 49099
样例输出
1596755015560