package template;

import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;

public class TestCase {

    private boolean isSolved;
    private Object solution;
    private Map<String, Integer> intProperties;
    private Map<String, ArrayList<Integer>> intArrayProperties;
    private Map<String, ArrayList<ArrayList<Integer>>> intArray2DProperties;
    private Map<String, Double> doubleProperties;
    private Map<String, ArrayList<Double>> doubleArrayProperties;
    private Map<String, ArrayList<ArrayList<Double>>> doubleArray2DProperties;
    private Map<String, String> stringProperties;
    private Map<String, ArrayList<String>> stringArrayProperties;
    private Map<String, ArrayList<ArrayList<String>>> stringArray2DProperties;
    private Map<String, Boolean> booleanProperties;
    private Map<String, ArrayList<Boolean>> booleanArrayProperties;
    private Map<String, ArrayList<ArrayList<Boolean>>> booleanArray2DProperties;
    private Map<String, Long> longProperties;
    private Map<String, ArrayList<Long>> longArrayProperties;
    private Map<String, ArrayList<ArrayList<Long>>> longArray2DProperties;
    private int ref;
    private double time;

    public TestCase() {
        initialise();
    }

    private void initialise() {
        isSolved = false;
        intProperties = new HashMap<>();
        intArrayProperties = new HashMap<>();
        intArray2DProperties = new HashMap<>();
        doubleProperties = new HashMap<>();
        doubleArrayProperties = new HashMap<>();
        doubleArray2DProperties = new HashMap<>();
        stringProperties = new HashMap<>();
        stringArrayProperties = new HashMap<>();
        stringArray2DProperties = new HashMap<>();
        booleanProperties = new HashMap<>();
        booleanArrayProperties = new HashMap<>();
        booleanArray2DProperties = new HashMap<>();
        longProperties = new HashMap<>();
        longArrayProperties = new HashMap<>();
        longArray2DProperties = new HashMap<>();
        ref = 0;
    }

    public void setSolution(Object o) {
        solution = o;
        isSolved = true;
    }
    
    public Object getSolution() {
        if (!isSolved) {
            Utils.die("getSolution on unsolved testcase");
        }

        return solution;
    }

    public void setRef(int i) {
        ref = i;
    }
    public int getRef() {
        return ref;
    }

    public void setTime(double d) {
        time = d;
    }
    public double getTime() {
        return time;
    }
    
    public void setInteger(String s, Integer i) {
        intProperties.put(s, i);
    }
    
    public Integer getInteger(String s) {
        return intProperties.get(s);
    }

    public void setIntegerList(String s, ArrayList<Integer> l) {
        intArrayProperties.put(s, l);
    }

    public void setIntegerMatrix(String s, ArrayList<ArrayList<Integer>> l) {
        intArray2DProperties.put(s, l);
    }

    public ArrayList<Integer> getIntegerList(String s) {
        return intArrayProperties.get(s);
    }

    public Integer getIntegerListItem(String s, int i) {
        return intArrayProperties.get(s).get(i);
    }

    public ArrayList<ArrayList<Integer>> getIntegerMatrix(String s) {
        return intArray2DProperties.get(s);
    }
    
    public ArrayList<Integer> getIntegerMatrixRow(String s, int row) {
        return intArray2DProperties.get(s).get(row);
    }
    
    public Integer getIntegerMatrixItem(String s, int row, int column) {
        return intArray2DProperties.get(s).get(row).get(column);
    }

    public ArrayList<Integer> getIntegerMatrixColumn(String s, int column) {
        ArrayList<Integer> out = new ArrayList();
        
        for(ArrayList<Integer> row : intArray2DProperties.get(s)) {
            out.add(row.get(column));
        }
        return out;
    }


    public void setDouble(String s, Double i) {
        doubleProperties.put(s, i);
    }
    
    public Double getDouble(String s) {
        return doubleProperties.get(s);
    }

    public void setDoubleList(String s, ArrayList<Double> l) {
        doubleArrayProperties.put(s, l);
    }

    public void setDoubleMatrix(String s, ArrayList<ArrayList<Double>> l) {
        doubleArray2DProperties.put(s, l);
    }

    public ArrayList<Double> getDoubleList(String s) {
        return doubleArrayProperties.get(s);
    }

    public Double getDoubleListItem(String s, int i) {
        return doubleArrayProperties.get(s).get(i);
    }

    public ArrayList<ArrayList<Double>> getDoubleMatrix(String s) {
        return doubleArray2DProperties.get(s);
    }
    
    public ArrayList<Double> getDoubleMatrixRow(String s, int row) {
        return doubleArray2DProperties.get(s).get(row);
    }
    
    public Double getDoubleMatrixItem(String s, int row, int column) {
        return doubleArray2DProperties.get(s).get(row).get(column);
    }

    public ArrayList<Double> getDoubleMatrixColumn(String s, int column) {
        ArrayList<Double> out = new ArrayList();
        
        for(ArrayList<Double> row : doubleArray2DProperties.get(s)) {
            out.add(row.get(column));
        }
        return out;
    }

    
    public void setString(String s, String t) {
        stringProperties.put(s, t);
    }
    
