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:
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

void print_dp(int dp[1001],int paragraph_len,int p1,int p2){
  for(int i=0;i<=paragraph_len;i++){
    printf("i:=%d j:=%d dp[%d]:=%d\n",p1,p2,i,dp[i]);
  }
  printf("\n");
}

int main(){
  int paragraph_len,paper_width;
  
  int case_num = 1;
  while(~scanf("%d %d",&paragraph_len,&paper_width)){
    if(paragraph_len == 0 && paper_width == 0) break;

    int a[1001];
    int sum[1001][1001];
    memset(a,0,sizeof(a));
    
    for(int i=0;i<paragraph_len;i++){
      scanf("%d",a+i);
    }

    for(int i=0;i<paragraph_len;i++){
      int tmp = 0;
      for(int j=i;j<paragraph_len;j++){
	tmp += a[j];
	sum[i][j] = tmp;
      }
    }
    
    int dp[1001];
    for(int i=0;i<paragraph_len;i++){
      dp[i] = abs(sum[0][i] - paper_width);
      for(int j=0;j<i;j++){
	dp[i] = min(dp[i],dp[j]+abs(sum[j+1][i]-paper_width));
	// print_dp(dp,paragraph_len,i,j);
      }
    }
    
    dp[paragraph_len-1] = min(dp[paragraph_len-1],max(0,sum[0][paragraph_len-1]-paper_width));
    for(int i=0;i<paragraph_len;i++){
      dp[paragraph_len-1]
	= min(dp[paragraph_len-1],
	      dp[i] + max(0,sum[i+1][paragraph_len-1]-paper_width)
	);
    }
    
    printf("Case %d: %d\n",case_num++,dp[paragraph_len-1]);
  }
}