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

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.InputStreamReader;

public class ProblemB {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try{
			// Open the file that is the first 
			// command line parameter
			FileInputStream fstream = new FileInputStream("input.txt");
			// Get the object of DataInputStream
			DataInputStream in = new DataInputStream(fstream);
			BufferedReader br = new BufferedReader(new InputStreamReader(in));
			String strLine;
			br.readLine();
			int counter = 1;
			//Read File Line By Line
			while ((strLine = br.readLine()) != null)   {
				String values[] = strLine.split(" ");
				
				int surprisingScores = Integer.parseInt(values[1]);
				
				int pValue = Integer.parseInt(values[2]);
				
				int nearP = 0;
				int aboveP = 0;
				
				for (int i = 3; i < values.length; i++)
				{
					int score = Integer.parseInt(values[i]);
					
					int maxScore = 0;
					int maxSurprisingScore = 0;
					
					if (score > 0)
					{
						maxScore = (score - 1) / 3 + 1;
						maxSurprisingScore = (score + 1) / 3 + 1;
					}
					
					if (maxScore > 10)
					{
						maxScore = 10;
					}
					
					if (maxSurprisingScore > 10)
					{
						maxSurprisingScore = 10;
					}
					
					if (maxScore >= pValue)
					{
						aboveP ++;
					}
					else if (maxSurprisingScore >= pValue)
					{
						nearP ++;
					}
				}
				
				int result = aboveP;
				
				if (nearP < surprisingScores)
				{
					result += nearP;
				}
				else
				{
					result += surprisingScores;
				}
				
				System.out.println("Case #" + counter + ": " + result);
				
				counter ++;
			}
			//Close the input stream
			in.close();
		}catch (Exception e){//Catch exception if any
			System.err.println("Error: " + e.getMessage());
		}
	}

}
