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

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
	
	public static int calcWIS(int n){
		if(n - 2 < 0)
			return 0;
		return ((n - 2) / 3) + 2;
	}
	
	public static int calcWOS(int n){
		if(n - 1 < 0)
			return 0;
		return ((n - 1) / 3) + 1;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//String fileName = args[0];
		String fileName = "googlers/B-small-attempt0.in";
		Scanner sC = null;
		try {
			sC = new Scanner(new File(fileName));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		int T = sC.nextInt();
		int N, S, p;
		int[] tab, wiS, woS;
		for(int i = 0; i < T; i++){
			N = sC.nextInt();
			S = sC.nextInt();
			p = sC.nextInt();
			tab = new int[N];
			wiS = new int[N];
			woS = new int[N];
			
			for(int j = 0; j < N; j++){
				tab[j] = sC.nextInt();
				wiS[j] = calcWIS(tab[j]);
				woS[j] = calcWOS(tab[j]);
				//System.out.println(tab[j] + " " + wiS[j] + " " + woS[j]);
			}
			
			int count = 0;
			
			for(int j = 0; j < N; j++){
				if(woS[j] >= p){
					count++;
				}
				if(woS[j] < p && wiS[j] >= p && S > 0){
					count++;
					S--;
				}
			}
			
			System.out.println("Case #" + (i + 1) + ": " + count);
			
		}

	}

}
