/**
 * 
 */
package pandit.codejam;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.Scanner;

/**
 * @author Manu Ram Pandit
 * 
 */
public class DancingWithGooglersUpload {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		FileInputStream fStream = new FileInputStream(
				"input.txt");

		Scanner scanner = new Scanner(new BufferedInputStream(fStream));
		Writer out = new OutputStreamWriter(new FileOutputStream("output.txt"));

		int T = scanner.nextInt();
		int N,S,P,ti;
		int counter = 0;
		for (int count = 1; count <= T; count++) {
			N=scanner.nextInt();
			S = scanner.nextInt();
			counter = 0;
			P = scanner.nextInt();
			for(int i=1;i<=N;i++){
				ti=scanner.nextInt();
				if(ti>=(3*P-2)){
					counter++;
					continue;
				}
				else if(S>0){
					if(P>=2 && ((ti==(3*P-3)) ||(ti==(3*P-4)))) {
					S--;
					counter++;
					continue;
					}
				}
				
			}
			// System.out.println("Case #" + count + ": " + counter);
			out.write("Case #" + count + ": " + counter + "\n");
		}
		fStream.close();
		out.close();

	}

}

package quals;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Dancing {

	public static void main(String args[]) {
		try {
			System.setIn(new FileInputStream("B-small-attempt0.in"));
			Scanner scanner = new Scanner(System.in);

			int testCases = scanner.nextInt();
			scanner.nextLine();

			for (int i = 1; i <= testCases; i++) {
				int numGooglers = scanner.nextInt();
				int numSurprising = scanner.nextInt();
				int bestResultThreshold = scanner.nextInt();

				int[] googlers = new int[numGooglers];
				for (int j = 0; j < numGooglers; j++) {
					googlers[j] = scanner.nextInt();
				}

				int passingGooglers = dancingWithTheGooglers(numGooglers,
						numSurprising, bestResultThreshold, googlers);
				System.out.println(String.format("Case #%d: %d", i,
						passingGooglers));
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	private static int dancingWithTheGooglers(int numGooglers,
			int numSurprising, int bestResultThreshold, int[] googlers) {
		int passingGooglers = 0;

		for (int i = 0; i < numGooglers; i++) {
			if (googlers[i] / 3.0 > bestResultThreshold - 1) {
				// in the case of say, [30,29,28,27,26,25], they can all meet
				// a threshold of 9 without being 'surprising'
				passingGooglers++;
			} else if (numSurprising > 0
					&& bestResultThreshold > 1
					&& googlers[i] >= ((bestResultThreshold - 1) * 3) - 1) {
				// boundary cases are when the threshold is 1 or less - in that
				// case, any non zero score would work here.
				passingGooglers++;
				numSurprising--;
			}
		}

		return passingGooglers;
	}

}
