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.*;

public class MySolution {
	public MySolution() {

	}

	public static void main(String[] a) throws IOException {
		sumfile("B-large.in");
	}

	static void sumfile(String filename) throws IOException {
		int tests=0;
		int N=0;
		int S=0;
		int p=0;
		int ti=0;
		int count=0;
		Reader r = new BufferedReader(new FileReader(filename));
		StreamTokenizer stok = new StreamTokenizer(r);
		stok.parseNumbers();
		stok.nextToken();
		if (stok.ttype == StreamTokenizer.TT_NUMBER) {
			tests=(int)stok.nval;
		}
		for(int i=0;i<tests;i++){
			stok.nextToken();
			if (stok.ttype == StreamTokenizer.TT_NUMBER) {
				N=(int)stok.nval;
			}
			stok.nextToken();
			if (stok.ttype == StreamTokenizer.TT_NUMBER) {
				S=(int)stok.nval;
			}
			stok.nextToken();
			if (stok.ttype == StreamTokenizer.TT_NUMBER) {
				p=(int)stok.nval;
			}
			for(int j=0;j<N;j++){
				stok.nextToken();
				ti=(int)stok.nval;
				if(ti>=p*3-2){
					count++;
				}
				else if(ti>=p*3-4&&S>0&&p*3-4>=0){
					count++;
					S--;
				}
			}
			System.out.println("Case #"+(i+1)+": "+count);
			count=0;
		}
	}
}
