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 year2012.DancingWiththeGooglers;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

final class DancingWiththeGooglers {

	/**
	 * @param args
	 * @throws IOException
	 */
	static class Triplet {
		public boolean ableMax = false;
		public boolean ableSurprising = true;
		public boolean beMaxMustSurprise = false;

		Triplet(int totalScore, int maxScore) {
			int mean = totalScore / 3;
			int remainder = totalScore % 3;
			if (totalScore == 29 || totalScore == 30) {
				ableMax = true;
			} 
			else if (totalScore == 0 || totalScore == 1)
			{
				ableSurprising = false;
				if (maxScore <= totalScore)
				{
					ableMax = true;
				}
				else ableMax = false;
			}
			else if (mean >= maxScore) {
				ableMax = true;
			} else if (mean == (maxScore - 1)) {
				if (remainder == 2 || remainder == 1)
					ableMax = true;
				if (remainder == 0)
					beMaxMustSurprise = true;
			} else if (mean == (maxScore - 2)) {
				if (remainder == 2)
					beMaxMustSurprise = true;
			}
		}
	}

	public static void main(String[] args) throws IOException {

		String file = "B-small-attempt0";
		Scanner sc = new Scanner(new FileReader(file + ".in"));
		PrintWriter pw = new PrintWriter(new FileWriter(file + ".out"));

		int T = sc.nextInt();
		for (int i = 0; i < T; i++) {

			int N = sc.nextInt();
			int S = sc.nextInt(); // surprising
			int p = sc.nextInt();

			int totalBeAlwaysMax = 0;
			int totalBeMaxMustSurprising = 0;
			int totalNotSurpriseAbleMax = 0;

			int result = 0;

			for (int i1 = 0; i1 < N; i1++) {
				Triplet temp = new Triplet(sc.nextInt(), p);
				if (temp.ableMax  && temp.ableSurprising)
					totalBeAlwaysMax++;
				if (temp.beMaxMustSurprise == true)
					totalBeMaxMustSurprising++;
				if (!temp.ableSurprising && temp.ableMax)
				{
					totalNotSurpriseAbleMax++;
				}
				
			}

			if (S <= totalBeMaxMustSurprising) {
				result = totalBeAlwaysMax + S + totalNotSurpriseAbleMax ;
			} else {
				result = totalBeAlwaysMax + totalBeMaxMustSurprising + totalNotSurpriseAbleMax;
			}

			pw.println("Case #" + (i + 1) + ": " + result);
			// pw.println();

		}
		pw.flush();
		pw.close();
		sc.close();
	}
}
