import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Scanner;


public class Dancing_With_the_Googlers {


    /**
     * The first line of the input gives the number of test cases, T.
     *  T test cases follow. 
     *  Each test case consists of a single line containing integers separated by single spaces. 
     *  The first integer will be N, the number of Googlers, and the second integer will be S, the number of surprising triplets of scores. 
     *  The third integer will be p, as described above. Next will be N integers ti: the total points of the Googlers. 
     * @throws IOException
     */
	   public static void main(String[] args) throws IOException {
	        // TODO Auto-generated method stub
			// Reading the input file
			Scanner in = new Scanner(new File("B-large.in"));
			// writting the input file
			FileOutputStream fos = new FileOutputStream("B-large.out");
			PrintStream out = new PrintStream(fos);
	         //Close the output stream
	        int testCase=Integer.parseInt(in.nextLine());
	        for(int i=0;i<testCase;i++) {
	        	out.print("Case #" + (i + 1) + ":\t");
	        	int NoOfGooglers= in.nextInt();
	        	int NoOfSurprisingResults = in.nextInt();
	        	int atLeastP=in.nextInt();
	        	ArrayList<Integer> scores= new ArrayList<Integer>();
        		int BestResults=0;
        		int Surprising=0;
	        	for(int j=0;j<NoOfGooglers;j++)
	        	{
	        		scores.add(in.nextInt());
	        		//System.out.print(scores.get(j));
	        		int modulus=scores.get(j)%3;
	        		int temp = scores.get(j);
	    			switch (modulus) {
					case 0:
						if (((temp / 3) >= atLeastP)) {
							BestResults++;
						} else {
							if (((((temp / 3) + 1) >= atLeastP) && ((temp / 3) >= 1))
									&& (Surprising < NoOfSurprisingResults)) {
								BestResults++;
								Surprising++;
								
							}
							System.out.println("Case 0"+"itr:"+i+"  surprising:"+temp);
						}
						
						break;
					case 1:
						if ((temp / 3) + 1 >= atLeastP) {
							BestResults++;
							continue;
						}
						
						break;
					case 2:
						if ((temp / 3) + 1 >= atLeastP) {
							BestResults++;
						} else {
							if (((temp / 3) + 2 >= atLeastP)
									&& (Surprising < NoOfSurprisingResults)) {
								BestResults++;
								Surprising++;
							}
							System.out.println("Case 2"+"itr:"+i+"  surprising:"+temp);
						}
						break;
					default:
						System.out.println("Error");
					}
	    			
				}// Internal for
				out.println(BestResults);
				// System.out.println(BestResults);
				System.out.println(Surprising);
				BestResults = 0;
			}// for
			in.close();
			out.close();
			fos.close();

	   }
}

package codejam2012;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.PrintStream;

public class ProblemB
{
	public static void main(String[] args) throws Exception
	{
		BufferedReader in = new BufferedReader(new FileReader("in.txt"));
		PrintStream out = System.out;
		out = new PrintStream("out.txt");
		
		int T = Integer.parseInt(in.readLine());
		
		for (int t = 0; t < T; t++)
		{
			String[] tok = in.readLine().split(" ");
			int N = Integer.parseInt(tok[0]);
			int S = Integer.parseInt(tok[1]);
			int p = Integer.parseInt(tok[2]);
			
// BRUTE FORCE
//			int ans = 0;
//			
//			for (int s1 = 0; s1 <= 10; s1++)
//			for (int s2 = s1; s2 <= s1+2; s2++)
//			for (int s3 = s2; s3 <= s1+2; s3++)
//			for (int s4 = 0; s4 <= 10; s4++)
//			for (int s5 = s4; s5 <= s4+2; s5++)
//			for (int s6 = s5; s6 <= s4+2; s6++)
//			for (int s7 = 0; s7 <= 10; s7++)
//			for (int s8 = s7; s8 <= s7+2; s8++)
//			for (int s9 = s8; s9 <= s7+2; s9++)
//			{
//				int p1 = Integer.parseInt(tok[3]);
//				int p1s = (s1+2 == s3) ? 1 : 0;
//				int p1t = (s3 >= p) ? 1 : 0;
//				if (s1+s2+s3 != p1) continue;
//				
//				if (N > 1)
//				{
//					int p2 = Integer.parseInt(tok[4]);
//					int p2s = (s4+2 == s6) ? 1 : 0;
//					int p2t = (s6 >= p) ? 1 : 0;
//					if (s4+s5+s6 != p2) continue;
//					
//					if (N > 2)
//					{
//						int p3 = Integer.parseInt(tok[5]);
//						int p3s = (s7+2 == s9) ? 1 : 0;
//						int p3t = (s9 >= p) ? 1 : 0;
//						if (s7+s8+s9 != p3) continue;
//						if (p1s+p2s+p3s != S) continue;
//						if (p1t+p2t+p3t > ans) ans = p1t+p2t+p3t;
//					}
//					else
//					{
//						if (p1s+p2s != S) continue;
//						if (p1t+p2t > ans) ans = p1t+p2t;
//					}
//				}
//				else
//				{
//					if (p1s != S) continue;
//					if (p1t > ans) ans = p1t;
//				}
//			}
// END BRUTE FORCE
			
			int with = 0, without = 0, either = 0, other = 0;
			for (int i = 3; i < tok.length; i++)
			{
				int total = Integer.parseInt(tok[i]);
				
				if (total == 0)
				{
					if (p == 0) without++;
				}
				else if (total == 1)
				{
					if (p <= 1) without++;
				}
				else if (total < 29)
				{
					if (total >= 3*p-2) either++;
					else if (total >= 3*p-4) with++;
					else other++;
				}
				else without++;
			}
			
			int ans = with + without + either;
			if (with > S) ans = S + without + either;
			else if (S > with + either + other) ans = 0;
			out.printf("Case #%d: %d\n", t+1, ans);
		}
		
		if (out != System.out) out.close();
	}
}
