/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Dancing
 * Jason Bradley Nel
 * 16287398
 */
import java.io.*;

public class Dancing {

    public static void main(String[] args) {

        In input = new In("input.txt");
        int T = Integer.parseInt(input.readLine());

        for (int i = 0; i < T; i++) {
            System.out.printf("Case #%d: ", i + 1);
            int N = input.readInt();
            int s = input.readInt();
            int p = input.readInt();
            int c = 0;//counter for >=p cases
            //System.out.printf("N: %d, S: %d, P: %d, R: ", N, s, p);
            
            for (int j = 0; j < N; j++) {
                
                int score = input.readInt();
                int q = score / 3;
                int m = score % 3;
                //System.out.printf("%2d (%d, %d) ", scores[j], q, m);
                                
                switch (m) {
                    case 0:
                        if (q >= p) {
                            c++;
                        } else if (((q + 1) == p) && (s > 0) && (q != 0)) {
                            c++;
                            s--;
                        }
                        break;
                    case 1:
                        if (q >= p) {
                            c++;
                        } else if ((q + 1) == p) {
                            c++;
                        }
                        break;
                    case 2:
                        if (q >= p) {
                            c++;
                        } else if ((q + 1) == p) {
                            c++;
                        } else if (((q + 2) == p) && (s > 0)) {
                            c++;
                            s--;
                        }
                        break;
                }
            }
            //System.out.printf("Best result of %d or higher: ", p);
            System.out.println(c);
        }


    }
}

package CodeJam;

import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;

public class CodeJam {

	public static void main(String[] args) throws IOException {
		 String outputFile = System.getenv("USERPROFILE") +
		 "\\Documents\\B-small.out";
		 String inputFile = System.getenv("USERPROFILE") +
		 "\\Documents\\B-small.in";

		BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile));
		DataInputStream reader = new DataInputStream(new FileInputStream(
				inputFile));

		int T = Integer.valueOf(reader.readLine());
		for (int k = 1; k <= T; k++) {

			String line = reader.readLine();

			int nbreDancers = Integer.valueOf(line.substring(0,
					line.indexOf(" ")));
			line = line.substring(line.indexOf(" ") + 1);
			int s = Integer.valueOf(line.substring(0, line.indexOf(" ")));
			line = line.substring(line.indexOf(" ") + 1);
			int p = Integer.valueOf(line.substring(0, line.indexOf(" ")));
			line = line.substring(line.indexOf(" ") + 1);
			line += " ";
			int q = 0;
			int n = 0;
			if (3 * p - 4 < 0)
				s = 0;
			for (int j = 0; j < nbreDancers; j++) {
				int sum = Integer.valueOf(line.substring(0, line.indexOf(" ")));
				line = line.substring(line.indexOf(" ") + 1);
				if (sum >= 3 * p - 4) {
					if (((sum == 3 * p - 4) || (sum == 3 * p - 3))) {
						q++;
						if (q <= s) {
							n++;
						}
					} else {
						n++;
					}
				}
			}
			writer.write("Case #" + k + ": " + n);
			writer.newLine();
		}
		writer.close();
	}
}