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 small;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;

import javax.swing.plaf.basic.BasicInternalFrameTitlePane.MaximizeAction;

public class DancingGooglers {
	private static int noOfCases;
	private static int[] noOfGooglers;
	private static int[] noOfSurprisingTriplets;
	private static int[] bestResult;
	private static int[][] scores;
	private static String[] result;

	public static void main(String[] args) {

		readInputFile();
		result = new String[noOfCases];

		for (int i = 0; i < noOfCases; i++) {
			int totalSum = 0;
			int surprisingCount = 0;
			for (int j = 0; j < noOfGooglers[i]; j++) {
				// System.out.print(" "+scores[i][j]);
				if (scores[i][j] >= bestResult[i]) {
					if ((scores[i][j] - bestResult[i]) / 2 >= bestResult[i] - 2) {
						totalSum++;
						if ((scores[i][j] - bestResult[i]) / 2 == bestResult[i] - 2) {
							surprisingCount++;
						}
					}
				}

			}

			if (surprisingCount > noOfSurprisingTriplets[i]) {
				totalSum = totalSum
						- (surprisingCount - noOfSurprisingTriplets[i]);
			}
			System.out.println();
			System.out.println("Case #" + (i + 1) + ": " + totalSum);
			result[i] = "Case #" + (i + 1) + ": " + totalSum;

		}

		writeToFile(result);

	}

	private static void readInputFile() {

		try {
			FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
			DataInputStream in = new DataInputStream(fstream);
			BufferedReader br = new BufferedReader(new InputStreamReader(in));

			noOfCases = Integer.parseInt(br.readLine());
			String strLine;
			scores = new int[noOfCases][];
			noOfGooglers = new int[noOfCases];
			noOfSurprisingTriplets = new int[noOfCases];
			bestResult = new int[noOfCases];
			for (int i = 0; i < noOfCases; i++) {
				strLine = br.readLine();
				String[] temp = strLine.split(" ");
				noOfGooglers[i] = Integer.parseInt(temp[0]);
				noOfSurprisingTriplets[i] = Integer.parseInt(temp[1]);
				bestResult[i] = Integer.parseInt(temp[2]);
				scores[i] = new int[noOfGooglers[i]];

				// System.out.println("No of Googlers: "+noOfGooglers);
				// System.out.println("No of surp trip: "+noOfSurprisingTriplets);
				// System.out.println("Best Result: "+bestResult);

				for (int j = 0; j < noOfGooglers[i]; j++) {
					scores[i][j] = Integer.parseInt(temp[3 + j]);
					System.out.println(scores[i][j]);
				}

			}

			in.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.err.println("Error: " + e.getMessage());
		}
	}

	public static void writeToFile(String args[]) {
		try {
			FileWriter fstream = new FileWriter("B-small-attempt0.out");
			BufferedWriter out = new BufferedWriter(fstream);
			for (int i = 0; i < args.length; i++) {
				out.write(args[i]);
				if (i != args.length - 1)
					out.newLine();
			}
			out.close();
		} catch (Exception e) {
			System.err.println("Error: " + e.getMessage());
		}
	}

}
