package problem1;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Arrays;





public class Problem1 {

    public static void main(String[] args) throws FileNotFoundException, IOException{
        try {
             TextIO.readFile("L:\\Coodejam\\Input\\Input.txt");
        }
        catch (IllegalArgumentException e) {
              System.out.println("Can't open file ");
              System.exit(0);
         }
        
        FileOutputStream fout = new FileOutputStream("L:\\Coodejam\\Output\\output.txt");
        PrintStream ps=new PrintStream(fout);
        
        int cases=TextIO.getInt();
        int googlers=0,surprising=0,least=0;
        for(int i=0;i<cases;i++){
            int counter=0;
            googlers=TextIO.getInt();
            surprising=TextIO.getInt();
            least=TextIO.getInt();
            int score[]=new int[googlers];
            for(int j=0;j<googlers;j++){
                score[j]=TextIO.getInt();
                 }
            
            
            
            
            Arrays.sort(score);
            int temp=0;
            int sup[]=new int[surprising];
            
          for(int j=0;j<googlers && surprising>0;j++){
               if(biggestNS(score[j])<least && biggestS(score[j])==least){
                   surprising--;
                   counter++;
                }
               }
           
            for(int j=0;j<googlers;j++){
                if(surprising==0)temp=biggestNS(score[j]);
                    
                else {
                    temp=biggestS(score[j]);
                    surprising--;     
                } 
                   if(temp>=least)counter++;
           
             }
            
             ps.println("Case #"+(i+1)+": "+counter);
        }
    }
    
   static int biggestNS(int x){
       if(x==0)return 0;
       if(x==1)return 1;
       return ((x-1)/3)+1;
   }
   
   static int biggestS(int x){
       if(x==0)return 0;
       if(x==1)return 1;
       return ((x-2)/3)+2;
   }
}
package codeJam;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Dance {
	
	public static void main(String[] args) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		try {
			FileWriter fstream = new FileWriter("Dance.txt");
			BufferedWriter out = new BufferedWriter(fstream);
			int noTestCases = Integer.parseInt(in.readLine());
			for (int i = 1; i <= noTestCases; i++) {
				out.write("\nCase #" + i + ": ");
				String[] inputs = in.readLine().split(" ");
				int surprise = Integer.parseInt(inputs[1]);
				int minMark = Integer.parseInt(inputs[2]);
				int result = 0;
				List<Integer> lessmarks = new ArrayList<Integer>();
				for (int j = 3; j < inputs.length; j++) {
					int div = Integer.parseInt(inputs[j]) / 3;
					int mod = Integer.parseInt(inputs[j]) % 3;
					if (mod > 0) {
						div++;						
					}
					if (div >= minMark) {
						result++;
					} else if (Integer.parseInt(inputs[j]) > 0) {
						lessmarks.add(Integer.parseInt(inputs[j]));
					}
				}
				if (surprise > 0 && !lessmarks.isEmpty()) {
					int ite = 0;
					for (int z = 0; z < lessmarks.size() && surprise > 0; z++) {
						ite++;
						if (ite > lessmarks.size() * 3 && surprise == Integer.parseInt(inputs[1])) {
							break;
						}
						int mark = lessmarks.get(z);
						int div = mark / 3;
						int mod = mark % 3;
						if (mod > 0) div++;
						if (minMark - div > 2) continue;
						div++;
						if (div >= minMark) {
							result++;
							lessmarks.remove(z);
						}
						surprise--;
						if (z + 1 == lessmarks.size() && surprise > 0) {
							z = 0;
						}
					}
				}
				out.write(Integer.toString(result));
			}
			out.close();
		} catch (NumberFormatException e) {
				e.printStackTrace();
		} catch (IOException e) {
				e.printStackTrace();
		}
		
	}

}
