Problem: You are hired by the ∀I¶אΞ℘, an extraterrestrial intelligence, as a programmer of their typesetting system. Your task today is to design an algorithm for text justification.

Text justification is to equalize the line widths as much as possible by inserting line breaks at appropriate posi- tions, given a word sequence called a paragraph and the width of the paper. Since you have not developed an automatic hyphenation algorithm yet, you cannot break a line in the middle of a word. And since their language does not put spaces between words, you do not need to consider about spacing.

To measure how well the text is justified in one configuration (i.e., a set of lines generated by inserting line breaks to a paragraph), you have defined its cost as follows:

* The total cost of a paragraph is the sum of the cost of each line.
* The cost for the last line is defined as max(0, s - w).
* The cost for other lines are given by |s - w|.



where s is the sum of the widths of the words in the line, and w is the width of the paper.

Please design the algorithm which takes a paragraph and calculates the configuration of the minimum cost.



Input

The input consists of multiple test cases.

The first line of each test case contains two positive integers n and w (0 ≤ n ≤ 1000 and 0 ≤ w ≤ 1,000,000). n is the length of paragraph and w is the width of the used paper. Each of the following n lines contains one positive integer ai which indicates the width of the i-th word in the paragraph. Here it is guaranteed that 0 ≤ ai ≤ w.

The input terminates with the line containing two zeros. This is not a part of any test case and should not be processed.

Output

For each test case, print the case number and the minimum cost for the paragraph.

Example

Input

4 10
8
6
9
1
4 7
1
2
3
4
0 0


Output

Case 1: 4
Case 2: 1

Solution (in CPP):

Solution:
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"

long long int memo[2000];
long long int aws[10000];
int N, W;

int getans(const int l) {
	if (memo[l] ==-1) {
		long long int sum = 0;
		long long int ans = 2e9 + 1;
		for (int r = l + 1; r <= N; ++r) {
			sum += aws[r - 1];
			if (r == N)ans = min(ans, max(0ll, sum - W));
			ans = min(ans, getans(r) + abs(sum - W));
		}
		memo[l] = ans;
	}
	return memo[l];
}
int main() {
	int num(0);
	while (1) {
		num++;
		cin >> N >> W;
		for (int i = 0; i < 2000; ++i) {
			memo[i] = -1;
		}
		if (!N)break;
		for (int i = 0; i < N; ++i) {
			cin >> aws[i];
		}
		long long int ans = getans(0);
		cout << "Case "<<num<<": "<<ans << endl;
	}
	return 0;
}