package codejam;

import fixjava.Pair;

public class Utils {

	public static long minLong(long firstVal, long... otherVals) {
		long minVal = firstVal;
		for (int i = 0; i < otherVals.length; i++)
			minVal = Math.min(firstVal, otherVals[i]);
		return minVal;
	}

	public static int minInt(int firstVal, int... otherVals) {
		int minVal = firstVal;
		for (int i = 0; i < otherVals.length; i++)
			minVal = Math.min(firstVal, otherVals[i]);
		return minVal;
	}

	public static float minFloat(float firstVal, float... otherVals) {
		float minVal = firstVal;
		for (int i = 0; i < otherVals.length; i++)
			minVal = Math.min(firstVal, otherVals[i]);
		return minVal;
	}

	/**
	 * ArgMin returned as a Pair<Integer, Integer>(index, value). Array must
	 * have at least one value.
	 */
	public static Pair<Integer, Integer> argMin(int[] arr) {
		int min = arr[0];
		int argMin = 0;
		for (int i = 1; i < arr.length; i++) {
			if (arr[i] < min) {
				min = arr[i];
				argMin = i;
			}
		}
		return new Pair<Integer, Integer>(argMin, min);
	}

	/**
	 * ArgMax returned as a Pair<Integer, Integer>(index, value). Array must
	 * have at least one value.
	 */
	public static Pair<Integer, Integer> argMax(int[] arr) {
		int max = arr[0];
		int argMax = 0;
		for (int i = 1; i < arr.length; i++) {
			if (arr[i] > max) {
				max = arr[i];
				argMax = i;
			}
		}
		return new Pair<Integer, Integer>(argMax, max);
	}

}

package test;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;

public class DancingWithTheGooglers {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		PrintWriter out = null;
		BufferedReader in = null;
		String test;
		
		try {
			
			out = new PrintWriter(args[1]);
			in = new BufferedReader(new FileReader(args[0]), 1024);
			
			// number of test cases
			in.readLine();
			
			for (int i=1; (test=in.readLine())!=null; i++) {
				String parameters[] = test.split(" ");
				int googlers = 0;
				int surprising = 0;
				int totalSurprising = Integer.parseInt(parameters[1]);
				int minScore = Integer.parseInt(parameters[2]);
				int minTotal = minScore * 3;
				for (int j=3; j<parameters.length; j++) {
					int score = Integer.parseInt(parameters[j]);
					if (minTotal==0) {
						googlers++;
					}
					else if (score==0) {
						// do nothing
					}
					else if (score>=minTotal-2) {
						googlers++;
					}
					else if (score>=minTotal-4&&surprising<totalSurprising) {
						googlers++;
						surprising++;
					}
				}
				out.printf("Case #%d: %d%n", i, googlers);
			}
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		try {
			if (in!=null)
				in.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		if (out!=null)
			out.close();
		
		
	}

}
