/**
 * 
 */
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 cj2;

import dancingwiththegooglers.ScoreAnalyzer;
import edu.uwec.cs.genacje.codejam.speakingintongues.GooglereseTranslator;
import edu.uwec.cs.genacje.codejam.utilities.objects.IoMgr;
import edu.uwec.cs.genacje.codejam.utilities.objects.StringFormatter;

/**
 *
 * @author James Genac
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        
        long totalTime = System.currentTimeMillis();
        solveDancingWithTheGooglers();
       System.out.println("Total time to solve: " + (System.currentTimeMillis() - totalTime) + " ms.");

    }

    private static void solveDancingWithTheGooglers() {
        IoMgr io = new IoMgr("B-small-attempt0.in");

        int linecount = 1;
        long start = 0;
        io.rls(); // eat first line

        ScoreAnalyzer scoreAnalyzer = null;

        while (io.ready()) {
            scoreAnalyzer = new ScoreAnalyzer(io.rlia(" "));


            start = System.currentTimeMillis();

            io.wlf("Case #"+linecount+": " + scoreAnalyzer.getMaxNumOfHighScoringDancers());
            System.out.println("Case " + linecount + " took " + (System.currentTimeMillis()-start) + " ms.");
            linecount++;
        }


       io.close();
    }

    private static void solveSpeakingInTongues() {
        IoMgr io = new IoMgr("A-small-attempt0.in");

            int linecount = 1;
            long start = 0;
            io.rls(); // eat first line
            String in = "";
            long totalTime = System.currentTimeMillis();

            while (io.ready()) {
                in = io.rls();


                start = System.currentTimeMillis();

                io.wlf("Case #"+linecount+": " + GooglereseTranslator.translateString(in));
                System.out.println("Case " + linecount + " took " + (System.currentTimeMillis()-start) + " ms.");
                linecount++;
            }


           io.close();
    }
}


