/**
 * 
 */
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 gcj.main;

import gcj.cases.competition.qualification_round_2012.CaseB;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;

public class Main {

	
	public static final void main (String[] args) throws Exception{
//		doTask("taskTeszt0", "/home/dev/LetÃ¶ltÃ©sek/0-teszt-practice.in", "/home/dev/LetÃ¶ltÃ©sek/0-teszt-practice.out", new Case0());
//		doTask("taskSmall0", "/home/dev/LetÃ¶ltÃ©sek/A-small-attempt0.in", "/home/dev/LetÃ¶ltÃ©sek/A-small-attempt0.out", new Case0());
		
//		doTask("taskTesztB", "/home/dev/LetÃ¶ltÃ©sek/B-teszt-practice.in", "/home/dev/LetÃ¶ltÃ©sek/B-teszt-practice.out", new CaseB());
		doTask("taskSmallB", "/home/dev/LetÃ¶ltÃ©sek/B-small-attempt0.in", "/home/dev/LetÃ¶ltÃ©sek/B-small-attempt0.out", new CaseB());
//		doTask("taskLargeB", "/home/dev/LetÃ¶ltÃ©sek/B-large-practice.in", "/home/dev/LetÃ¶ltÃ©sek/B-large-practice.out", new CaseB());
		
//		doTask("taskTesztC", "/home/dev/LetÃ¶ltÃ©sek/C-teszt-practice.in", "/home/dev/LetÃ¶ltÃ©sek/C-teszt-practice.out", new CaseC());
//		doTask("taskSmallC", "/home/dev/LetÃ¶ltÃ©sek/C-small-attempt0.in", "/home/dev/LetÃ¶ltÃ©sek/C-small-attempt0.out", new CaseC());
//		doTask("taskLargeC", "/home/dev/LetÃ¶ltÃ©sek/C-large.in", "/home/dev/LetÃ¶ltÃ©sek/C-large.out", new CaseC());
		
		doTask(null, null, null, null); //because i hate the 'never used locally' warning... 
	}

	
	private static final void doTask(String taskID, String inpFilePath, String outFilePath, Case c) throws Exception {
		if(taskID == null) return;
		BufferedReader br = null;
		BufferedWriter bw = null;
		String strLine;
		int caseNum = 0;
		System.out.println(taskID + " strated...");
		try{
			{
				//open files
				br = new BufferedReader(new FileReader(new File(inpFilePath)));
				bw = new BufferedWriter(new FileWriter(new File(outFilePath)));
			}
			{
				//read caseNum value
				if ((strLine = br.readLine()) != null){
					caseNum = Integer.parseInt(strLine);	
				}
				System.out.println("CaseNum: "+caseNum);
			}
			for(int i=0; i<caseNum; i++){			
				System.out.println("\tprocessing Case #: "+(i+1));
				//load case
				c.init(i+1, br);
				//processing case
				c.solve();
				//write to file
				c.generateOutput(bw, i<caseNum-1);
			}
		}catch(Exception e){
			System.out.println(taskID + " failed!");
			e.printStackTrace();
		}finally{
			//end
			if(br!=null) br.close();
			if(bw!=null) bw.close();
			System.out.println(taskID + " finished.");
		}
	}
}