    public String getString(String s) {
        return stringProperties.get(s);
    }

    public void setStringList(String s, ArrayList<String> l) {
        stringArrayProperties.put(s, l);
    }

    public void setStringMatrix(String s, ArrayList<ArrayList<String>> l) {
        stringArray2DProperties.put(s, l);
    }

    public ArrayList<String> getStringList(String s) {
        return stringArrayProperties.get(s);
    }

    public String getStringListItem(String s, int i) {
        return stringArrayProperties.get(s).get(i);
    }

    public ArrayList<ArrayList<String>> getStringMatrix(String s) {
        return stringArray2DProperties.get(s);
    }
    
    public ArrayList<String> getStringMatrixRow(String s, int row) {
        return stringArray2DProperties.get(s).get(row);
    }
    
    public String getStringMatrixItem(String s, int row, int column) {
        return stringArray2DProperties.get(s).get(row).get(column);
    }

    public ArrayList<String> getStringMatrixColumn(String s, int column) {
        ArrayList<String> out = new ArrayList();
        
        for(ArrayList<String> row : stringArray2DProperties.get(s)) {
            out.add(row.get(column));
        }
        return out;
    }

    
    public void setBoolean(String s, Boolean b) {
        booleanProperties.put(s, b);
    }
    
    public Boolean getBoolean(String s) {
        return booleanProperties.get(s);
    }

    public void setBooleanList(String s, ArrayList<Boolean> l) {
        booleanArrayProperties.put(s, l);
    }

    public void setBooleanMatrix(String s, ArrayList<ArrayList<Boolean>> l) {
        booleanArray2DProperties.put(s, l);
    }

    public ArrayList<Boolean> getBooleanList(String s) {
        return booleanArrayProperties.get(s);
    }

    public Boolean getBooleanListItem(String s, int i) {
        return booleanArrayProperties.get(s).get(i);
    }

    public ArrayList<ArrayList<Boolean>> getBooleanMatrix(String s) {
        return booleanArray2DProperties.get(s);
    }
    
    public ArrayList<Boolean> getBooleanMatrixRow(String s, int row) {
        return booleanArray2DProperties.get(s).get(row);
    }
    
    public Boolean getBooleanMatrixItem(String s, int row, int column) {
        return booleanArray2DProperties.get(s).get(row).get(column);
    }

    public ArrayList<Boolean> getBooleanMatrixColumn(String s, int column) {
        ArrayList<Boolean> out = new ArrayList();
        
        for(ArrayList<Boolean> row : booleanArray2DProperties.get(s)) {
            out.add(row.get(column));
        }
        return out;
    }

    public void setLong(String s, Long b) {
        longProperties.put(s, b);
    }
    
    public Long getLong(String s) {
        return longProperties.get(s);
    }

    public void setLongList(String s, ArrayList<Long> l) {
        longArrayProperties.put(s, l);
    }

    public void setLongMatrix(String s, ArrayList<ArrayList<Long>> l) {
        longArray2DProperties.put(s, l);
    }

    public ArrayList<Long> getLongList(String s) {
        return longArrayProperties.get(s);
    }

    public Long getLongListItem(String s, int i) {
        return longArrayProperties.get(s).get(i);
    }

    public ArrayList<ArrayList<Long>> getLongMatrix(String s) {
        return longArray2DProperties.get(s);
    }
    
    public ArrayList<Long> getLongMatrixRow(String s, int row) {
        return longArray2DProperties.get(s).get(row);
    }
    
    public Long getLongMatrixItem(String s, int row, int column) {
        return longArray2DProperties.get(s).get(row).get(column);
    }

    public ArrayList<Long> getLongMatrixColumn(String s, int column) {
        ArrayList<Long> out = new ArrayList();
        
        for(ArrayList<Long> row : longArray2DProperties.get(s)) {
            out.add(row.get(column));
        }
        return out;
    }

    

    


}

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Leonid
 * Date: 4/14/12
 * Time: 2:41 PM
 * Dancing With Googlers solution
 */
public class DancingWithGooglers {
    public static void main(String[] args) {
        FilesManager fileManager = FilesManager.getFilesManager();
        while (fileManager != null) {
            produceSolution(fileManager);
            fileManager = FilesManager.getFilesManager();
        }

    }

    private static void produceSolution(FilesManager filesManager) {
        FileCommunicationManager fileComManager = new FileCommunicationManager(filesManager);
        List<String> input = fileComManager.convertInputToStrings();
        List<InputInfo> parsedInput = CaseInterpreter.parseInput(input);
        List<String> output = new ArrayList<String>();

        for (int i = 0; i < parsedInput.size(); i++) {
            OutputInfo outputInfo = solve(parsedInput.get(i));
            output.add(CaseInterpreter.composeOutputLine(outputInfo, i + 1));
        }

        fileComManager.convertStringsToOutput(output);
    }

