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

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class dance {
    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int nocases = Integer.parseInt(br.readLine());
        int arr[];
        int ans[] = new int[nocases];
        for (int i = 0; i < nocases; i++) {
            String token[] = br.readLine().split(" ");
            int N = Integer.parseInt(token[0]);
            int S = Integer.parseInt(token[1]);
            int P = Integer.parseInt(token[2]);
            arr=new int[N];
            for (int j = 0; j < N; j++) {
                arr[j] = Integer.parseInt(token[j + 3]);
            }
            ans[i]=method(arr, N, P, S);
        }
        for (int i = 0; i < nocases; i++) {
            System.out.println("Case #" + (i + 1) + ": " + ans[i]);
        }
    }
    private static int method(int[] arr, int N, int P, int S) {
        int c1 = 0, c2 = 0;
        for (int j = 0; j < N; j++) {
            if (arr[j] >= P) {
                int diff = (int) (arr[j] - P);
                if (((2 * P) - diff) <= 2) {
                    c1++;
                } else if ((((2 * P) - diff) <= 4) && (((2 * P) - diff) > 2)) {
                    c2++;
                }
            }
        }
        if (c2 > S) {
            c1 = c1 + S;
        } else {
            c1 = c1 + c2;
        }
        return c1;
    }
}
