package dancinggooglers;

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

public class DanceScoreCalculator {


    public static void main(String[] args) {
        if(args.length <= 0 || args[0] == null) {
            System.out.println("You must enter a file to read");
            System.out.println("Usage: blah <filename>");
            System.exit(0);
        }

        File argFile = new File(args[0]);
        try {
            Scanner googleSpeakScanner = new Scanner(argFile);
            String firstLine = googleSpeakScanner.nextLine();
            Integer linesToScan = new Integer(firstLine);
            for(int i = 1; i <= linesToScan; i++) {
                String googleDancerLine = googleSpeakScanner.nextLine();
                DanceScoreCase danceCase = new DanceScoreCase(googleDancerLine);
                System.out.println(String.format("Case #%d: %d", i, danceCase.maxDancersThatCouldPass()));
            }
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
}

import java.io.*;
import java.util.*;


public class DancingWithTheGooglers {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			FileReader fileReader = new FileReader("B-large.in.txt");
			FileWriter fileWriter = new FileWriter("out.txt");
			BufferedReader reader = new BufferedReader(fileReader);
			BufferedWriter writer = new BufferedWriter(fileWriter);
			String inputString;
			inputString = reader.readLine();
			int cases = Integer.parseInt(inputString);
			for (int caseCount = 0; caseCount < cases; caseCount++)
			{
				inputString = reader.readLine();
				String output = "Case #" + (caseCount+1) + ": ";
				String a[] = inputString.split(" ");
				int n = Integer.parseInt(a[0]);
				int s = Integer.parseInt(a[1]);
				int p = Integer.parseInt(a[2]);
				int ans = 0;
				int score[] = new int[n];
				for (int i = 0; i < n; i++)
					score[i] = Integer.parseInt(a[i + 3]);
				Arrays.sort(score);
				for (int i = 0; i < n; i++)
				{
					if ((score[i] + 2) / 3 >= p) ans ++;
					else
					{
						if (s > 0 && score[i] >= 2 && ((score[i] + 4) / 3 >= p))
						{
							s--;
							ans++;
						}
					}
				}
				output += ans;
				output += '\n';
				writer.write(output);
			}
			reader.close();
			writer.close();
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
