package com.example;

import java.io.IOException;
import java.util.List;

public class ProblemB {
    
    enum Result {
	INSUFFICIENT,
	SUFFICIENT,
	SUFFICIENT_WHEN_SURPRISING
    }

    public static void main(String[] a) throws IOException {

	List<String> lines = FileUtil.getLines("/B-large.in");
	
	int cases = Integer.valueOf(lines.get(0));
	
	for(int c=0; c<cases; c++) {
	    String[] tokens = lines.get(c+1).split(" ");
	    
	    int n = Integer.valueOf(tokens[0]); // N = number of Googlers
	    int s = Integer.valueOf(tokens[1]); // S = number of surprising triplets
	    int p = Integer.valueOf(tokens[2]); // P = __at least__ a score of P
	    
	    int sumSufficient = 0;
	    int sumSufficientSurprising = 0;
	    
	    for(int i=0; i<n; i++) {
		int points = Integer.valueOf(tokens[3+i]);
		
		switch(test(points, p)) {
		case SUFFICIENT:
		    sumSufficient++;
		    break;
		    
		case SUFFICIENT_WHEN_SURPRISING:
		    sumSufficientSurprising++;
		    break;
		}
		
//		uSystem.out.println("points "+ points +" ? "+ p +" => "+ result);
	    }
	    
	    System.out.println("Case #"+ (c+1) +": "+ (sumSufficient + Math.min(s, sumSufficientSurprising)));
	    
//	    System.out.println();
//	    System.out.println("N="+ n +", S="+ s +", P="+ p);
//	    System.out.println();
	}
    }

    private static Result test(int n, int p) {
	int fac = n / 3;
	int rem = n % 3;
	
	if(rem == 0) {
	    
//	    int triplet0[] = { fac, fac, fac };
//	    print(n, triplet0);
	    
	    if(fac >= p) {
		return Result.SUFFICIENT;
	    }
	    
	    if(fac > 0 && fac < 10) {
		
		if(fac+1 >= p) {
		    return Result.SUFFICIENT_WHEN_SURPRISING;
		}
		
//		int triplet1[] = { fac+1, fac, fac-1 }; // surprising 
//		print(n, triplet1);
	    }
	    
	    
	} else if(rem == 1) {
	    
//	    int triplet0[] = { fac+1, fac, fac };
//	    print(n, triplet0);
	    
	    if(fac+1 >= p) {
		return Result.SUFFICIENT;
	    }
	    
//	    if(fac > 0 && fac < 10) {
//		int triplet1[] = { fac+1, fac+1, fac-1 };
//		print(n, triplet1);
//	    }
	    
	} else if(rem == 2) {
	    
//	    int triplet0[] = { fac+1, fac+1, fac };
//	    print(n, triplet0);
	    
	    if(fac+1 >= p) {
		return Result.SUFFICIENT;
	    }
	    
	    if(fac < 9) {
//		int triplet1[] = { fac+2, fac, fac }; // surprising
//		print(n, triplet1);

		if(fac+2 >= p) {
		    return Result.SUFFICIENT_WHEN_SURPRISING;
		}
	    }
	    
	} else {
	    throw new RuntimeException("error");
	}
	
	return Result.INSUFFICIENT;
//	System.out.println();
//	System.out.println(n +" => "+ div3 +" ("+ rem +")");
    }
    
//    private static void print(int n, int[] triplet) {
//	System.out.println("n="+ n +" ("+ (n/3) +","+ (n%3) +") => ["+ triplet[0] +","+ triplet[1] +","+ triplet[2] +"]" + (triplet[0]-triplet[2] > 1 ? " *" : ""));
//    }
    
}

package com.coding.codejam;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author madhava
 * 
 */
public class B {

    private static final int MAX_SCORE = 10;
    private static final int MIN_SCORE = 0;
    private static final int MAX_DIFFERENCE = 2;
    private static int[][] dp = new int[100][101];
    static {
    }

