/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 3/3/12
 * Time: 11:00 AM
 * To change this template use File | Settings | File Templates.
 */

import SRMLib.MathLibrary;
import SRMLib.TestSRMLib;
import com.sun.org.apache.bcel.internal.generic.F2D;

import java.io.*;
import java.util.*;
import java.util.zip.Inflater;

public class SRM {
    public static void main(String[] args) throws IOException {
        //TestSRMLib.run();
        codeJam1.main();

        return;
    }
}
class codeJam1 {
    public static void main() throws IOException {
        String inputPath = "E:\\input.txt";
        String outputPath = "E:\\output.txt";
        BufferedReader input = new BufferedReader(new FileReader(inputPath));
        BufferedWriter output = new BufferedWriter(new FileWriter(outputPath));

        String line;
        line = input.readLine();
        int T = Integer.parseInt(line);
        for (int i = 1; i <= T; ++i) {
            line = input.readLine();
            String[] words = line.split(" ");
            int N = Integer.parseInt(words[0]);
            int S = Integer.parseInt(words[1]);
            int p = Integer.parseInt(words[2]);
            int n = 0;
            int res = 0;

            for (int j = 3; j < words.length; ++j) {
                if (p == 0) {
                    res++;
                    continue;
                }

                int t = Integer.parseInt(words[j]);
                if (p == 1) {
                    if (t > 0)
                        res++;
                    continue;
                }
                if (t >= 3 * p - 2)
                    res++;
                else if (t >= 3 * p - 4)
                    n++;
            }

            res += Math.min(n, S);
            output.write("Case #" + i + ": " + res);
            output.newLine();
        }

        input.close();
        output.close();
    }
}

package gcj.main;

import gcj.cases.competition.qualification_round_2012.CaseB;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;

public class Main {

	
	public static final void main (String[] args) throws Exception{
//		doTask("taskTeszt0", "/home/dev/LetÃ¶ltÃ©sek/0-teszt-practice.in", "/home/dev/LetÃ¶ltÃ©sek/0-teszt-practice.out", new Case0());
//		doTask("taskSmall0", "/home/dev/LetÃ¶ltÃ©sek/A-small-attempt0.in", "/home/dev/LetÃ¶ltÃ©sek/A-small-attempt0.out", new Case0());
		
//		doTask("taskTesztB", "/home/dev/LetÃ¶ltÃ©sek/B-teszt-practice.in", "/home/dev/LetÃ¶ltÃ©sek/B-teszt-practice.out", new CaseB());
		doTask("taskSmallB", "/home/dev/LetÃ¶ltÃ©sek/B-small-attempt0.in", "/home/dev/LetÃ¶ltÃ©sek/B-small-attempt0.out", new CaseB());
//		doTask("taskLargeB", "/home/dev/LetÃ¶ltÃ©sek/B-large-practice.in", "/home/dev/LetÃ¶ltÃ©sek/B-large-practice.out", new CaseB());
		
//		doTask("taskTesztC", "/home/dev/LetÃ¶ltÃ©sek/C-teszt-practice.in", "/home/dev/LetÃ¶ltÃ©sek/C-teszt-practice.out", new CaseC());
//		doTask("taskSmallC", "/home/dev/LetÃ¶ltÃ©sek/C-small-attempt0.in", "/home/dev/LetÃ¶ltÃ©sek/C-small-attempt0.out", new CaseC());
//		doTask("taskLargeC", "/home/dev/LetÃ¶ltÃ©sek/C-large.in", "/home/dev/LetÃ¶ltÃ©sek/C-large.out", new CaseC());
		
		doTask(null, null, null, null); //because i hate the 'never used locally' warning... 
	}

	
	private static final void doTask(String taskID, String inpFilePath, String outFilePath, Case c) throws Exception {
		if(taskID == null) return;
		BufferedReader br = null;
		BufferedWriter bw = null;
		String strLine;
		int caseNum = 0;
		System.out.println(taskID + " strated...");
		try{
			{
				//open files
				br = new BufferedReader(new FileReader(new File(inpFilePath)));
				bw = new BufferedWriter(new FileWriter(new File(outFilePath)));
			}
			{
				//read caseNum value
				if ((strLine = br.readLine()) != null){
					caseNum = Integer.parseInt(strLine);	
				}
				System.out.println("CaseNum: "+caseNum);
			}
			for(int i=0; i<caseNum; i++){			
				System.out.println("\tprocessing Case #: "+(i+1));
				//load case
				c.init(i+1, br);
				//processing case
				c.solve();
				//write to file
				c.generateOutput(bw, i<caseNum-1);
			}
		}catch(Exception e){
			System.out.println(taskID + " failed!");
			e.printStackTrace();
		}finally{
			//end
			if(br!=null) br.close();
			if(bw!=null) bw.close();
			System.out.println(taskID + " finished.");
		}
	}
}