    private static OutputInfo solve(InputInfo inputInfo) {
        OutputInfo outputInfo = new OutputInfo();

        int surpriseThreshold = inputInfo.p * 3 - 4;
        int regularThreshold = inputInfo.p * 3 - 2;
        int surpriseCounter = 0;
        int regularCounter = 0;

        for (int totalResult : inputInfo.results) {
            if (totalResult >= regularThreshold) {
                regularCounter++;
            } else if (totalResult >= surpriseThreshold && totalResult!=0) {
                surpriseCounter++;
            }
        }
        outputInfo.result = regularCounter + (surpriseCounter > inputInfo.s ? inputInfo.s : surpriseCounter);

        return outputInfo;
    }

    private static class InputInfo {
        int n, s, p;
        int[] results;
    }

    private static class OutputInfo {
        int result;

        public String toString() {
            return Integer.toString(result);
        }

    }

    private static class CaseInterpreter {
        private static final int CASE_NUMBER_OF_LINES = 1;

        public static List<InputInfo> parseInput(List<String> input) {
            List<InputInfo> parsedInput = new ArrayList<InputInfo>();
            for (int i = 0; i < input.size(); i += CASE_NUMBER_OF_LINES) {
                parsedInput.add(parseCase(input.subList(i, i + CASE_NUMBER_OF_LINES)));
            }

            return parsedInput;
        }

        private static InputInfo parseCase(List<String> caseLines) {
            InputInfo inputInfo = new InputInfo();
            List<Integer> ints = strToInts(caseLines.get(0));

            inputInfo.n = ints.get(0);
            inputInfo.s = ints.get(1);
            inputInfo.p = ints.get(2);

            inputInfo.results = new int[inputInfo.n];
            for (int i = 0; i < inputInfo.n; i++) {
                inputInfo.results[i] = ints.get(i + 3);
            }

            return inputInfo;
        }

        public static String composeOutputLine(OutputInfo output, int caseNumber) {
            String outputString = "Case #" + caseNumber + ": " + output.toString();

            return outputString;
        }

        private static List<Integer> strToInts(String str) {
            List<Integer> ints = new ArrayList<Integer>();
            String[] strs = str.split(" ");
            for (String s : strs) {
                ints.add(Integer.parseInt(s));
            }
            return ints;
        }
    }

    private static class FilesManager {
        File inputFile;
        File outputFile;
        private static List<String> inputFiles;
        private static int inputFilesIt = 0;

        static {
            File f = new File(".");
            inputFiles = getInputFiles(f.list());
        }

        private static List<String> getInputFiles(String[] fileNames) {
            List<String> inputFileNames = new ArrayList<String>();

            for (String fileName : fileNames) {
                String[] splitFileName = fileName.split("\\.");
                if (splitFileName.length == 2) {
                    if (splitFileName[1].equals("IN") || splitFileName[1].equals("In") || splitFileName[1].equals("in")) {
                        inputFileNames.add(fileName);
                    }
                }
            }
            return inputFileNames;
        }

        private static String generateOutputFileName(String inputFileName) {
            String[] stlitFileName = inputFileName.split("\\.");
            return stlitFileName[0] + "-output.txt";
        }

        FilesManager(String inputFileName, String outputFileName) {
            inputFile = new File(inputFileName);
            assert (inputFile.exists());
            outputFile = new File(outputFileName);
            try {
                outputFile.createNewFile();
            } catch (IOException ex) {
                System.out.println("Exception while trying to create an output file");
            }
        }

        public static FilesManager getFilesManager() {
            if (inputFilesIt >= inputFiles.size()) {
                return null;
            }
            String inputFileName = inputFiles.get(inputFilesIt++);
            String outputFileName = generateOutputFileName(inputFileName);
            return new FilesManager(inputFileName, outputFileName);
        }


        File getInputFile() {
            return inputFile;
        }

        File getOutputFile() {
            return outputFile;
        }
    }

    private static class FileCommunicationManager {
        File inputFile;
        File outputFile;

        FileCommunicationManager(FilesManager filesManager) {
            inputFile = filesManager.getInputFile();
            outputFile = filesManager.getOutputFile();
        }

        List<String> convertInputToStrings() {
            List<String> linesList = new ArrayList<String>();

            try {
                FileReader fr = new FileReader(inputFile);
                BufferedReader bufReader = new BufferedReader(fr);
                int numOfCases = Integer.parseInt(bufReader.readLine());

                for (int i = 0; i < numOfCases; i++) {
                    linesList.add(bufReader.readLine());
                }

            } catch (IOException e) {
                System.out.println("Error reading from the file");
            }

            return linesList;
        }

        void convertStringsToOutput(List<String> linesList) {
            BufferedWriter bufWriter = null;
            try {
                bufWriter = new BufferedWriter(new FileWriter(outputFile));

                for (String line : linesList) {
                    bufWriter.write(line);
                    bufWriter.newLine();
                }

            } catch (IOException e) {
                System.out.println("Error reading from the file");
            } finally {
                //Close the BufferedWriter
                try {
                    if (bufWriter != null) {
                        bufWriter.flush();
                        bufWriter.close();
                    }
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
        }
    }
}
