/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package IO;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
    
/**
 * 
 * @author dannocz
 */
public class InputReader {
    
    public static Input readFile(String filename){
        try {
              
              /*  Sets up a file reader to read the file passed on the command
          77        line one character at a time */
              FileReader input = new FileReader(filename);
              
              /* Filter FileReader through a Buffered read to read a line at a
                 time */
              BufferedReader bufRead = new BufferedReader(input);
              
              String line;    // String that holds current file line
              int count = 0;  // Line number of count 
              ArrayList<String> cases= new ArrayList<String>();
              
              // Read first line
              line = bufRead.readLine();
              int noTestCases=Integer.parseInt(line);
              count++;
              
              // Read through file one line at time. Print line # and line
              while (count<=noTestCases){
                  //System.out.println("Reading. "+count+": "+line);
                  line = bufRead.readLine();
                  cases.add(line);
                  count++;
              }
              
              bufRead.close();
              
              return new Input(noTestCases,cases);
              
          }catch (ArrayIndexOutOfBoundsException e){
              /* If no file was passed on the command line, this expception is
              generated. A message indicating how to the class should be
              called is displayed */
              e.printStackTrace();        
  
          }catch (IOException e){
              // If another exception is generated, print a stack trace
              e.printStackTrace();
          }
        
        return null;
          
      }// end main
    }

package dancers;

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

public class Dancers {

	public static int SURPRISE = 0;
	public static int ATENDEE = 0;
	public static int BESTRESULT = 0;
	public static int[] SCORES;
	public static int[] RESULTS;
	public static String[] inputLines;
	
	
	public static void main(String args[])
	{
		try {
			readIo();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		solveProblemsFromLine();
		try {
			saveOutputFile();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static int countResult()
	{
		int result = 0;
		int mayResult = 0;
		for(int score:SCORES){
			if(score>=(BESTRESULT+(Math.max(0, 2*(BESTRESULT-1)))))
				result++;
			else
				if(score>=BESTRESULT+(Math.max(0,2*(BESTRESULT-2))))
					mayResult++;
		}
		mayResult = Math.min(mayResult, SURPRISE);
		
		return result+mayResult;
	}
	
	
	
	public static void readIo() throws Exception
	{
		 DataInputStream in = new DataInputStream(new FileInputStream("B2.in"));//inp2.in
		 BufferedReader br = new BufferedReader(new InputStreamReader(in));
		 int lineNum = Integer.parseInt(br.readLine());
		 inputLines = new String[lineNum];
		 RESULTS = new int[lineNum];
		 String strLine=null;
		 int count=0;
		 while ((strLine = br.readLine()) != null)
		 {
			 inputLines[count] = strLine;
			 count++;
		 }		 
	}
	
	public static void parse(String input)
	{
		String tokens[] = input.split(" ");
		ATENDEE = Integer.parseInt(tokens[0]);
		SURPRISE = Integer.parseInt(tokens[1]);
		BESTRESULT = Integer.parseInt(tokens[2]);
		SCORES = new int[ATENDEE];
		for(int i = 3; i<tokens.length; i++)
			SCORES[i-3] = Integer.parseInt(tokens[i]);
		
	}
	
	
	public static void solveProblemsFromLine()
	{
		for(int inp=0; inp<inputLines.length;inp++)
		{
			parse(inputLines[inp]);
			RESULTS[inp] = countResult();
			System.out.println(RESULTS[inp]);
		} 
		
	}
	
	public static void saveOutputFile() throws IOException
	{
		BufferedWriter out = new BufferedWriter(new FileWriter("result.txt"));
		for(int i=0; i<RESULTS.length; i++)
		{
			out.write("Case #"+(i+1)+": "+ RESULTS[i]);
			out.newLine();
		}
		out.flush();
		out.close();
	}
}