    /**
     * @param args
     * @throws IOException
     * @throws NumberFormatException
     */
    public static void main(final String[] args) throws NumberFormatException, IOException {

        String inputFileName = args[0];
        BufferedReader reader = new BufferedReader(new FileReader(inputFileName));
        String outputFileName = inputFileName + "_output";
        BufferedWriter writer = new BufferedWriter(new FileWriter(outputFileName));
        int noOfTestCases = getInteger(reader);
        int loopCounter = 1;
        while (noOfTestCases-- != 0) {
            initialize();
            List<Integer> input = getArray(reader);
            int noOfGooglers = input.get(0);
            int noOfSurprisingTriplets = input.get(1);
            int bestResult = input.get(2);
            List<Integer> scores = new ArrayList<Integer>(noOfGooglers);
            for (int i = 0; i < noOfGooglers; i++) {
                scores.add(input.get(i + 3));
            }

            int result = maxNoOfGooglers(scores, 0, noOfSurprisingTriplets, bestResult);
            writer.write("Case #" + loopCounter + ": " + result + "\n");
            System.out.println("Case #" + loopCounter + ": " + result);
            loopCounter++;
        }
        writer.close();
    }

    /**
    																											   * 
    																											   */
    private static void initialize() {
        for (int i = 0; i < dp.length; i++) {
            for (int j = 0; j < dp[i].length; j++) {
                dp[i][j] = -1;
            }

        }

    }

    /**
     * @param scores
     * @param index
     * @param noOfSurprisingTriplets
     * @param bestResult
     * @return
     */
    private static int maxNoOfGooglers(final List<Integer> scores, final int index,
            final int noOfSurprisingTriplets, final int bestResult) {

        if (noOfSurprisingTriplets < 0) {
            return -(scores.size() + 1);
        }
        if (index == scores.size()) {
            return noOfSurprisingTriplets == 0 ? 0 : -(scores.size() + 1);
        }
        int result = dp[index][noOfSurprisingTriplets];
        if (result != -1) {
            return result;
        } else {
            result = 0;
            for (int maxScore = MAX_SCORE; maxScore >= MIN_SCORE; maxScore--) {

                for (int i = 0; i <= MAX_DIFFERENCE; i++) {
                    int secondMaxScore = maxScore - i;
                    int thirdMaxScore = scores.get(index) - secondMaxScore - maxScore;
                    if ((thirdMaxScore > secondMaxScore) || (thirdMaxScore < 0)
                            || (maxScore - thirdMaxScore > MAX_DIFFERENCE)) {
                        continue;
                    }
                    result = Math.max(
                            maxNoOfGooglers(scores, index + 1,
                                    noOfSurprisingTriplets - isTripletSuprising(maxScore, thirdMaxScore),
                                    bestResult) + toInteger(maxScore >= bestResult), result);
                }
            }
            dp[index][noOfSurprisingTriplets] = result;
            return result;
        }
    }

    /**
     * @param b
     * @return
     */
    private static int toInteger(final boolean b) {
        if (b) {
            return 1;
        } else {
            return 0;
        }

    }

    /**
     * @param maxScore
     * @param thirdMaxScore
     * @return
     */
    private static Integer isTripletSuprising(final int maxScore, final int thirdMaxScore) {
        return toInteger(maxScore - thirdMaxScore == MAX_DIFFERENCE);

    }

    /**
     * @param reader
     * @return
     * @throws IOException
     * @throws NumberFormatException
     */
    private static int getInteger(final BufferedReader reader) throws NumberFormatException, IOException {
        return Integer.parseInt(reader.readLine());
    }

    private static List<Integer> getArray(final BufferedReader reader) throws IOException {
        String[] line = reader.readLine().split(" ");
        List<Integer> numbers = new ArrayList<Integer>();
        for (String input : line) {
            numbers.add(Integer.parseInt(input));
        }
        return numbers;
    }
}
