//dp[i][k]表示前i个店添加k个供应点所达到的最小值
//状态转移方程为:dp[i][k] = min(dp[j][k-1], dis[j+1][i]),
//其中k-1 <= j <= i-1, dis[i][j]表示从第i个饭店到第j个饭店添加一个供应点所达到的最小值,取i,j中间值即可
//初始化:dp[0][0] = 0;
#include <iostream>
#include <cstring>
using namespace std;
const int N = 205;
const int INF = 1000000000;
int dp[N][N];
int dis[N][N];
int num[N];
int n, m;
int my_abs(int a)
{
if (a > 0)
return a;
return -a;
}
int main()
{
int cases = 1;
while (cin >> n >> m && (n || m))
{
for (int i = 1; i <= n; i++)
cin >> num[i];
memset(dis, 0, sizeof(dis));
for (int i = 1; i <= n; i++)
{
for (int j = i; j <= n; j++)
{
int mid = (i+j)/2;
for (int k = i; k <= j; k++)
dis[i][j] += my_abs(num[mid] - num[k]);
}
}
for (int i = 0; i <= n; i++)
for (int j = 0; j <= n; j++)
dp[i][j] = INF;
dp[0][0] = 0;
for (int i = 1; i <= n; i++)
for (int k = 1; k <= m; k++)
for (int j = k-1; j < i; j++)
dp[i][k] = min(dp[j][k-1] + dis[j+1][i], dp[i][k]);
cout << "Chain " << cases++ << endl;
cout << "Total distance sum = " << dp[n][m] << endl;
cout << endl;
}
return 0;
}