/**
 * 
 */
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 tr0llhoehle.cakemix.googleCodejam;

import tr0llhoehle.cakemix.utility.googleCodeJam.Solver;

public class DWGSolver implements Solver<DWGProblem> {

	@Override
	public String solve(DWGProblem p) {
		int numberOfBestResult = 0;
		int surprising = 0;

		/*
		 * for (int sum : p.getDancerSums()) { int[] triplet = new int[3];
		 * boolean done = false; int remainder = sum % 3;
		 * 
		 * for (int i : triplet) { i = sum / 3;
		 * 
		 * if (remainder > 0) { i++; remainder--; } // not-surprising triplets
		 * generated.
		 * 
		 * if (i >= p.getBorder()) { numberOfBestResult++; done = true; break; }
		 * }
		 * 
		 * if (!done && sum > 1 && surprising < p.getNumberOfSuprisingTriplets()
		 * && triplet[0] + 1 >= p.getBorder()) { numberOfBestResult++;
		 * surprising++;
		 * 
		 * } }
		 */

		for (int sum : p.getDancerSums()) {
			int avg = sum / 3;
			int remainder = sum % 3;

			if (sum == 0) {
				if (p.getBorder() <= 0) {
					numberOfBestResult++;
				}
			} else if (sum == 1) {
				if (p.getBorder() <= 1) {
					numberOfBestResult++;
				}
			} else { // sum >= 2
				switch (remainder) {
				case 0:
					if (avg >= p.getBorder()) {
						numberOfBestResult++;
					} else if (surprising < p.getNumberOfSuprisingTriplets()
							&& avg + 1 >= p.getBorder()) {
						numberOfBestResult++;
						surprising++;
					}
					break;
				case 1:
					if (avg + 1 >= p.getBorder()) {
						numberOfBestResult++;
					}
					break;
				case 2:
					if (avg + 1 >= p.getBorder()) {
						numberOfBestResult++;
					} else if (surprising < p.getNumberOfSuprisingTriplets()
							&& avg + 2 >= p.getBorder()) {
						numberOfBestResult++;
						surprising++;
					}
					break;
				}
			}
		}

		return numberOfBestResult + "";
	}
}
